BookInfoDialog.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. <template>
  2. <Dialog ref="dialog" v-model="dialogVisible">
  3. <template #header>
  4. <div class="row items-center">
  5. <div style="font-size: 110%">
  6. Информация о книге
  7. </div>
  8. </div>
  9. </template>
  10. <div ref="box" class="fit column q-mt-xs overflow-auto no-wrap" style="padding: 0px 10px 10px 10px;">
  11. <div class="text-green-10">
  12. {{ bookAuthor }}
  13. </div>
  14. <div>
  15. <b>{{ book.title }}</b>
  16. </div>
  17. <div class="row q-mt-sm no-wrap">
  18. <div class="column justify-center" style="height: 300px; width: 200px;">
  19. <img v-if="coverSrc" :src="coverSrc" class="fit row justify-center items-center" style="object-fit: contain" @error="coverSrc = ''" />
  20. <div v-if="!coverSrc" class="fit row justify-center items-center text-grey-5" style="border: 1px solid #ccc; font-size: 300%">
  21. <i>{{ book.ext }}</i>
  22. </div>
  23. </div>
  24. <div class="col column q-ml-sm" style="min-width: 300px; border: 1px solid #ccc">
  25. <div class="bg-grey-3 row">
  26. <q-tabs
  27. v-model="selectedTab"
  28. active-color="black"
  29. active-bg-color="white"
  30. indicator-color="white"
  31. dense
  32. no-caps
  33. inline-label
  34. class="bg-grey-4 text-grey-7"
  35. >
  36. <q-tab name="fb2" label="Fb2 инфо" />
  37. <q-tab name="inpx" label="Inpx инфо" />
  38. </q-tabs>
  39. </div>
  40. <div class="overflow-auto full-width" style="height: 262px">
  41. <div v-for="item in info" :key="item.name">
  42. <div class="row q-ml-sm q-mt-sm items-center">
  43. <div class="text-blue" style="font-size: 90%">
  44. {{ item.label }}
  45. </div>
  46. <div class="col q-mx-xs" style="height: 0px; border-top: 1px solid #ccc"></div>
  47. </div>
  48. <div v-for="subItem in item.value" :key="subItem.name" class="row q-ml-md">
  49. <div style="width: 110px">
  50. {{ subItem.label }}
  51. </div>
  52. <div class="q-ml-sm">
  53. {{ subItem.value }}
  54. </div>
  55. </div>
  56. </div>
  57. <div class="q-mt-xs"></div>
  58. </div>
  59. </div>
  60. </div>
  61. <div class="q-mt-md" v-html="annotation" />
  62. </div>
  63. <template #footer>
  64. <q-btn class="q-px-md q-ml-sm" color="primary" dense no-caps @click="okClick">
  65. OK
  66. </q-btn>
  67. </template>
  68. </Dialog>
  69. </template>
  70. <script>
  71. //-----------------------------------------------------------------------------
  72. import vueComponent from '../../vueComponent.js';
  73. import Dialog from '../../share/Dialog.vue';
  74. import Fb2Parser from '../../../../server/core/fb2/Fb2Parser';
  75. import * as utils from '../../../share/utils';
  76. const componentOptions = {
  77. components: {
  78. Dialog
  79. },
  80. watch: {
  81. modelValue(newValue) {
  82. this.dialogVisible = newValue;
  83. if (newValue)
  84. this.init();
  85. },
  86. dialogVisible(newValue) {
  87. this.$emit('update:modelValue', newValue);
  88. },
  89. }
  90. };
  91. class BookInfoDialog {
  92. _options = componentOptions;
  93. _props = {
  94. modelValue: Boolean,
  95. bookInfo: Object,
  96. };
  97. dialogVisible = false;
  98. selectedTab = 'fb2';
  99. //info props
  100. coverSrc = '';
  101. annotation = '';
  102. fb2 = [];
  103. book = {};
  104. created() {
  105. this.commit = this.$store.commit;
  106. }
  107. mounted() {
  108. }
  109. init() {
  110. //defaults
  111. this.coverSrc = '';
  112. this.annotation = '';
  113. this.fb2 = [];
  114. this.book = {};
  115. this.parseBookInfo();
  116. }
  117. get bookAuthor() {
  118. if (this.book.author) {
  119. let a = this.book.author.split(',');
  120. return a.slice(0, 3).join(', ') + (a.length > 3 ? ' и др.' : '');
  121. }
  122. return '';
  123. }
  124. formatSize(size) {
  125. size = size/1024;
  126. let unit = 'KB';
  127. if (size > 1024) {
  128. size = size/1024;
  129. unit = 'MB';
  130. }
  131. return `${size.toFixed(1)} ${unit}`;
  132. }
  133. get inpx() {
  134. const mapping = [
  135. {name: 'fileInfo', label: 'Информация о файле', value: [
  136. {name: 'folder', label: 'Папка'},
  137. {name: 'file', label: 'Файл'},
  138. {name: 'ext', label: 'Тип'},
  139. {name: 'size', label: 'Размер'},
  140. {name: 'date', label: 'Добавлен'},
  141. {name: 'del', label: 'Удален'},
  142. {name: 'libid', label: 'LibId'},
  143. {name: 'insno', label: 'InsideNo'},
  144. ]},
  145. {name: 'titleInfo', label: 'Общая информация', value: [
  146. {name: 'author', label: 'Автор(ы)'},
  147. {name: 'title', label: 'Название'},
  148. {name: 'series', label: 'Серия'},
  149. {name: 'serno', label: 'Номер в серии'},
  150. {name: 'genre', label: 'Жанр'},
  151. {name: 'librate', label: 'Оценка'},
  152. {name: 'lang', label: 'Язык книги'},
  153. {name: 'keywords', label: 'Ключевые слова'},
  154. ]},
  155. ];
  156. const valueToString = (value, nodePath) => {//eslint-disable-line no-unused-vars
  157. if (nodePath == 'fileInfo/size')
  158. return `${this.formatSize(value)} (${value.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1 ')} Bytes)`;
  159. if (nodePath == 'fileInfo/date')
  160. return utils.sqlDateFormat(value);
  161. if (nodePath == 'fileInfo/del')
  162. return (value ? 'Да' : 'Нет');
  163. if (nodePath == 'titleInfo/author')
  164. return value.split(',').join(', ');
  165. if (typeof(value) === 'string') {
  166. return value;
  167. }
  168. return (value.toString ? value.toString() : '');
  169. };
  170. let result = [];
  171. for (const item of mapping) {
  172. const itemOut = {name: item.name, label: item.label, value: []};
  173. for (const subItem of item.value) {
  174. const subItemOut = {
  175. name: subItem.name,
  176. label: subItem.label,
  177. value: valueToString(this.book[subItem.name], `${item.name}/${subItem.name}`)
  178. };
  179. if (subItemOut.value)
  180. itemOut.value.push(subItemOut);
  181. }
  182. if (itemOut.value.length)
  183. result.push(itemOut);
  184. }
  185. return result;
  186. }
  187. get info() {
  188. let result = [];
  189. switch (this.selectedTab) {
  190. case 'fb2':
  191. return this.fb2;
  192. case 'inpx':
  193. return this.inpx;
  194. }
  195. return result;
  196. }
  197. parseBookInfo() {
  198. const bookInfo = this.bookInfo;
  199. const parser = new Fb2Parser();
  200. //cover
  201. if (bookInfo.cover)
  202. this.coverSrc = bookInfo.cover;
  203. //fb2
  204. if (bookInfo.fb2) {
  205. this.fb2 = parser.bookInfoList(bookInfo.fb2);
  206. const infoObj = parser.bookInfo(bookInfo.fb2);
  207. if (infoObj.titleInfo) {
  208. let ann = infoObj.titleInfo.annotationHtml;
  209. if (ann) {
  210. ann = ann.replace(/<p>/g, `<p class="p-annotation">`);
  211. this.annotation = ann;
  212. }
  213. }
  214. }
  215. //book
  216. if (bookInfo.book)
  217. this.book = bookInfo.book;
  218. }
  219. okClick() {
  220. this.dialogVisible = false;
  221. }
  222. }
  223. export default vueComponent(BookInfoDialog);
  224. //-----------------------------------------------------------------------------
  225. </script>
  226. <style scoped>
  227. </style>
  228. <style>
  229. .p-annotation {
  230. text-indent: 20px;
  231. text-align: justify;
  232. padding: 0;
  233. margin: 0;
  234. }
  235. </style>