BookView.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <div class="row items-center q-my-sm">
  3. <div class="row 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="config.bookReadLink" 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. titleColor: { type: String, default: 'text-blue-10'},
  76. };
  77. showRate = true;
  78. showGenres = true;
  79. showDeleted = false;
  80. created() {
  81. this.loadSettings();
  82. }
  83. loadSettings() {
  84. const settings = this.settings;
  85. this.showRate = settings.showRate;
  86. this.showGenres = settings.showGenres;
  87. this.showDeleted = settings.showDeleted;
  88. }
  89. get config() {
  90. return this.$store.state.config;
  91. }
  92. get settings() {
  93. return this.$store.state.settings;
  94. }
  95. get bookTitle() {
  96. if (this.showAuthor && this.book.author) {
  97. let a = this.book.author.split(',');
  98. const author = a.slice(0, 2).join(', ') + (a.length > 2 ? ' и др.' : '');
  99. return `${author} - ${this.book.title}`;
  100. } else {
  101. return this.book.title;
  102. }
  103. }
  104. get bookSize() {
  105. let size = this.book.size/1024;
  106. let unit = 'KB';
  107. if (size > 1024) {
  108. size = size/1024;
  109. unit = 'MB';
  110. }
  111. return `${size.toFixed(0)}${unit}`;
  112. }
  113. get rateColor() {
  114. const rate = (this.book.librate > 5 ? 5 : this.book.librate);
  115. if (rate > 2)
  116. return `green-${(rate - 1)*2}`;
  117. else
  118. return `red-${10 - rate*2}`;
  119. }
  120. get bookGenre() {
  121. let result = [];
  122. const genre = new Set(this.book.genre.split(','));
  123. for (const section of this.genreTree) {
  124. for (const g of section.value)
  125. if (genre.has(g.value))
  126. result.push(g.name);
  127. }
  128. return `(${result.join(' / ')})`;
  129. }
  130. selectTitle() {
  131. this.$emit('bookEvent', {action: 'titleClick', book: this.book});
  132. }
  133. download() {
  134. this.$emit('bookEvent', {action: 'download', book: this.book});
  135. }
  136. copyLink() {
  137. this.$emit('bookEvent', {action: 'copyLink', book: this.book});
  138. }
  139. readBook() {
  140. this.$emit('bookEvent', {action: 'readBook', book: this.book});
  141. }
  142. }
  143. export default vueComponent(BookView);
  144. //-----------------------------------------------------------------------------
  145. </script>
  146. <style scoped>
  147. .clickable {
  148. color: blue;
  149. cursor: pointer;
  150. }
  151. .clickable2 {
  152. cursor: pointer;
  153. }
  154. </style>