RefferenceDocDetail.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <template>
  2. <main>
  3. <div class="left">
  4. <header>
  5. <div @click="goBack"><icon-left style="margin-right: 5px" />{{ $t('conversation.back') }}</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>{{ $t('conversation.related_docs') }}</span>
  13. <span>{{ $t('conversation.doc_total', { total: 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>{{ $t('conversation.fragments') }}</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 }}
  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 list = ref([]);
  97. const showPdfViewer = ref(false);
  98. const positions = ref([]);
  99. const pdfFather = ref(null);
  100. const DOC_WIDTH = ref(1100);
  101. const target_doc_url = ref('');
  102. const target_doc_type = ref('');
  103. let target_doc_id = ref(props.targetDocument.id);
  104. let target_chunk_id = ref('');
  105. target_doc_url.value = getDocumentUrl(props.targetDocument.id);
  106. target_doc_type.value = getDocType(props.targetDocument.doc_name);
  107. const pdfViewer = ref(null);
  108. const docData = props.targetDocument;
  109. list.value = docData.doc_aggs.map((item) => {
  110. return {
  111. ...item,
  112. fragments: docData.chunks.filter((chunk) => chunk.document_name === item.doc_name),
  113. desc: docData.chunks.filter((chunk) => chunk.document_name === item.doc_name)[0]?.content
  114. };
  115. });
  116. const goBack = () => {
  117. emit('back');
  118. };
  119. const handelChangePdf = (item) => {
  120. if (item.doc_id !== target_doc_id.value) {
  121. target_doc_url.value = getDocumentUrl(item.doc_id);
  122. target_doc_type.value = getDocType(item.doc_name);
  123. target_doc_id.value = item.doc_id;
  124. target_chunk_id.value = '';
  125. readLoadPdf();
  126. }
  127. };
  128. const handlerClickFragment = (frag) => {
  129. target_chunk_id.value = frag.id;
  130. if (frag.document_id !== target_doc_id.value) {
  131. target_doc_url.value = getDocumentUrl(frag.document_id);
  132. target_doc_type.value = getDocType(frag.document_name);
  133. target_doc_id.value = frag.document_id;
  134. readLoadPdf();
  135. }
  136. positions.value = [...frag.positions] || [];
  137. if (target_doc_type.value === 'pdf') {
  138. if (frag.positions && frag.positions.length) {
  139. pdfViewer.value.toPageIndex(positions.value[0][0], positions.value);
  140. }
  141. }
  142. };
  143. // 切换问答需要重新加载pdf
  144. const readLoadPdf = () => {
  145. positions.value = [];
  146. showPdfViewer.value = false;
  147. setTimeout(() => {
  148. showPdfViewer.value = true;
  149. });
  150. };
  151. onMounted(() => {
  152. DOC_WIDTH.value = pdfFather.value.getBoundingClientRect().width;
  153. const target_doc = props.targetDocument;
  154. const doc_id = target_doc.doc_id;
  155. const doc_name = target_doc.doc_name;
  156. // const doc_id = props.targetDocument.doc_id;
  157. target_doc_url.value = getDocumentUrl(doc_id);
  158. target_doc_type.value = getDocType(doc_name);
  159. showPdfViewer.value = true;
  160. });
  161. </script>
  162. <style scoped>
  163. main {
  164. display: flex;
  165. height: 100%;
  166. }
  167. main > div {
  168. height: 100%;
  169. }
  170. main > div.right {
  171. flex: 1;
  172. width: calc(100% - 460px);
  173. position: relative;
  174. }
  175. main > div.right .pdf-viewer {
  176. width: 100%;
  177. }
  178. main > div.left {
  179. width: 460px;
  180. padding: 20px 0 20px 20px;
  181. /* background: #e2e4eb; */
  182. background-color: var(--color-fill-2);
  183. color: var(--color-text-1);
  184. display: flex;
  185. flex-direction: column;
  186. /* height: calc(100vh - 48px - 65px); */
  187. height: calc(100vh - 48px - 117px);
  188. }
  189. main > div.left > header {
  190. padding-right: 20px;
  191. margin-bottom: 10px;
  192. }
  193. main > div.left > header > div {
  194. cursor: pointer;
  195. font-weight: bold;
  196. }
  197. main > div.left > header > div:hover {
  198. color: #00aea3;
  199. }
  200. main > div.left > div {
  201. display: flex;
  202. gap: 20px;
  203. padding: 20px 20px 20px 0;
  204. }
  205. main > div.left > div > div {
  206. width: 40px;
  207. height: 40px;
  208. border-radius: 20px;
  209. display: flex;
  210. align-items: center;
  211. justify-content: center;
  212. color: #fff;
  213. }
  214. main > div.left > div > p {
  215. /* background: #f6f8ff; */
  216. /* background-color: var(--color-bg-1); */
  217. border-radius: 0 12px 12px 12px;
  218. padding: 16px 16px;
  219. font-size: 16px;
  220. line-height: 1.6;
  221. }
  222. main > div.left > p {
  223. display: flex;
  224. justify-content: space-between;
  225. color: #727376;
  226. margin-bottom: 20px;
  227. padding-right: 20px;
  228. }
  229. main > div.left > section {
  230. flex: 1;
  231. overflow-y: auto;
  232. padding-right: 20px;
  233. }
  234. main > div.left > section > div {
  235. /* background: #fff; */
  236. background-color: var(--color-bg-1);
  237. border-radius: 8px;
  238. padding: 12px;
  239. margin-bottom: 16px;
  240. cursor: pointer;
  241. gap: 5px;
  242. display: flex;
  243. border: 2px solid transparent;
  244. }
  245. main > div.left > section > div:hover,
  246. main > div.left > section > div.active {
  247. border: 2px solid #00aea3;
  248. }
  249. main > div.left > section > div > div > img {
  250. margin-top: 5px;
  251. }
  252. main > div.left > section > div > div > p:nth-child(1) {
  253. font-size: 16px;
  254. line-height: 28px;
  255. font-weight: bold;
  256. overflow: hidden;
  257. text-overflow: ellipsis;
  258. display: -webkit-box;
  259. -webkit-box-orient: vertical;
  260. -webkit-line-clamp: 2;
  261. margin-bottom: 8px;
  262. }
  263. main > div.left > section > div > div > p:nth-child(2) {
  264. font-size: 16px;
  265. line-height: 28px;
  266. overflow: hidden;
  267. text-overflow: ellipsis;
  268. display: -webkit-box;
  269. -webkit-box-orient: vertical;
  270. -webkit-line-clamp: 3;
  271. }
  272. main > div.left > section > div > div > span {
  273. display: flex;
  274. align-items: center;
  275. gap: 12px;
  276. margin: 12px 0;
  277. }
  278. main > div.left > section > div > div > span > b {
  279. font-style: normal;
  280. color: #aaa;
  281. font-size: 13px;
  282. }
  283. main > div.left > section > div > div > span > em {
  284. flex: 1;
  285. height: 1px;
  286. background: #e3e3e3;
  287. }
  288. main > div.left > section > div > div > div {
  289. overflow: hidden;
  290. white-space: nowrap;
  291. text-overflow: ellipsis;
  292. margin-bottom: 10px;
  293. font-size: 13px;
  294. line-height: 18px;
  295. width: 300px;
  296. cursor: pointer;
  297. }
  298. main > div.left > section > div > div > div:hover,
  299. main > div.left > section > div > div > div.active {
  300. color: #00aea3;
  301. }
  302. main > div.left > section > div > div > div span {
  303. margin-right: 5px;
  304. }
  305. main .activeBox {
  306. border: 3px solid #00aea3 !important;
  307. }
  308. main .activeLink {
  309. color: #00aea3 !important;
  310. }
  311. .right {
  312. height: calc(100vh - 48px - 65px);
  313. }
  314. </style>