BookView.vue 4.3 KB

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