| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344 |
- <template>
- <main>
- <div class="left">
- <header>
- <div @click="goBack"><icon-left style="margin-right: 5px" />返回知识问答</div>
- </header>
- <!-- <div>
- <div style="background-color: rgb(255, 110, 110)">{{ userName?.slice(0, 1) }}</div>
- <p>{{ targetDocument.question }}</p>
- </div> -->
- <p>
- <span>以下是根据您的提问搜索到的相关文档</span>
- <span>共 {{ list.length }} 条</span>
- </p>
- <section>
- <div
- :class="[item.doc_id === target_doc_id ? 'activeBox' : '']"
- v-for="(item, key) in list"
- :key="key"
- @click="handelChangePdf(item)"
- >
- <div>
- <img src="./icon.svg" />
- </div>
- <div>
- <p>{{ item.doc_name }}</p>
- <p>{{ item.desc }}</p>
- <span>
- <b>检索片段</b>
- <em></em>
- </span>
- <div
- :class="[frag.chunk_id === target_chunk_id ? 'activeLink' : '']"
- v-for="(frag, index) in item.fragments"
- :key="index"
- @click.stop="handlerClickFragment(frag)"
- >
- <span>{{ index + 1 }}.</span>
- {{ frag.content_with_weight }}
- </div>
- </div>
- </div>
- </section>
- </div>
- <div class="right" ref="pdfFather">
- <template v-if="showPdfViewer">
- <ViewerPDFFromUrl
- v-if="target_doc_type === 'pdf'"
- ref="pdfViewer"
- class="pdf-viewer"
- :url="target_doc_url"
- :doc_width="DOC_WIDTH"
- :positions="positions"
- >
- </ViewerPDFFromUrl>
- <ViewerDocxFromUrl
- v-if="target_doc_type === 'doc'"
- ref="pdfViewer"
- class="pdf-viewer"
- :url="target_doc_url"
- :doc_width="DOC_WIDTH"
- :positions="positions"
- >
- </ViewerDocxFromUrl>
- </template>
- </div>
- </main>
- </template>
- <script setup>
- import { onMounted, ref } from 'vue';
- import ViewerPDFFromUrl from '../viewer-pdf/ViewerPDFFromUrl.vue';
- import ViewerDocxFromUrl from '../viewer-docx/ViewerDocxFromUrl.vue';
- import { getDocumentUrl } from './document';
- const props = defineProps({
- targetDocument: Object
- });
- /**
- * 文档类别:doc/pdf
- */
- const getDocType = (doc_name) => {
- if (!doc_name) {
- return '';
- }
- const arr = doc_name.split('.');
- const len = arr.length;
- const end_fix = arr[len - 1];
- if (end_fix === 'pdf') {
- return 'pdf';
- }
- if (end_fix === 'docx' || end_fix === 'doc') {
- return 'doc';
- }
- return '';
- };
- const emit = defineEmits(['back']);
- const userName = ref('当前登录的用户名');
- const list = ref([]);
- const showPdfViewer = ref(false);
- const positions = ref([]);
- const pdfFather = ref(null);
- const DOC_WIDTH = ref(1100);
- const target_doc_url = ref('');
- const target_doc_type = ref('');
- let target_doc_id = ref(props.targetDocument.id);
- let target_chunk_id = ref('');
- target_doc_url.value = getDocumentUrl(props.targetDocument.id);
- target_doc_type.value = getDocType(props.targetDocument.doc_name);
- const pdfViewer = ref(null);
- const docData = props.targetDocument;
- list.value = docData.doc_aggs.map((item) => {
- return {
- ...item,
- fragments: docData.chunks.filter((chunk) => chunk.docnm_kwd === item.doc_name),
- desc: docData.chunks.filter((chunk) => chunk.docnm_kwd === item.doc_name)[0]?.content_ltks
- };
- });
- const goBack = () => {
- emit('back');
- };
- const handelChangePdf = (item) => {
- if (item.doc_id !== target_doc_id.value) {
- target_doc_url.value = getDocumentUrl(item.doc_id);
- target_doc_type.value = getDocType(item.doc_name);
- target_doc_id.value = item.doc_id;
- target_chunk_id.value = '';
- readLoadPdf();
- }
- };
- const handlerClickFragment = (frag) => {
- target_chunk_id.value = frag.chunk_id;
- if (frag.doc_id !== target_doc_id.value) {
- target_doc_url.value = getDocumentUrl(frag.doc_id);
- target_doc_type.value = getDocType(frag.doc_name);
- target_doc_id.value = frag.doc_id;
- readLoadPdf();
- }
- positions.value = [...frag.positions] || [];
- if (target_doc_type.value === 'pdf') {
- if (frag.positions && frag.positions.length) {
- pdfViewer.value.toPageIndex(positions.value[0][0], positions.value);
- }
- }
- };
- // 切换问答需要重新加载pdf
- const readLoadPdf = () => {
- positions.value = [];
- showPdfViewer.value = false;
- setTimeout(() => {
- showPdfViewer.value = true;
- });
- };
- onMounted(() => {
- DOC_WIDTH.value = pdfFather.value.getBoundingClientRect().width;
- const target_doc = props.targetDocument;
- const doc_id = target_doc.doc_id;
- const doc_name = target_doc.doc_name;
- // const doc_id = props.targetDocument.doc_id;
- target_doc_url.value = getDocumentUrl(doc_id);
- target_doc_type.value = getDocType(doc_name);
- showPdfViewer.value = true;
- });
- </script>
- <style scoped>
- main {
- display: flex;
- height: 100%;
- }
- main > div {
- height: 100%;
- }
- main > div.right {
- flex: 1;
- width: calc(100% - 460px);
- position: relative;
- }
- main > div.right .pdf-viewer {
- width: 100%;
- }
- main > div.left {
- width: 460px;
- padding: 20px 0 20px 20px;
- background: #e2e4eb;
- display: flex;
- flex-direction: column;
- /* height: calc(100vh - 48px - 65px); */
- height: calc(100vh - 48px - 117px);
- }
- main > div.left > header {
- padding-right: 20px;
- margin-bottom: 10px;
- }
- main > div.left > header > div {
- cursor: pointer;
- font-weight: bold;
- }
- main > div.left > header > div:hover {
- color: #00aea3;
- }
- main > div.left > div {
- display: flex;
- gap: 20px;
- padding: 20px 20px 20px 0;
- }
- main > div.left > div > div {
- width: 40px;
- height: 40px;
- border-radius: 20px;
- display: flex;
- align-items: center;
- justify-content: center;
- color: #fff;
- }
- main > div.left > div > p {
- background: #f6f8ff;
- border-radius: 0 12px 12px 12px;
- padding: 16px 16px;
- font-size: 16px;
- line-height: 1.6;
- }
- main > div.left > p {
- display: flex;
- justify-content: space-between;
- color: #727376;
- margin-bottom: 20px;
- padding-right: 20px;
- }
- main > div.left > section {
- flex: 1;
- overflow-y: auto;
- padding-right: 20px;
- }
- main > div.left > section > div {
- background: #fff;
- border-radius: 8px;
- padding: 12px;
- margin-bottom: 16px;
- cursor: pointer;
- gap: 5px;
- display: flex;
- border: 2px solid transparent;
- }
- main > div.left > section > div:hover,
- main > div.left > section > div.active {
- border: 2px solid #00aea3;
- }
- main > div.left > section > div > div > img {
- margin-top: 5px;
- }
- main > div.left > section > div > div > p:nth-child(1) {
- font-size: 16px;
- line-height: 28px;
- font-weight: bold;
- overflow: hidden;
- text-overflow: ellipsis;
- display: -webkit-box;
- -webkit-box-orient: vertical;
- -webkit-line-clamp: 2;
- margin-bottom: 8px;
- }
- main > div.left > section > div > div > p:nth-child(2) {
- font-size: 16px;
- line-height: 28px;
- overflow: hidden;
- text-overflow: ellipsis;
- display: -webkit-box;
- -webkit-box-orient: vertical;
- -webkit-line-clamp: 3;
- }
- main > div.left > section > div > div > span {
- display: flex;
- align-items: center;
- gap: 12px;
- margin: 12px 0;
- }
- main > div.left > section > div > div > span > b {
- font-style: normal;
- color: #aaa;
- font-size: 13px;
- }
- main > div.left > section > div > div > span > em {
- flex: 1;
- height: 1px;
- background: #e3e3e3;
- }
- main > div.left > section > div > div > div {
- overflow: hidden;
- white-space: nowrap;
- text-overflow: ellipsis;
- margin-bottom: 10px;
- font-size: 13px;
- line-height: 18px;
- width: 300px;
- cursor: pointer;
- }
- main > div.left > section > div > div > div:hover,
- main > div.left > section > div > div > div.active {
- color: #00aea3;
- }
- main > div.left > section > div > div > div span {
- margin-right: 5px;
- }
- main .activeBox {
- border: 3px solid #00aea3 !important;
- }
- main .activeLink {
- color: #00aea3 !important;
- }
- .right {
- height: calc(100vh - 48px - 65px);
- }
- </style>
|