Переглянути джерело

fix: 修复文档引用文档读取异常的bug

zhupei@smartai.com 1 рік тому
батько
коміт
beea2af676

+ 4 - 1
src/modules/answer-pdf-viewer/PDFViewer.vue

@@ -257,8 +257,11 @@ const toPageIndex = async (pageNumber, positions) => {
   if (!pdfDocument) {
     return;
   }
+
   setTimeout(() => {
-    box.value.scrollTop = height_list[pageNumber - 1];
+    if (box.value) {
+      box.value.scrollTop = height_list[pageNumber - 1];
+    }
   });
   if (!drawPages.includes(pageNumber)) {
     const highPos = highlight_position(positions);

+ 5 - 1
src/modules/answer-refference/RefferenceDocDetail.vue

@@ -73,7 +73,7 @@ const emit = defineEmits(['back']);
 const userName = ref('当前登录的用户名');
 
 const list = ref([]);
-const showPdfViewer = ref(true);
+const showPdfViewer = ref(false);
 const positions = ref([]);
 const pdfFather = ref(null);
 const DOC_WIDTH = ref(1100);
@@ -132,6 +132,10 @@ const readLoadPdf = () => {
 
 onMounted(() => {
   DOC_WIDTH.value = pdfFather.value.getBoundingClientRect().width;
+
+  const doc_id = props.targetDocument.doc_id;
+  pdf_url.value = getDocumentUrl(doc_id);
+  showPdfViewer.value = true;
 });
 </script>
 

+ 75 - 3
src/modules/answer-refference/RefferenceFileBlocks.vue

@@ -5,7 +5,7 @@
       <div class="btn-show-related-all" @click="showAllRelated">查看全部关联 <icon-double-right /></div>
     </header>
 
-    <RefferenceFileNameList :doc_aggs="doc_aggs" :chunks="chunks" @showDocDetail="handleShowDocDetail" />
+    <RefferenceFileNameList :document_list="document_list" @showDocDetail="handleShowDocDetail" />
 
     <a-drawer
       :width="'90%'"
@@ -26,7 +26,7 @@
 </template>
 
 <script setup>
-import { ref } from 'vue';
+import { ref, computed } from 'vue';
 
 import RefferenceFileNameList from './RefferenceFileNameList.vue';
 
@@ -40,6 +40,44 @@ const props = defineProps({
 const visible = ref(false);
 const position = ref('right');
 
+const document_list = computed(() => {
+  const doc_list = props.doc_aggs;
+  const chunks = props.chunks;
+
+  const res_list = [];
+
+  const len = doc_list.length;
+  for (let i = 0; i < len; i++) {
+    const doc = doc_list[i];
+
+    const res_doc = {
+      doc_id: doc.doc_id,
+      doc_name: doc.doc_name,
+      count: doc.count,
+      page: i
+    };
+
+    const cur_doc_id = doc.doc_id;
+
+    const cur_doc_peaces = [];
+    if (chunks && Array.isArray(chunks)) {
+      chunks.forEach((item, index) => {
+        const chunk_doc_id = item.doc_id;
+
+        if (cur_doc_id === chunk_doc_id) {
+          cur_doc_peaces.push(item.content_ltks);
+        }
+      });
+    }
+
+    res_doc.content_ltks = cur_doc_peaces;
+
+    res_list.push(res_doc);
+  }
+
+  return res_list;
+});
+
 /**
  * 目标数据
  */
@@ -58,14 +96,48 @@ const handleCancel = () => {
   visible.value = false;
 };
 
-const handleShowDocDetail = (doc_item) => {
+const handleShowDocDetail = (item) => {
+  console.log(item, '查看文档详情');
+
   // TODO:组装参数数据
+  const cur_tar = targetDocument.value;
+
+  const obj = {
+    doc_aggs: cur_tar.doc_aggs,
+    chunks: cur_tar.chunks,
+    doc_id: item.doc_id,
+    doc_name: item.doc_name,
+    count: item.count,
+    content_ltks: item.content_ltks
+  };
+
+  targetDocument.value = obj;
 
   // 展示文档详情
   handleClick();
 };
 
+/**
+ * 显示第一个
+ */
 const showAllRelated = () => {
+  const item = document_list.value[0];
+
+  console.log('显示第一个');
+
+  const cur_tar = targetDocument.value;
+
+  const obj = {
+    doc_aggs: cur_tar.doc_aggs,
+    chunks: cur_tar.chunks,
+    doc_id: item.doc_id,
+    doc_name: item.doc_name,
+    count: item.count,
+    content_ltks: item.content_ltks
+  };
+
+  targetDocument.value = obj;
+
   handleClick();
 };
 

+ 1 - 81
src/modules/answer-refference/RefferenceFileNameItem.vue

@@ -10,41 +10,15 @@
         <RefferenceFileNameContentLinks
           :content_ltks="knowledge.content_ltks"
           :page="knowledge.page"
-          @showDocument="goKnowledge"
+          @showDocument="goKnowledge(knowledge.doc_name)"
         />
-
-        <!-- <div class="knowledge-detail">
-          <div class="knowledge-content">
-            {{ knowledge.content_ltks }}
-          </div>
-
-          <div class="knowledge-footer">
-            <p>检索片段</p>
-            <p>
-              <span
-                v-for="(content, contentIndex) in knowledge.content_ltks"
-                :key="contentIndex"
-                :class="{ active: knowledge.page === contentIndex }"
-                @click="
-                  () => {
-                    knowledge.page = contentIndex;
-                  }
-                "
-                >{{ contentIndex + 1 }}</span
-              >
-            </p>
-            <p @click="goKnowledge(knowledge)">查看详情></p>
-          </div>
-        </div> -->
       </template>
     </a-popover>
   </div>
 </template>
 
 <script setup>
-import { defineComponent, ref, onBeforeUnmount, onMounted, reactive, nextTick, inject } from 'vue';
 import { defineEmits } from 'vue';
-import { getDocumentUrl } from './document';
 import RefferenceFileNameContentLinks from './RefferenceFileNameContentLinks.vue';
 
 const props = defineProps({
@@ -61,58 +35,6 @@ const goKnowledge = (knowledge) => {
 </script>
 
 <style scoped>
-.knowledge-detail {
-  /* width: 320px; */
-  /* padding-top: 20px; */
-}
-
-.knowledge-content {
-  height: 300px;
-  overflow-y: auto;
-  line-height: 30px;
-}
-
-.knowledge-footer {
-  border-top: 1px solid rgba(229, 229, 229, 1);
-  /* margin-top: 20px;
-  padding-top: 20px; */
-  display: flex;
-  justify-content: space-between;
-  align-items: center;
-  /*
-  p {
-    &:nth-child(1) {
-      opacity: 0.8;
-    }
-
-    &:nth-child(2) {
-      flex: 1;
-      display: flex;
-      justify-content: left;
-      margin: 0 30px;
-
-      > span {
-        margin: 0 5px;
-        cursor: pointer;
-
-        &:hover,
-        &.active {
-          color: #00aea3;
-        }
-      }
-    }
-
-    &:nth-child(3) {
-      font-weight: bold;
-      cursor: pointer;
-
-      &:hover {
-        color: #00aea3;
-      }
-    }
-  } */
-}
-
 .doc-ref-container {
   height: 32px;
   display: inline-flex;
@@ -128,12 +50,10 @@ const goKnowledge = (knowledge) => {
   margin-right: 5px;
   font-size: 12px;
 
-  /* margin: 0 5px; */
   cursor: pointer;
 }
 
 .doc-ref-label {
-  /* margin: 0 5px; */
   cursor: pointer;
 }
 

+ 30 - 30
src/modules/answer-refference/RefferenceFileNameList.vue

@@ -13,49 +13,49 @@ import { onMounted, computed } from 'vue';
 import RefferenceFileNameItem from './RefferenceFileNameItem.vue';
 
 const props = defineProps({
-  doc_aggs: Array,
-  chunks: Array
+  document_list: Array
+  // chunks: Array
 });
 
 const emit = defineEmits(['showDocDetail']);
 
-const document_list = computed(() => {
-  const doc_list = props.doc_aggs;
-  const chunks = props.chunks;
+// const document_list = computed(() => {
+//   const doc_list = props.doc_aggs;
+//   const chunks = props.chunks;
 
-  const res_list = [];
+//   const res_list = [];
 
-  const len = doc_list.length;
-  for (let i = 0; i < len; i++) {
-    const doc = doc_list[i];
+//   const len = doc_list.length;
+//   for (let i = 0; i < len; i++) {
+//     const doc = doc_list[i];
 
-    const res_doc = {
-      doc_id: doc.doc_id,
-      doc_name: doc.doc_name,
-      count: doc.count,
-      page: i
-    };
+//     const res_doc = {
+//       doc_id: doc.doc_id,
+//       doc_name: doc.doc_name,
+//       count: doc.count,
+//       page: i
+//     };
 
-    const cur_doc_id = doc.doc_id;
+//     const cur_doc_id = doc.doc_id;
 
-    const cur_doc_peaces = [];
-    if (chunks && Array.isArray(chunks)) {
-      chunks.forEach((item, index) => {
-        const chunk_doc_id = item.doc_id;
+//     const cur_doc_peaces = [];
+//     if (chunks && Array.isArray(chunks)) {
+//       chunks.forEach((item, index) => {
+//         const chunk_doc_id = item.doc_id;
 
-        if (cur_doc_id === chunk_doc_id) {
-          cur_doc_peaces.push(item.content_ltks);
-        }
-      });
-    }
+//         if (cur_doc_id === chunk_doc_id) {
+//           cur_doc_peaces.push(item.content_ltks);
+//         }
+//       });
+//     }
 
-    res_doc.content_ltks = cur_doc_peaces;
+//     res_doc.content_ltks = cur_doc_peaces;
 
-    res_list.push(res_doc);
-  }
+//     res_list.push(res_doc);
+//   }
 
-  return res_list;
-});
+//   return res_list;
+// });
 
 /**
  * 展示文档详情

+ 6 - 8
src/modules/conversation-dialog/format-dialog-send-options.js

@@ -1,18 +1,16 @@
-import { jsonParse, jsonStringify } from '../../utils/utils';
+// import { jsonParse, jsonStringify } from '../../utils/utils';
 
 /**
  * 组装发送websocket消息时的参数
  * @param {string} text - 纯文本数据
  * @param {object[]} file_list - 文件上传后,接口返回的数据信息,某些场景需要携带文件数据,此值可能为null
- * @param {object} agentInfo - agent信息,发送websocket的数据根据agent的不同而不同
- * @param {object} agentInfo.agent - Agent基本信息
- * @param {object} agentInfo.config - 客户端对于agent的配置项目
+ * @param {number} menu_id - agent信息,发送websocket的数据根据agent的不同而不同
  * @returns
  */
-export default function formatDialogSendOptions(text, file_list, agentInfo) {
-  const agent = agentInfo.agent || {};
-  const agent_id = agentInfo.id; // agent的ID值
-  const menu_id = agent.menuId / 1;
+export default function formatDialogSendOptions(text, file_list, menu_id) {
+  // const agent = agentInfo.agent || {};
+  // const agent_id = agentInfo.id; // agent的ID值
+  // const menu_id = agent.menuId / 1;
 
   let send_data = {
     message: text

+ 13 - 1
src/views/conversation/ConversationChatContainer.vue

@@ -197,6 +197,18 @@ const chat_display_list = computed(() => {
   return [].concat(chat_log_list.value, chat_new_list.value);
 });
 
+/**
+ * 菜单ID编号
+ * 1 报表合并
+ * 2 知识问答
+ * 3 文档智能
+ * 4 智能问答
+ * 5 智能数据
+ * 6 小数绘图
+ * 7 文档出卷
+ * 8 出题组卷
+ * 9 文档报告
+ */
 const current_menu_id = computed(() => {
   const agent = CHAT_AGENT_INFOMATION.value.agent;
   const menu_id = agent.menuId / 1;
@@ -466,7 +478,7 @@ const handleInputSubmit = async (options) => {
    * 组装socket参数: 文本和文件
    * 此方法会依据当前使用的agent,组装好传递给websocket的基础的文本和文件的参数
    */
-  const msg_obj = formatDialogSendOptions(ask_text, files_response, CHAT_AGENT_INFOMATION.value);
+  const msg_obj = formatDialogSendOptions(ask_text, files_response, current_menu_id.value);
 
   /**
    * 文本和文件的数据已经组装完成