BookInfoDialog.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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="poster-size column justify-center items-center" :class="{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" 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: 'ext', label: 'Тип'},
  153. {name: 'size', label: 'Размер'},
  154. {name: 'date', label: 'Добавлен'},
  155. {name: 'del', label: 'Удален'},
  156. {name: 'libid', label: 'LibId'},
  157. {name: 'insno', label: 'InsideNo'},
  158. ]},
  159. {name: 'titleInfo', label: 'Общая информация', value: [
  160. {name: 'author', label: 'Автор(ы)'},
  161. {name: 'title', label: 'Название'},
  162. {name: 'series', label: 'Серия'},
  163. {name: 'genre', label: 'Жанр'},
  164. {name: 'librate', label: 'Оценка'},
  165. {name: 'lang', label: 'Язык книги'},
  166. {name: 'keywords', label: 'Ключевые слова'},
  167. ]},
  168. ];
  169. const valueToString = (value, nodePath) => {//eslint-disable-line no-unused-vars
  170. if (nodePath == 'fileInfo/size')
  171. return `${this.formatSize(value)} (${value.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1 ')} Bytes)`;
  172. if (nodePath == 'fileInfo/date')
  173. return utils.sqlDateFormat(value);
  174. if (nodePath == 'fileInfo/del')
  175. return (value ? 'Да' : null);
  176. if (nodePath == 'fileInfo/insno')
  177. return (value ? value : null);
  178. if (nodePath == 'titleInfo/author')
  179. return value.split(',').join(', ');
  180. if (nodePath == 'titleInfo/librate' && !value)
  181. return null;
  182. if (typeof(value) === 'string') {
  183. return value;
  184. }
  185. return (value.toString ? value.toString() : '');
  186. };
  187. let result = [];
  188. const book = _.cloneDeep(this.book);
  189. book.series = [book.series, book.serno].filter(v => v).join(' #');
  190. for (const item of mapping) {
  191. const itemOut = {name: item.name, label: item.label, value: []};
  192. for (const subItem of item.value) {
  193. const subItemOut = {
  194. name: subItem.name,
  195. label: subItem.label,
  196. value: valueToString(book[subItem.name], `${item.name}/${subItem.name}`)
  197. };
  198. if (subItemOut.value)
  199. itemOut.value.push(subItemOut);
  200. }
  201. if (itemOut.value.length)
  202. result.push(itemOut);
  203. }
  204. return result;
  205. }
  206. get info() {
  207. let result = [];
  208. switch (this.selectedTab) {
  209. case 'fb2':
  210. return this.fb2;
  211. case 'inpx':
  212. return this.inpx;
  213. }
  214. return result;
  215. }
  216. parseBookInfo() {
  217. const bookInfo = this.bookInfo;
  218. //cover
  219. if (bookInfo.cover)
  220. this.coverSrc = bookInfo.cover;
  221. //fb2
  222. if (bookInfo.fb2) {
  223. const parser = new Fb2Parser(bookInfo.fb2);
  224. const infoObj = parser.bookInfo();
  225. if (infoObj.titleInfo) {
  226. let ann = infoObj.titleInfo.annotationHtml;
  227. if (ann) {
  228. ann = ann.replace(/<p>/g, `<p class="p-annotation">`);
  229. this.annotation = ann;
  230. }
  231. }
  232. this.fb2 = parser.bookInfoList(infoObj, {
  233. valueToString(value, nodePath, origVTS) {//eslint-disable-line no-unused-vars
  234. if (nodePath == 'documentInfo/historyHtml' && value)
  235. return value.replace(/<p>/g, `<p class="p-history">`);
  236. return origVTS(value, nodePath);
  237. },
  238. });
  239. }
  240. //book
  241. if (bookInfo.book)
  242. this.book = bookInfo.book;
  243. }
  244. posterClick() {
  245. if (!this.coverSrc)
  246. return;
  247. this.posterDialogVisible = true;
  248. }
  249. okClick() {
  250. this.dialogVisible = false;
  251. }
  252. }
  253. export default vueComponent(BookInfoDialog);
  254. //-----------------------------------------------------------------------------
  255. </script>
  256. <style scoped>
  257. .poster-size {
  258. height: 300px;
  259. width: 200px;
  260. min-width: 100px;
  261. }
  262. .poster {
  263. width: 100%;
  264. height: 100%;
  265. }
  266. .poster:hover {
  267. position: relative;
  268. top: -1%;
  269. left: -1%;
  270. width: 102%;
  271. height: 102%;
  272. cursor: pointer;
  273. }
  274. </style>
  275. <style>
  276. .p-annotation {
  277. text-indent: 20px;
  278. text-align: justify;
  279. padding: 0;
  280. margin: 0;
  281. }
  282. .p-history {
  283. padding: 0;
  284. margin: 0;
  285. }
  286. </style>