BookInfoDialog.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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="poster-size">
  19. <div class="column justify-center items-center" :class="{'poster': coverSrc, 'no-poster': !coverSrc}" @click.stop.prevent="posterClick">
  20. <img v-if="coverSrc" :src="coverSrc" class="fit row justify-center items-center" style="object-fit: contain" @error="coverSrc = ''" />
  21. <div v-if="!coverSrc" class="fit row justify-center items-center text-grey-5 overflow-hidden" style="border: 1px solid #ccc; font-size: 300%">
  22. <i>{{ book.ext }}</i>
  23. </div>
  24. </div>
  25. </div>
  26. <div class="col column q-ml-sm" style="min-width: 400px; border: 1px solid #ccc">
  27. <div class="bg-grey-3 row">
  28. <q-tabs
  29. v-model="selectedTab"
  30. active-color="black"
  31. active-bg-color="white"
  32. indicator-color="white"
  33. dense
  34. no-caps
  35. inline-label
  36. class="bg-grey-4 text-grey-7"
  37. >
  38. <q-tab v-if="fb2.length" name="fb2" label="Fb2 инфо" />
  39. <q-tab name="inpx" label="Inpx инфо" />
  40. </q-tabs>
  41. </div>
  42. <div class="overflow-auto full-width" style="height: 262px">
  43. <div v-for="item in info" :key="item.name">
  44. <div class="row q-ml-sm q-mt-sm items-center">
  45. <div class="text-blue" style="font-size: 90%">
  46. {{ item.label }}
  47. </div>
  48. <div class="col q-mx-xs" style="height: 0px; border-top: 1px solid #ccc"></div>
  49. </div>
  50. <div v-for="subItem in item.value" :key="subItem.name" class="row q-ml-md">
  51. <div style="width: 100px">
  52. {{ subItem.label }}
  53. </div>
  54. <div class="q-ml-sm" v-html="subItem.value" />
  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 v-model="posterDialogVisible">
  69. <template #header>
  70. <div class="row items-center">
  71. <div style="font-size: 110%">
  72. Обложка
  73. </div>
  74. </div>
  75. </template>
  76. <img :src="coverSrc" class="fit q-pb-sm" style="height: 100%; max-height: calc(100vh - 140px); object-fit: contain" />
  77. </Dialog>
  78. </Dialog>
  79. </template>
  80. <script>
  81. //-----------------------------------------------------------------------------
  82. import vueComponent from '../../vueComponent.js';
  83. import Dialog from '../../share/Dialog.vue';
  84. import Fb2Parser from '../../../../server/core/fb2/Fb2Parser';
  85. import * as utils from '../../../share/utils';
  86. import _ from 'lodash';
  87. const componentOptions = {
  88. components: {
  89. Dialog
  90. },
  91. watch: {
  92. modelValue(newValue) {
  93. this.dialogVisible = newValue;
  94. if (newValue)
  95. this.init();
  96. },
  97. dialogVisible(newValue) {
  98. this.$emit('update:modelValue', newValue);
  99. },
  100. }
  101. };
  102. class BookInfoDialog {
  103. _options = componentOptions;
  104. _props = {
  105. modelValue: Boolean,
  106. bookInfo: Object,
  107. };
  108. dialogVisible = false;
  109. posterDialogVisible = false;
  110. selectedTab = 'fb2';
  111. //info props
  112. coverSrc = '';
  113. annotation = '';
  114. fb2 = [];
  115. book = {};
  116. created() {
  117. this.commit = this.$store.commit;
  118. }
  119. mounted() {
  120. }
  121. init() {
  122. //defaults
  123. this.coverSrc = '';
  124. this.annotation = '';
  125. this.fb2 = [];
  126. this.book = {};
  127. this.parseBookInfo();
  128. if (!this.fb2.length)
  129. this.selectedTab = 'inpx';
  130. }
  131. get bookAuthor() {
  132. if (this.book.author) {
  133. let a = this.book.author.split(',');
  134. return a.slice(0, 3).join(', ') + (a.length > 3 ? ' и др.' : '');
  135. }
  136. return '';
  137. }
  138. formatSize(size) {
  139. size = size/1024;
  140. let unit = 'KB';
  141. if (size > 1024) {
  142. size = size/1024;
  143. unit = 'MB';
  144. }
  145. return `${size.toFixed(1)} ${unit}`;
  146. }
  147. get inpx() {
  148. const mapping = [
  149. {name: 'fileInfo', label: 'Информация о файле', value: [
  150. {name: 'folder', label: 'Папка'},
  151. {name: 'file', label: 'Файл'},
  152. {name: 'size', label: 'Размер'},
  153. {name: 'date', label: 'Добавлен'},
  154. {name: 'del', label: 'Удален'},
  155. {name: 'libid', label: 'LibId'},
  156. {name: 'insno', label: 'InsideNo'},
  157. ]},
  158. {name: 'titleInfo', label: 'Общая информация', value: [
  159. {name: 'author', label: 'Автор(ы)'},
  160. {name: 'title', label: 'Название'},
  161. {name: 'series', label: 'Серия'},
  162. {name: 'genre', label: 'Жанр'},
  163. {name: 'librate', label: 'Оценка'},
  164. {name: 'lang', label: 'Язык книги'},
  165. {name: 'keywords', label: 'Ключевые слова'},
  166. ]},
  167. ];
  168. const valueToString = (value, nodePath, b) => {//eslint-disable-line no-unused-vars
  169. if (nodePath == 'fileInfo/file')
  170. return `${value}.${b.ext}`;
  171. if (nodePath == 'fileInfo/size')
  172. return `${this.formatSize(value)} (${value.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1 ')} Bytes)`;
  173. if (nodePath == 'fileInfo/date')
  174. return utils.sqlDateFormat(value);
  175. if (nodePath == 'fileInfo/del')
  176. return (value ? 'Да' : null);
  177. if (nodePath == 'fileInfo/insno')
  178. return (value ? value : null);
  179. if (nodePath == 'titleInfo/author')
  180. return value.split(',').join(', ');
  181. if (nodePath == 'titleInfo/librate' && !value)
  182. return null;
  183. if (typeof(value) === 'string') {
  184. return value;
  185. }
  186. return (value.toString ? value.toString() : '');
  187. };
  188. let result = [];
  189. const book = _.cloneDeep(this.book);
  190. book.series = [book.series, book.serno].filter(v => v).join(' #');
  191. for (const item of mapping) {
  192. const itemOut = {name: item.name, label: item.label, value: []};
  193. for (const subItem of item.value) {
  194. const subItemOut = {
  195. name: subItem.name,
  196. label: subItem.label,
  197. value: valueToString(book[subItem.name], `${item.name}/${subItem.name}`, book)
  198. };
  199. if (subItemOut.value)
  200. itemOut.value.push(subItemOut);
  201. }
  202. if (itemOut.value.length)
  203. result.push(itemOut);
  204. }
  205. return result;
  206. }
  207. get info() {
  208. let result = [];
  209. switch (this.selectedTab) {
  210. case 'fb2':
  211. return this.fb2;
  212. case 'inpx':
  213. return this.inpx;
  214. }
  215. return result;
  216. }
  217. parseBookInfo() {
  218. const bookInfo = this.bookInfo;
  219. //cover
  220. if (bookInfo.cover)
  221. this.coverSrc = bookInfo.cover;
  222. //fb2
  223. if (bookInfo.fb2) {
  224. const parser = new Fb2Parser(bookInfo.fb2);
  225. const infoObj = parser.bookInfo();
  226. if (infoObj.titleInfo) {
  227. let ann = infoObj.titleInfo.annotationHtml;
  228. if (ann) {
  229. ann = ann.replace(/<p>/g, `<p class="p-annotation">`);
  230. this.annotation = ann;
  231. }
  232. }
  233. this.fb2 = parser.bookInfoList(infoObj, {
  234. valueToString(value, nodePath, origVTS) {//eslint-disable-line no-unused-vars
  235. if (nodePath == 'documentInfo/historyHtml' && value)
  236. return value.replace(/<p>/g, `<p class="p-history">`);
  237. return origVTS(value, nodePath);
  238. },
  239. });
  240. }
  241. //book
  242. if (bookInfo.book)
  243. this.book = bookInfo.book;
  244. }
  245. posterClick() {
  246. if (!this.coverSrc)
  247. return;
  248. this.posterDialogVisible = true;
  249. }
  250. okClick() {
  251. this.dialogVisible = false;
  252. }
  253. }
  254. export default vueComponent(BookInfoDialog);
  255. //-----------------------------------------------------------------------------
  256. </script>
  257. <style scoped>
  258. .poster-size {
  259. height: 300px;
  260. width: 200px;
  261. min-width: 100px;
  262. }
  263. .poster, .no-poster {
  264. width: 100%;
  265. height: 100%;
  266. }
  267. .poster:hover {
  268. position: relative;
  269. top: -1%;
  270. left: -1%;
  271. width: 102%;
  272. height: 102%;
  273. cursor: pointer;
  274. }
  275. </style>
  276. <style>
  277. .p-annotation {
  278. text-indent: 20px;
  279. text-align: justify;
  280. padding: 0;
  281. margin: 0;
  282. }
  283. .p-history {
  284. padding: 0;
  285. margin: 0;
  286. }
  287. </style>