BookInfoDialog.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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; min-width: 100px">
  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: 400px; 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 v-if="fb2.length" 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: 100px">
  50. {{ subItem.label }}
  51. </div>
  52. <div class="q-ml-sm" v-html="subItem.value" />
  53. </div>
  54. </div>
  55. <div class="q-mt-xs"></div>
  56. </div>
  57. </div>
  58. </div>
  59. <div class="q-mt-md" v-html="annotation" />
  60. </div>
  61. <template #footer>
  62. <q-btn class="q-px-md q-ml-sm" color="primary" dense no-caps @click="okClick">
  63. OK
  64. </q-btn>
  65. </template>
  66. </Dialog>
  67. </template>
  68. <script>
  69. //-----------------------------------------------------------------------------
  70. import vueComponent from '../../vueComponent.js';
  71. import Dialog from '../../share/Dialog.vue';
  72. import Fb2Parser from '../../../../server/core/fb2/Fb2Parser';
  73. import * as utils from '../../../share/utils';
  74. import _ from 'lodash';
  75. const componentOptions = {
  76. components: {
  77. Dialog
  78. },
  79. watch: {
  80. modelValue(newValue) {
  81. this.dialogVisible = newValue;
  82. if (newValue)
  83. this.init();
  84. },
  85. dialogVisible(newValue) {
  86. this.$emit('update:modelValue', newValue);
  87. },
  88. }
  89. };
  90. class BookInfoDialog {
  91. _options = componentOptions;
  92. _props = {
  93. modelValue: Boolean,
  94. bookInfo: Object,
  95. };
  96. dialogVisible = false;
  97. selectedTab = 'fb2';
  98. //info props
  99. coverSrc = '';
  100. annotation = '';
  101. fb2 = [];
  102. book = {};
  103. created() {
  104. this.commit = this.$store.commit;
  105. }
  106. mounted() {
  107. }
  108. init() {
  109. //defaults
  110. this.coverSrc = '';
  111. this.annotation = '';
  112. this.fb2 = [];
  113. this.book = {};
  114. this.parseBookInfo();
  115. if (!this.fb2.length)
  116. this.selectedTab = 'inpx';
  117. }
  118. get bookAuthor() {
  119. if (this.book.author) {
  120. let a = this.book.author.split(',');
  121. return a.slice(0, 3).join(', ') + (a.length > 3 ? ' и др.' : '');
  122. }
  123. return '';
  124. }
  125. formatSize(size) {
  126. size = size/1024;
  127. let unit = 'KB';
  128. if (size > 1024) {
  129. size = size/1024;
  130. unit = 'MB';
  131. }
  132. return `${size.toFixed(1)} ${unit}`;
  133. }
  134. get inpx() {
  135. const mapping = [
  136. {name: 'fileInfo', label: 'Информация о файле', value: [
  137. {name: 'folder', label: 'Папка'},
  138. {name: 'file', label: 'Файл'},
  139. {name: 'ext', label: 'Тип'},
  140. {name: 'size', label: 'Размер'},
  141. {name: 'date', label: 'Добавлен'},
  142. {name: 'del', label: 'Удален'},
  143. {name: 'libid', label: 'LibId'},
  144. {name: 'insno', label: 'InsideNo'},
  145. ]},
  146. {name: 'titleInfo', label: 'Общая информация', value: [
  147. {name: 'author', label: 'Автор(ы)'},
  148. {name: 'title', label: 'Название'},
  149. {name: 'series', 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 ? 'Да' : null);
  163. if (nodePath == 'fileInfo/insno')
  164. return (value ? value : null);
  165. if (nodePath == 'titleInfo/author')
  166. return value.split(',').join(', ');
  167. if (nodePath == 'titleInfo/librate' && !value)
  168. return null;
  169. if (typeof(value) === 'string') {
  170. return value;
  171. }
  172. return (value.toString ? value.toString() : '');
  173. };
  174. let result = [];
  175. const book = _.cloneDeep(this.book);
  176. book.series = [book.series, book.serno].filter(v => v).join(' #');
  177. for (const item of mapping) {
  178. const itemOut = {name: item.name, label: item.label, value: []};
  179. for (const subItem of item.value) {
  180. const subItemOut = {
  181. name: subItem.name,
  182. label: subItem.label,
  183. value: valueToString(book[subItem.name], `${item.name}/${subItem.name}`)
  184. };
  185. if (subItemOut.value)
  186. itemOut.value.push(subItemOut);
  187. }
  188. if (itemOut.value.length)
  189. result.push(itemOut);
  190. }
  191. return result;
  192. }
  193. get info() {
  194. let result = [];
  195. switch (this.selectedTab) {
  196. case 'fb2':
  197. return this.fb2;
  198. case 'inpx':
  199. return this.inpx;
  200. }
  201. return result;
  202. }
  203. parseBookInfo() {
  204. const bookInfo = this.bookInfo;
  205. //cover
  206. if (bookInfo.cover)
  207. this.coverSrc = bookInfo.cover;
  208. //fb2
  209. if (bookInfo.fb2) {
  210. const parser = new Fb2Parser(bookInfo.fb2);
  211. const infoObj = parser.bookInfo();
  212. if (infoObj.titleInfo) {
  213. let ann = infoObj.titleInfo.annotationHtml;
  214. if (ann) {
  215. ann = ann.replace(/<p>/g, `<p class="p-annotation">`);
  216. this.annotation = ann;
  217. }
  218. }
  219. this.fb2 = parser.bookInfoList(infoObj, {
  220. valueToString(value, nodePath, origVTS) {//eslint-disable-line no-unused-vars
  221. if (nodePath == 'documentInfo/historyHtml' && value)
  222. return value.replace(/<p>/g, `<p class="p-history">`);
  223. return origVTS(value, nodePath);
  224. },
  225. });
  226. }
  227. //book
  228. if (bookInfo.book)
  229. this.book = bookInfo.book;
  230. }
  231. okClick() {
  232. this.dialogVisible = false;
  233. }
  234. }
  235. export default vueComponent(BookInfoDialog);
  236. //-----------------------------------------------------------------------------
  237. </script>
  238. <style scoped>
  239. </style>
  240. <style>
  241. .p-annotation {
  242. text-indent: 20px;
  243. text-align: justify;
  244. padding: 0;
  245. margin: 0;
  246. }
  247. .p-history {
  248. padding: 0;
  249. margin: 0;
  250. }
  251. </style>