BookView.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <div class="row items-center q-my-sm no-wrap">
  3. <div class="row items-center">
  4. <div v-if="showRates || showDeleted">
  5. <div v-if="showRates && !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>
  33. <div class="q-ml-sm column">
  34. <div v-if="(mode == 'series' || mode == 'title') && bookAuthor" class="row">
  35. <div class="clickable2 text-green-10" @click="emit('authorClick')">
  36. {{ bookAuthor }}
  37. </div>
  38. </div>
  39. <div class="row items-center">
  40. <div v-if="book.serno" class="q-mr-xs">
  41. {{ book.serno }}.
  42. </div>
  43. <div class="clickable2" :class="titleColor" @click="emit('titleClick')">
  44. {{ book.title }}
  45. </div>
  46. <div v-if="mode == 'title' && bookSeries" class="q-ml-xs clickable2" @click="emit('seriesClick')">
  47. {{ bookSeries }}
  48. </div>
  49. <div class="q-ml-sm">
  50. {{ bookSize }}, {{ book.ext }}
  51. </div>
  52. <div v-if="showInfo" class="q-ml-sm clickable" @click="emit('bookInfo')">
  53. (инфо)
  54. </div>
  55. <div class="q-ml-sm clickable" @click="emit('download')">
  56. (скачать)
  57. </div>
  58. <div class="q-ml-sm clickable" @click="emit('copyLink')">
  59. <q-icon name="la la-copy" size="20px" />
  60. </div>
  61. <div v-if="showReadLink" class="q-ml-sm clickable" @click="emit('readBook')">
  62. (читать)
  63. </div>
  64. <div v-if="showGenres && book.genre" class="q-ml-sm">
  65. {{ bookGenre }}
  66. </div>
  67. <div v-if="showDates && book.date" class="q-ml-sm">
  68. {{ bookDate }}
  69. </div>
  70. </div>
  71. </div>
  72. <div v-show="false">
  73. {{ book }}
  74. </div>
  75. </div>
  76. </template>
  77. <script>
  78. //-----------------------------------------------------------------------------
  79. import vueComponent from '../../vueComponent.js';
  80. import * as utils from '../../../share/utils';
  81. const componentOptions = {
  82. components: {
  83. },
  84. watch: {
  85. settings() {
  86. this.loadSettings();
  87. },
  88. }
  89. };
  90. class BookView {
  91. _options = componentOptions;
  92. _props = {
  93. book: Object,
  94. mode: String,
  95. genreMap: Object,
  96. showReadLink: Boolean,
  97. titleColor: { type: String, default: 'text-blue-10'},
  98. };
  99. showRates = true;
  100. showInfo = true;
  101. showGenres = true;
  102. showDeleted = false;
  103. showDates = false;
  104. created() {
  105. this.loadSettings();
  106. }
  107. loadSettings() {
  108. const settings = this.settings;
  109. this.showRates = settings.showRates;
  110. this.showInfo = settings.showInfo;
  111. this.showGenres = settings.showGenres;
  112. this.showDates = settings.showDates;
  113. this.showDeleted = settings.showDeleted;
  114. }
  115. get settings() {
  116. return this.$store.state.settings;
  117. }
  118. get bookAuthor() {
  119. if (this.book.author) {
  120. let a = this.book.author.split(',');
  121. return a.slice(0, 3).join(', ') + (a.length > 3 ? ' и др.' : '');
  122. }
  123. return '';
  124. }
  125. get bookSeries() {
  126. if (this.book.series) {
  127. return `(Серия: ${this.book.series})`;
  128. }
  129. return '';
  130. }
  131. get bookSize() {
  132. let size = this.book.size/1024;
  133. let unit = 'KB';
  134. if (size > 1024) {
  135. size = size/1024;
  136. unit = 'MB';
  137. }
  138. return `${size.toFixed(0)}${unit}`;
  139. }
  140. get rateColor() {
  141. const rate = (this.book.librate > 5 ? 5 : this.book.librate);
  142. if (rate > 2)
  143. return `green-${(rate - 1)*2}`;
  144. else
  145. return `red-${10 - rate*2}`;
  146. }
  147. get bookGenre() {
  148. let result = [];
  149. const genre = this.book.genre.split(',');
  150. for (const g of genre) {
  151. const name = this.genreMap.get(g);
  152. if (name)
  153. result.push(name);
  154. }
  155. return `(${result.join(' / ')})`;
  156. }
  157. get bookDate() {
  158. if (!this.book.date)
  159. return '';
  160. return utils.sqlDateFormat(this.book.date);
  161. }
  162. emit(action) {
  163. this.$emit('bookEvent', {action, book: this.book});
  164. }
  165. }
  166. export default vueComponent(BookView);
  167. //-----------------------------------------------------------------------------
  168. </script>
  169. <style scoped>
  170. .clickable {
  171. color: blue;
  172. cursor: pointer;
  173. }
  174. .clickable2 {
  175. cursor: pointer;
  176. }
  177. </style>