RefferenceDocDetail.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. <template>
  2. <main>
  3. <div class="left">
  4. <header>
  5. <div @click="goBack"><icon-left style="margin-right: 5px" />返回知识问答</div>
  6. </header>
  7. <!-- <div>
  8. <div style="background-color: rgb(255, 110, 110)">{{ userName?.slice(0, 1) }}</div>
  9. <p>{{ targetDocument.question }}</p>
  10. </div> -->
  11. <p>
  12. <span>以下是根据您的提问搜索到的相关文档</span>
  13. <span>共 {{ list.length }} 条</span>
  14. </p>
  15. <section>
  16. <div
  17. :class="[item.doc_id === target_doc_id ? 'activeBox' : '']"
  18. v-for="(item, key) in list"
  19. :key="key"
  20. @click="handelChangePdf(item)"
  21. >
  22. <div>
  23. <img src="./icon.svg" />
  24. </div>
  25. <div>
  26. <p>{{ item.doc_name }}</p>
  27. <p>{{ item.desc }}</p>
  28. <span>
  29. <b>检索片段</b>
  30. <em></em>
  31. </span>
  32. <div
  33. :class="[frag.chunk_id === target_chunk_id ? 'activeLink' : '']"
  34. v-for="(frag, index) in item.fragments"
  35. :key="index"
  36. @click.stop="handlerClickFragment(frag)"
  37. >
  38. <span>{{ index + 1 }}.</span>
  39. {{ frag.content_with_weight }}
  40. </div>
  41. </div>
  42. </div>
  43. </section>
  44. </div>
  45. <div class="right" ref="pdfFather">
  46. <template v-if="showPdfViewer">
  47. <ViewerPDFFromUrl
  48. v-if="target_doc_type === 'pdf'"
  49. ref="pdfViewer"
  50. class="pdf-viewer"
  51. :url="target_doc_url"
  52. :doc_width="DOC_WIDTH"
  53. :positions="positions"
  54. >
  55. </ViewerPDFFromUrl>
  56. <ViewerDocxFromUrl
  57. v-if="target_doc_type === 'doc'"
  58. ref="pdfViewer"
  59. class="pdf-viewer"
  60. :url="target_doc_url"
  61. :doc_width="DOC_WIDTH"
  62. :positions="positions"
  63. >
  64. </ViewerDocxFromUrl>
  65. </template>
  66. </div>
  67. </main>
  68. </template>
  69. <script setup>
  70. import { onMounted, ref } from 'vue';
  71. import ViewerPDFFromUrl from '../viewer-pdf/ViewerPDFFromUrl.vue';
  72. import ViewerDocxFromUrl from '../viewer-docx/ViewerDocxFromUrl.vue';
  73. import { getDocumentUrl } from './document';
  74. const props = defineProps({
  75. targetDocument: Object
  76. });
  77. /**
  78. * 文档类别:doc/pdf
  79. */
  80. const getDocType = (doc_name) => {
  81. if (!doc_name) {
  82. return '';
  83. }
  84. const arr = doc_name.split('.');
  85. const len = arr.length;
  86. const end_fix = arr[len - 1];
  87. if (end_fix === 'pdf') {
  88. return 'pdf';
  89. }
  90. if (end_fix === 'docx' || end_fix === 'doc') {
  91. return 'doc';
  92. }
  93. return '';
  94. };
  95. const emit = defineEmits(['back']);
  96. const userName = ref('当前登录的用户名');
  97. const list = ref([]);
  98. const showPdfViewer = ref(false);
  99. const positions = ref([]);
  100. const pdfFather = ref(null);
  101. const DOC_WIDTH = ref(1100);
  102. const target_doc_url = ref('');
  103. const target_doc_type = ref('');
  104. let target_doc_id = ref(props.targetDocument.id);
  105. let target_chunk_id = ref('');
  106. target_doc_url.value = getDocumentUrl(props.targetDocument.id);
  107. target_doc_type.value = getDocType(props.targetDocument.doc_name);
  108. const pdfViewer = ref(null);
  109. const docData = props.targetDocument;
  110. list.value = docData.doc_aggs.map((item) => {
  111. return {
  112. ...item,
  113. fragments: docData.chunks.filter((chunk) => chunk.docnm_kwd === item.doc_name),
  114. desc: docData.chunks.filter((chunk) => chunk.docnm_kwd === item.doc_name)[0]?.content_ltks
  115. };
  116. });
  117. const goBack = () => {
  118. emit('back');
  119. };
  120. const handelChangePdf = (item) => {
  121. if (item.doc_id !== target_doc_id.value) {
  122. target_doc_url.value = getDocumentUrl(item.doc_id);
  123. target_doc_type.value = getDocType(item.doc_name);
  124. target_doc_id.value = item.doc_id;
  125. target_chunk_id.value = '';
  126. readLoadPdf();
  127. }
  128. };
  129. const handlerClickFragment = (frag) => {
  130. target_chunk_id.value = frag.chunk_id;
  131. if (frag.doc_id !== target_doc_id.value) {
  132. target_doc_url.value = getDocumentUrl(frag.doc_id);
  133. target_doc_type.value = getDocType(frag.doc_name);
  134. target_doc_id.value = frag.doc_id;
  135. readLoadPdf();
  136. }
  137. positions.value = [...frag.positions] || [];
  138. if (target_doc_type.value === 'pdf') {
  139. if (frag.positions && frag.positions.length) {
  140. pdfViewer.value.toPageIndex(positions.value[0][0], positions.value);
  141. }
  142. }
  143. };
  144. // 切换问答需要重新加载pdf
  145. const readLoadPdf = () => {
  146. positions.value = [];
  147. showPdfViewer.value = false;
  148. setTimeout(() => {
  149. showPdfViewer.value = true;
  150. });
  151. };
  152. onMounted(() => {
  153. DOC_WIDTH.value = pdfFather.value.getBoundingClientRect().width;
  154. const target_doc = props.targetDocument;
  155. const doc_id = target_doc.doc_id;
  156. const doc_name = target_doc.doc_name;
  157. // const doc_id = props.targetDocument.doc_id;
  158. target_doc_url.value = getDocumentUrl(doc_id);
  159. target_doc_type.value = getDocType(doc_name);
  160. showPdfViewer.value = true;
  161. });
  162. </script>
  163. <style scoped>
  164. main {
  165. display: flex;
  166. height: 100%;
  167. }
  168. main > div {
  169. height: 100%;
  170. }
  171. main > div.right {
  172. flex: 1;
  173. width: calc(100% - 460px);
  174. position: relative;
  175. }
  176. main > div.right .pdf-viewer {
  177. width: 100%;
  178. }
  179. main > div.left {
  180. width: 460px;
  181. padding: 20px 0 20px 20px;
  182. background: #e2e4eb;
  183. display: flex;
  184. flex-direction: column;
  185. /* height: calc(100vh - 48px - 65px); */
  186. height: calc(100vh - 48px - 117px);
  187. }
  188. main > div.left > header {
  189. padding-right: 20px;
  190. margin-bottom: 10px;
  191. }
  192. main > div.left > header > div {
  193. cursor: pointer;
  194. font-weight: bold;
  195. }
  196. main > div.left > header > div:hover {
  197. color: #00aea3;
  198. }
  199. main > div.left > div {
  200. display: flex;
  201. gap: 20px;
  202. padding: 20px 20px 20px 0;
  203. }
  204. main > div.left > div > div {
  205. width: 40px;
  206. height: 40px;
  207. border-radius: 20px;
  208. display: flex;
  209. align-items: center;
  210. justify-content: center;
  211. color: #fff;
  212. }
  213. main > div.left > div > p {
  214. background: #f6f8ff;
  215. border-radius: 0 12px 12px 12px;
  216. padding: 16px 16px;
  217. font-size: 16px;
  218. line-height: 1.6;
  219. }
  220. main > div.left > p {
  221. display: flex;
  222. justify-content: space-between;
  223. color: #727376;
  224. margin-bottom: 20px;
  225. padding-right: 20px;
  226. }
  227. main > div.left > section {
  228. flex: 1;
  229. overflow-y: auto;
  230. padding-right: 20px;
  231. }
  232. main > div.left > section > div {
  233. background: #fff;
  234. border-radius: 8px;
  235. padding: 12px;
  236. margin-bottom: 16px;
  237. cursor: pointer;
  238. gap: 5px;
  239. display: flex;
  240. border: 2px solid transparent;
  241. }
  242. main > div.left > section > div:hover,
  243. main > div.left > section > div.active {
  244. border: 2px solid #00aea3;
  245. }
  246. main > div.left > section > div > div > img {
  247. margin-top: 5px;
  248. }
  249. main > div.left > section > div > div > p:nth-child(1) {
  250. font-size: 16px;
  251. line-height: 28px;
  252. font-weight: bold;
  253. overflow: hidden;
  254. text-overflow: ellipsis;
  255. display: -webkit-box;
  256. -webkit-box-orient: vertical;
  257. -webkit-line-clamp: 2;
  258. margin-bottom: 8px;
  259. }
  260. main > div.left > section > div > div > p:nth-child(2) {
  261. font-size: 16px;
  262. line-height: 28px;
  263. overflow: hidden;
  264. text-overflow: ellipsis;
  265. display: -webkit-box;
  266. -webkit-box-orient: vertical;
  267. -webkit-line-clamp: 3;
  268. }
  269. main > div.left > section > div > div > span {
  270. display: flex;
  271. align-items: center;
  272. gap: 12px;
  273. margin: 12px 0;
  274. }
  275. main > div.left > section > div > div > span > b {
  276. font-style: normal;
  277. color: #aaa;
  278. font-size: 13px;
  279. }
  280. main > div.left > section > div > div > span > em {
  281. flex: 1;
  282. height: 1px;
  283. background: #e3e3e3;
  284. }
  285. main > div.left > section > div > div > div {
  286. overflow: hidden;
  287. white-space: nowrap;
  288. text-overflow: ellipsis;
  289. margin-bottom: 10px;
  290. font-size: 13px;
  291. line-height: 18px;
  292. width: 300px;
  293. cursor: pointer;
  294. }
  295. main > div.left > section > div > div > div:hover,
  296. main > div.left > section > div > div > div.active {
  297. color: #00aea3;
  298. }
  299. main > div.left > section > div > div > div span {
  300. margin-right: 5px;
  301. }
  302. main .activeBox {
  303. border: 3px solid #00aea3 !important;
  304. }
  305. main .activeLink {
  306. color: #00aea3 !important;
  307. }
  308. .right {
  309. height: calc(100vh - 48px - 65px);
  310. }
  311. </style>