BookView.vue 7.4 KB

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