BookView.vue 6.1 KB

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