BookView.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <div class="row items-center q-my-sm">
  3. <div v-if="showRate || showDeleted">
  4. <div v-if="showRate && !book.del">
  5. <div v-if="book.librate">
  6. <q-knob
  7. :model-value="book.librate"
  8. :min="0"
  9. :max="5"
  10. show-value
  11. size="22px"
  12. font-size="12px"
  13. :thickness="0.3"
  14. :color="rateColor"
  15. track-color="grey-4"
  16. readonly
  17. />
  18. </div>
  19. <div v-else style="width: 22px" />
  20. </div>
  21. <div v-else class="row justify-center" style="width: 22px">
  22. <q-icon v-if="book.del" class="la la-trash text-bold text-red" size="22px" />
  23. </div>
  24. </div>
  25. <div class="q-ml-sm clickable2" @click="selectTitle">
  26. {{ book.serno ? `${book.serno}. ` : '' }}
  27. <span class="text-blue-10">{{ book.title }}</span>
  28. </div>
  29. <div class="q-ml-sm">
  30. {{ bookSize }}, {{ book.ext }}
  31. </div>
  32. <div class="q-ml-sm clickable" @click="download">
  33. (скачать)
  34. </div>
  35. <div class="q-ml-sm clickable" @click="copyLink">
  36. <q-icon name="la la-copy" size="20px" />
  37. </div>
  38. <div v-if="config.bookReadLink" class="q-ml-sm clickable" @click="readBook">
  39. (читать)
  40. </div>
  41. <div v-if="showGenres && book.genre" class="q-ml-sm">
  42. {{ bookGenre }}
  43. </div>
  44. <div v-show="false">
  45. {{ book }}
  46. </div>
  47. </div>
  48. </template>
  49. <script>
  50. //-----------------------------------------------------------------------------
  51. import vueComponent from '../../vueComponent.js';
  52. const componentOptions = {
  53. components: {
  54. },
  55. watch: {
  56. settings() {
  57. this.loadSettings();
  58. },
  59. }
  60. };
  61. class BookView {
  62. _options = componentOptions;
  63. _props = {
  64. book: Object,
  65. genreTree: Array,
  66. };
  67. showRate = true;
  68. showGenres = true;
  69. showDeleted = false;
  70. created() {
  71. this.loadSettings();
  72. }
  73. loadSettings() {
  74. const settings = this.settings;
  75. this.showRate = settings.showRate;
  76. this.showGenres = settings.showGenres;
  77. this.showDeleted = settings.showDeleted;
  78. }
  79. get config() {
  80. return this.$store.state.config;
  81. }
  82. get settings() {
  83. return this.$store.state.settings;
  84. }
  85. get bookSize() {
  86. let size = this.book.size/1024;
  87. let unit = 'KB';
  88. if (size > 1024) {
  89. size = size/1024;
  90. unit = 'MB';
  91. }
  92. return `${size.toFixed(0)}${unit}`;
  93. }
  94. get rateColor() {
  95. const rate = (this.book.librate > 5 ? 5 : this.book.librate);
  96. if (rate > 2)
  97. return `green-${(rate - 1)*2}`;
  98. else
  99. return `red-${10 - rate*2}`;
  100. }
  101. get bookGenre() {
  102. let result = [];
  103. const genre = new Set(this.book.genre.split(','));
  104. for (const section of this.genreTree) {
  105. for (const g of section.value)
  106. if (genre.has(g.value))
  107. result.push(g.name);
  108. }
  109. return `(${result.join(' / ')})`;
  110. }
  111. selectTitle() {
  112. this.$emit('bookEvent', {action: 'titleClick', book: this.book});
  113. }
  114. download() {
  115. this.$emit('bookEvent', {action: 'download', book: this.book});
  116. }
  117. copyLink() {
  118. this.$emit('bookEvent', {action: 'copyLink', book: this.book});
  119. }
  120. readBook() {
  121. this.$emit('bookEvent', {action: 'readBook', book: this.book});
  122. }
  123. }
  124. export default vueComponent(BookView);
  125. //-----------------------------------------------------------------------------
  126. </script>
  127. <style scoped>
  128. .clickable {
  129. color: blue;
  130. cursor: pointer;
  131. }
  132. .clickable2 {
  133. cursor: pointer;
  134. }
  135. </style>