BookView.vue 6.2 KB

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