BookView.vue 4.9 KB

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