BookView.vue 3.7 KB

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