Parcourir la source

feat: 完善对话板块

zhupei@smartai.com il y a 1 an
Parent
commit
01c5dbad63

+ 1 - 0
src/modules/conversation-chat/DialogItem.vue

@@ -73,6 +73,7 @@ const answerInfo = computed(() => {
   obj.client_custom_linked_code = chat_info.client_custom_linked_code || '';
   obj.client_custom_linked_refference_full_content = chat_info.client_custom_linked_refference_full_content || '';
   obj.client_custom_linked_image = chat_info.client_custom_linked_image || '';
+  obj.client_custom_linked_download_files = chat_info.client_custom_linked_download_files || '';
 
   return obj;
 });

+ 41 - 0
src/modules/conversation-chat/chat-content.css

@@ -22,11 +22,52 @@
   text-align: center;
   display: block;
 }
+
+/* 正文文档来源header */
+.client-formated-markdown-refference-header {
+  display: flex;
+  justify-content: space-between;
+  align-items: center;
+}
 /* 正文底部文档引用列表 */
 .client-formated-markdown-doc-refference-container {
+  list-style: none;
+  margin: 0;
+  padding: 0;
 }
+
+/* 文档来源样式开始 */
 .client-formated-markdown-doc-refference-item {
+  display: flex;
+  justify-content: flex-start;
+  align-items: center;
+}
+.client-formated-markdown-doc-refference-item .refference-index {
+  display: inline-block;
+  background-color: #00aea333;
+  color: #00aea3;
+  padding: 1px 5px;
+  border-radius: 2px;
+  margin-right: 5px;
+  font-size: 12px;
+  cursor: pointer;
+}
+.client-formated-markdown-doc-refference-item .refference-label {
+}
+/* 文档来源样式结束 */
+
+/* 下载链接样式开始 */
+.client-formated-download-container {
+}
+.client-formated-download-container .download-link {
+  display: flex;
+  align-items: center;
+}
+.client-formated-download-container .download-link .download-icon {
+  display: inline-block;
+  margin-right: 5px;
 }
+/* 下载链接样式结束 */
 
 .dialog-markdown-container {
 }

+ 107 - 0
src/modules/conversation-dialog/api-dialog.js

@@ -71,6 +71,113 @@ export const uploadFiles = (agent_id, chat_id, file) => {
   });
 };
 
+/**
+ * 报表合并上传文件
+ * @param {FormData} file
+ * @returns
+ */
+export const uploadCombineExcelFiles = (file) => {
+  /**
+   * 响应数据示例
+   * 单文件
+   */
+  const res_example1 = { code: 200, msg: '', data: {} };
+
+  return ajax.post(`/api/document/excel/upload`, file, {
+    headers: {
+      'Content-Type': 'multipart/form-data'
+    }
+  });
+};
+
+/**
+ * 将 File 转换为文件上传用到的 formdata 数据
+ * @param {File[]} f_list
+ * @returns
+ */
+export const files2Formdata = (f_list, key_name) => {
+  const formData = new FormData();
+
+  f_list.forEach((item) => {
+    formData.append(key_name, item);
+  });
+
+  return formData;
+};
+
+/**
+ * 根据智能体上传文件
+ * @param {*} agent_id
+ * @param {*} chat_id
+ * @param {*} client_file
+ * @param {*} agentInfo
+ */
+export const uploadFileByAgentInfo = async (agent_id, chat_id, client_file, agentInfo) => {
+  const agent = agentInfo.agent;
+  console.log(agent, '什么啊');
+  const menu_id = agent.menuId / 1;
+
+  let files_response = null;
+
+  if (menu_id === 1) {
+    // 报表合并
+    const file_params = files2Formdata(client_file, 'files');
+
+    const uploadResult = await uploadCombineExcelFiles(file_params);
+
+    if (uploadResult.code / 1 === 200) {
+      const file_uploaded = uploadResult.data;
+
+      // TODO: 统一文件上传数据
+      // 文档智能的文件上传文件信息在 files 里
+      if (file_uploaded.files) {
+        files_response = file_uploaded.files;
+      } else {
+        if (Array.isArray(file_uploaded)) {
+          files_response = file_uploaded;
+        } else {
+          files_response = [file_uploaded];
+        }
+      }
+
+      return {
+        code: 200,
+        data: null
+      };
+    } else {
+      return uploadResult;
+    }
+  } else {
+    // 其他类型
+
+    const file_params = files2Formdata(client_file, 'file');
+    const uploadResult = await uploadFiles(agent_id, chat_id, file_params);
+
+    if (uploadResult.code / 1 === 200) {
+      const file_uploaded = uploadResult.data;
+
+      // TODO: 统一文件上传数据
+      // 文档智能的文件上传文件信息在 files 里
+      if (file_uploaded.files) {
+        files_response = file_uploaded.files;
+      } else {
+        if (Array.isArray(file_uploaded)) {
+          files_response = file_uploaded;
+        } else {
+          files_response = [file_uploaded];
+        }
+      }
+
+      return {
+        code: 200,
+        data: files_response
+      };
+    } else {
+      return uploadResult;
+    }
+  }
+};
+
 /**
  * 新建对话,根据agent获取chat_id
  * @returns {Promise<Object>}

+ 90 - 0
src/modules/conversation-dialog/format-dialog-answer-custom-markdown-str.js

@@ -0,0 +1,90 @@
+// import { jsonParse, jsonStringify } from '../../utils/utils';
+
+// import { formatCodePython, formatCodeSql } from './format-code-string';
+// import generateClientUniqueId from '../../utils/generate-client-unique-id';
+// import { getIcon4Answer } from './get-icon-4-dialog';
+
+// import formatAnwserString from './format-anwser-string';
+import { formatStaticAssetsUrl } from '../../utils/utils';
+
+/**
+ * 格式化文档引用的数据
+ * 将对象转换为字符串
+ * @param {object} refference
+ * @param {string} field_key - 数据中的相关字段
+ */
+export function formatRefferenceString(refference, field_key) {
+  if (!refference) {
+    return '';
+  }
+
+  const doc_aggs = refference.doc_aggs;
+
+  if (!doc_aggs) {
+    return '';
+  }
+
+  const refs_markdown = [];
+  if (Array.isArray(doc_aggs)) {
+    doc_aggs.forEach((item, index) => {
+      refs_markdown.push(
+        `<li
+          class="client-formated-markdown-element-item client-formated-markdown-doc-refference-item"
+          data-doc-id="${item.doc_id}"
+          data-real-index="${index}"
+          data-ref-key="${field_key}"
+        >
+          <span class="refference-index">${index + 1}</span>
+          <span class="refference-label">${item.doc_name}</span>
+        </li>`
+      );
+    });
+  }
+
+  const li_str = refs_markdown.join('');
+
+  const ref_header = `<header class="client-formated-markdown-element-item client-formated-markdown-refference-header">
+    <div>来源</div>
+    <div>查看全部关联</div>
+  </header>`;
+  const ref_list = `<ul class="client-formated-markdown-element-item client-formated-markdown-doc-refference-container" data-ref-key="${field_key}">${li_str}</ul>`;
+
+  return `${ref_header} ${ref_list}`;
+}
+
+export function formatRefferenceFlag(answer) {
+  let cur_text = answer;
+
+  cur_text = cur_text.replace(/##\d\$\$/g, function (match, index, full) {
+    // console.log(match, index, full);
+    // match示例数据 ##1$$ ##2$$
+    // 通过两次替换,字符串只剩下序号
+    const match_v1 = match.replace('##', '');
+    const match_v2 = match_v1.replace('$$', '');
+
+    const ref_idx = match_v2;
+
+    return `<span class="client-formated-markdown-element-item client-formated-markdown-doc-refference-flag" data-ref-index="${ref_idx}"></span>`;
+  });
+
+  return cur_text;
+}
+
+/**
+ * 处理文件下载链接
+ * @param {string} file_name
+ * @param {string} file_url
+ * @param {string} file_id
+ */
+export function formatFileDownloadStr(file_name, file_url, file_id) {
+  let real_url = file_url.replace('//', '/');
+  real_url = file_url.replace('/./', '/');
+  real_url = formatStaticAssetsUrl(real_url);
+
+  return `<div class="client-formated-markdown-element-item client-formated-download-container">
+    <a class="download-link" href="${real_url}" target="_blank">
+      <span class="download-icon"><svg viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg" stroke="currentColor" class="arco-icon arco-icon-download" stroke-width="4" stroke-linecap="butt" stroke-linejoin="miter" filter="downl" data-v-2bc6460e="" style="font-size: 32px;"><path d="m33.072 22.071-9.07 9.071-9.072-9.07M24 5v26m16 4v6H8v-6"></path></svg></span>
+      <span>${file_name}</span>
+    </a>
+  </div>`;
+}

+ 123 - 1
src/modules/conversation-dialog/format-dialog-answer-from-history.js

@@ -1,14 +1,25 @@
 import generateClientUniqueId from '../../utils/generate-client-unique-id';
+import { jsonParse, jsonStringify } from '../../utils/utils';
 
+import { formatCodePython, formatCodeSql } from './format-code-string';
 import { getIcon4Answer } from './get-icon-4-dialog';
 
+import formatAnwserString from './format-anwser-string';
+import { formatStaticAssetsUrl } from '../../utils/utils';
+
+import {
+  formatRefferenceString,
+  formatRefferenceFlag,
+  formatFileDownloadStr
+} from './format-dialog-answer-custom-markdown-str';
+
 /**
  * 格式化用户的对话记录的回答数据
  */
 export default function formatDialogAnswerFromHistory(item, agentInfo) {
   const icon_src = getIcon4Answer(agentInfo);
 
-  return {
+  const history_item = {
     /**
      * 对话消息类别
      * 0 历史消息
@@ -36,4 +47,115 @@ export default function formatDialogAnswerFromHistory(item, agentInfo) {
     client_custom_unique_id: generateClientUniqueId(item.answer),
     answer: item.answer
   };
+
+  const resType = item.type;
+  const resMessage = item.message; // 消息内容
+  const resRefference = item.reference; // 引用消息
+  const resStepMessage = item.step_message; // 消息内容
+  const resFiles = item.files; // 文件
+  const resMessageFiles = item.message_files; // 关联的文件
+  const resDownloadUrl = item.download_url; // 下载链接
+  const resFileUrl = item.file_url; // 文件链接
+  const resFileName = item.file_name; // 文件名称
+  const resImageUrl = item.image_url; // 图片链接
+  const resExcelUrl = item.excel_url; // excel链接
+  const resExcelName = item.excel_name; // excel文件
+  const resCode = item.code; // 代码内容
+  const resSQL = item.sql; // SQL内容
+
+  if (resExcelUrl && resExcelName) {
+    // 智能数据需要用到的值
+    history_item.client_custom_linked_download_files = {
+      file_name: resExcelName,
+      file_url: resExcelUrl
+    };
+  }
+
+  if (resFileUrl && resFileName) {
+    // 出题组卷可能存在此数据
+    history_item.client_custom_linked_download_files = {
+      file_name: resFileName,
+      file_url: resFileUrl
+    };
+  }
+
+  if (resDownloadUrl) {
+    // 文档报告可能存在此数据(type document_report)
+    const real_url = decodeURIComponent(resDownloadUrl);
+
+    const file_url_arr = decodeURIComponent(resDownloadUrl).split('/');
+    const file_name = file_url_arr[file_url_arr.length - 1];
+
+    history_item.client_custom_linked_download_files = {
+      file_name: file_name,
+      file_url: real_url
+    };
+  }
+
+  // -------------------------------------------------------------
+  // -------------------------------------------------------------
+  // -------------------------------------------------------------
+  // -------------------------------------------------------------
+  // -------------------------------------------------------------
+  // -------------------------------------------------------------
+  // -------------------------------------------------------------
+  // 智能数据:代码和图片处理
+  // 上传一个excel,提问:生成一个饼状图
+  if (resCode) {
+    // 智能数据可能存在此字段
+    const code_formated = formatCodePython(resCode);
+
+    history_item.client_custom_linked_code = code_formated;
+  }
+
+  if (resSQL) {
+    // 智能数据可能存在此字段
+    // 代码数据不能使用markdown解析器进行解析,否则会乱码
+    const sql_formated = formatCodeSql(resSQL);
+
+    history_item.client_custom_linked_sql = sql_formated;
+  }
+
+  if (resImageUrl) {
+    // 智能数据可能会存在此值
+    history_item.client_custom_linked_image = resImageUrl;
+  }
+
+  if (resFiles) {
+    if (resFiles[0]) {
+      history_item.client_custom_linked_download_files = {
+        file_name: resFiles[0].file_name,
+        file_url: resFiles[0].file_url
+      };
+    }
+  }
+
+  // ------------------------
+  // ------------------------
+  // ------------------------
+  // ------------------------
+  // 处理可能存在的文档引用效果
+  // 在知识问答板块中,正文存在文档引用效果
+  history_item.answer = formatRefferenceFlag(history_item.answer);
+  // 文档引用效果
+  if (resRefference) {
+    // 文档引用,在知识问答板块中,存在一些文档引用内容
+    // 需要在对话的答案底部显示文档引用的节点
+    // 将文档引用相关的数据拼接到答案的底部
+    const ref_str = formatRefferenceString(resRefference, 'client_custom_linked_refference_full_content');
+
+    if (ref_str) {
+      history_item.answer =
+        history_item.answer +
+        `
+        ${ref_str}
+      `;
+    }
+
+    // 添加字段:客户端自定义的相关字段,link完整数据
+    // 在答案展示部分,需要根据此数据展示文档引用效果
+    history_item.client_custom_linked_refference_full_content = resRefference;
+  }
+
+  return history_item;
 }

+ 91 - 91
src/modules/conversation-dialog/format-dialog-answer-from-websocket_receive_message.js

@@ -5,63 +5,13 @@ import generateClientUniqueId from '../../utils/generate-client-unique-id';
 import { getIcon4Answer } from './get-icon-4-dialog';
 
 import formatAnwserString from './format-anwser-string';
+import { formatStaticAssetsUrl } from '../../utils/utils';
 
-/**
- * 格式化文档引用的数据
- * 将对象转换为字符串
- * @param {object} refference
- * @param {string} field_key - 数据中的相关字段
- */
-function formatRefferenceString(refference, field_key) {
-  if (!refference) {
-    return '';
-  }
-
-  const doc_aggs = refference.doc_aggs;
-
-  if (!doc_aggs) {
-    return '';
-  }
-
-  const refs_markdown = [];
-  if (Array.isArray(doc_aggs)) {
-    doc_aggs.forEach((item, index) => {
-      refs_markdown.push(
-        `<li
-          class="client-formated-markdown-element-item client-formated-markdown-doc-refference-item"
-          data-doc-id="${item.doc_id}"
-          data-real-index="${index}"
-          data-ref-key="${field_key}"
-        >
-          <span class="refference-index">${index + 1}</span>
-          <span class="refference-label">${item.doc_name}</span>
-        </li>`
-      );
-    });
-  }
-
-  const li_str = refs_markdown.join('');
-
-  return `<ul class="client-formated-markdown-element-item client-formated-markdown-doc-refference-container" data-ref-key="${field_key}">${li_str}</ul>`;
-}
-
-function formatRefferenceFlag(answer) {
-  let cur_text = answer;
-
-  cur_text = cur_text.replace(/##\d\$\$/g, function (match, index, full) {
-    // console.log(match, index, full);
-    // match示例数据 ##1$$ ##2$$
-    // 通过两次替换,字符串只剩下序号
-    const match_v1 = match.replace('##', '');
-    const match_v2 = match_v1.replace('$$', '');
-
-    const ref_idx = match_v2;
-
-    return `<span class="client-formated-markdown-element-item client-formated-markdown-doc-refference-flag" data-ref-index="${ref_idx}"></span>`;
-  });
-
-  return cur_text;
-}
+import {
+  formatRefferenceString,
+  formatRefferenceFlag,
+  formatFileDownloadStr
+} from './format-dialog-answer-custom-markdown-str';
 
 /**
  * 格式化websocket发送消息的参数
@@ -101,6 +51,16 @@ export default function formatDialogAnswerFromWebsocketReceiveMessage(message_st
   const resCode = res_content.code; // 代码内容
   const resSQL = res_content.sql; // SQL内容
 
+  // 文档出卷返回的数据
+  // 需要进行文件下载
+  // file_name: "76157b5884554a56bf3ed27990d44f97_1734603024"
+  // file_url: "/api/files/download/?agent_id=basic_question_talk&file_id=76157b5884554a56bf3ed27990d44f97_1734603024&file_type=word"
+  // message: "已经为您生成了10道中等难度的选择题,并已将这些题目保存到名为76157b5884554a56bf3ed27990d44f97_1734603024的docx文件中。希望这些题目符合您的需求!如果有其他要求,请随时告知。"
+  // type: "message"
+  // ------------------------------------
+
+  // 报表合并返回的数据:需要进行文件下载
+
   // 本次对话的消息内容
   const currentMsg = {
     /**
@@ -162,42 +122,70 @@ export default function formatDialogAnswerFromWebsocketReceiveMessage(message_st
 
     if (resExcelUrl && resExcelName) {
       // 智能数据需要用到的值
-      const port = window.location.port ? `:${window.location.port}` : '';
+      // const port = window.location.port ? `:${window.location.port}` : '';
 
-      const file = {
-        file_type: 'excel',
-        file_url: `http://${window.location.hostname}${port}${resExcelUrl}`,
-        file_name: `${resExcelName}.xlsx` || '点击下载'
+      // const file = {
+      //   file_type: 'excel',
+      //   file_url: `http://${window.location.hostname}${port}${resExcelUrl}`,
+      //   file_name: `${resExcelName}.xlsx` || '点击下载'
+      // };
+
+      // currentMsg.file = file;
+
+      currentMsg.client_custom_linked_download_files = {
+        file_name: resExcelName,
+        file_url: resExcelUrl
       };
 
-      currentMsg.file = file;
+      // const download_file_str = formatFileDownloadStr(resExcelName, resExcelUrl);
+
+      // currentMsg.answer = currentMsg.agentInfo + download_file_str;
     }
 
     if (resFileUrl && resFileName) {
       // 出题组卷可能存在此数据
-      const port = window.location.port ? `:${window.location.port}` : '';
+      // const port = window.location.port ? `:${window.location.port}` : '';
+
+      // const file = {
+      //   file_type: 'word',
+      //   file_url: `http://${window.location.hostname}${port}${resFileUrl}`,
+      //   file_name: `${resFileName}.docx` || '点击下载'
+      // };
 
-      const file = {
-        file_type: 'word',
-        file_url: `http://${window.location.hostname}${port}${resFileUrl}`,
-        file_name: `${resFileName}.docx` || '点击下载'
+      // currentMsg.file = file;
+
+      currentMsg.client_custom_linked_download_files = {
+        file_name: resFileName,
+        file_url: resFileUrl
       };
 
-      currentMsg.file = file;
+      // const download_file_str = formatFileDownloadStr(resFileName, resFileUrl);
+
+      // currentMsg.answer = currentMsg.agentInfo + download_file_str;
     }
 
     if (resDownloadUrl) {
       // 文档报告可能存在此数据(type document_report)
+      const real_url = decodeURIComponent(resDownloadUrl);
+
       const file_url_arr = decodeURIComponent(resDownloadUrl).split('/');
       const file_name = file_url_arr[file_url_arr.length - 1];
 
-      const file = {
-        file_type: 'word',
-        file_url: resDownloadUrl,
-        file_name: `${file_name}.docx` || '点击下载'
-      };
+      // const file = {
+      //   file_type: 'word',
+      //   file_url: resDownloadUrl,
+      //   file_name: `${file_name}.docx` || '点击下载'
+      // };
+
+      // currentMsg.file = file;
 
-      currentMsg.file = file;
+      // const download_file_str = formatFileDownloadStr(file_name, real_url);
+
+      // currentMsg.answer = currentMsg.agentInfo + download_file_str;
+      currentMsg.client_custom_linked_download_files = {
+        file_name: file_name,
+        file_url: real_url
+      };
     }
 
     // -------------------------------------------------------------
@@ -278,27 +266,39 @@ export default function formatDialogAnswerFromWebsocketReceiveMessage(message_st
     }
 
     if (resFiles) {
+      // 文档合并有此数据
       const file_name = resFiles[0].file_name;
-      const file_info_arr = file_name.split('.');
-      const end_fix = file_info_arr[file_info_arr.length - 1];
+      // const file_info_arr = file_name.split('.');
+      // const end_fix = file_info_arr[file_info_arr.length - 1];
+
+      // const file = {
+      //   file_name: resFiles[0].file_name,
+      //   file_url: resFiles[0].file_url
+      // };
+
+      // // 理论上报表合并,只能是 excel
+      // // if(chat_type === 'excel'){
+      // //   file.file_type = 'excel'
+      // // }
+      // if (end_fix === 'xlsx') {
+      //   file.file_type = 'excel';
+      // }
+      // if (end_fix === 'docx') {
+      //   file.file_type = 'word';
+      // }
 
-      const file = {
-        file_name: resFiles[0].file_name,
-        file_url: resFiles[0].file_url
-      };
+      // currentMsg.file = file;
 
-      // 理论上报表合并,只能是 excel
-      // if(chat_type === 'excel'){
-      //   file.file_type = 'excel'
-      // }
-      if (end_fix === 'xlsx') {
-        file.file_type = 'excel';
-      }
-      if (end_fix === 'docx') {
-        file.file_type = 'word';
-      }
+      if (resFiles[0]) {
+        // console.log('报表合并,所有文件', resFiles);
+        // const download_file_str = formatFileDownloadStr(resFiles[0].file_name, resFiles[0].file_url);
+        // console.log('报表合并,所有文件', download_file_str);
 
-      currentMsg.file = file;
+        currentMsg.client_custom_linked_download_files = {
+          file_name: resFiles[0].file_name,
+          file_url: resFiles[0].file_url
+        };
+      }
     }
   }
 

+ 1 - 0
src/modules/conversation-dialog/format-dialog-send-options.js

@@ -21,6 +21,7 @@ export default function formatDialogSendOptions(text, file_list, agentInfo) {
   switch (menu_id) {
     case 1:
       // 报表合并
+      send_data = '合并Excel';
       break;
     case 2:
       // 知识问答

+ 9 - 2
src/modules/conversation-item/DialogAnswer.vue

@@ -41,6 +41,7 @@ import BtnStopChat from './BtnStopChat.vue';
 import DialogContent from '../conversation-content/DialogContent.vue';
 
 import formatAnwserString from '../conversation-dialog/format-anwser-string';
+import { formatFileDownloadStr } from '../conversation-dialog/format-dialog-answer-custom-markdown-str';
 import { getIconIntelligent } from '../common/icon-map';
 import { formatStaticAssetsUrl } from '../../utils/utils';
 
@@ -93,8 +94,6 @@ const answer_html = computed(() => {
   const answer = props.answer;
   const str = answer.content;
 
-  // return str;
-
   let answer_string = formatAnwserString(str);
 
   // 由于SQL和代码不能通过markdown解析,所以此处进行字符串的拼接
@@ -112,6 +111,14 @@ const answer_html = computed(() => {
     answer_string = answer_string + `<img src="${img_url}" />`;
   }
 
+  // 处理下载链接
+  if (answer.client_custom_linked_download_files) {
+    const file_name = answer.client_custom_linked_download_files.file_name;
+    const file_url = answer.client_custom_linked_download_files.file_url;
+    const download_file_str = formatFileDownloadStr(file_name, file_url);
+    answer_string = answer_string + download_file_str;
+  }
+
   return answer_string;
 });
 

+ 2 - 2
src/modules/file-preview/files-2-formdata.js

@@ -3,7 +3,7 @@
  * @param {File[]} f_list
  * @returns
  */
-export default function files2Formdata(f_list) {
+export const files2Formdata = (f_list, agentInfo) => {
   const formData = new FormData();
 
   f_list.forEach((item) => {
@@ -11,4 +11,4 @@ export default function files2Formdata(f_list) {
   });
 
   return formData;
-}
+};

+ 44 - 18
src/views/conversation/ConversationChatContainer.vue

@@ -69,8 +69,14 @@ import DialogAsideRight from '../../modules/conversation-chat/DialogAsideRight.v
 import getChatAgentInfomation from '../../modules/conversation-board/get-chat-agent-infomation';
 
 import useWebSocketChat from '../../modules/conversation-dialog/use-websocket-chat';
-import { getHistoryLogs, getDialogChatId, uploadFiles } from '../../modules/conversation-dialog/api-dialog';
-import files2Formdata from '../../modules/file-preview/files-2-formdata';
+import {
+  getHistoryLogs,
+  getDialogChatId,
+  uploadFiles,
+  uploadCombineExcelFiles,
+  uploadFileByAgentInfo
+} from '../../modules/conversation-dialog/api-dialog';
+import { files2Formdata } from '../../modules/file-preview/files-2-formdata';
 
 import formatDialogSendOptions from '../../modules/conversation-dialog/format-dialog-send-options';
 
@@ -190,6 +196,17 @@ const chat_display_list = computed(() => {
   return [].concat(chat_log_list.value, chat_new_list.value);
 });
 
+/**
+ * 当前对话的类型
+ */
+const current_chat_type = computed(() => {
+  const agent = CHAT_AGENT_INFOMATION.value.agent;
+  const menu_id = agent.menuId / 1;
+  const chat_type = menu_id === 1 ? 'excel' : '';
+
+  return chat_type;
+});
+
 /**
  * 是否显示欢迎页
  * 当用户进入对话页面,还未正式开始对话时
@@ -402,27 +419,28 @@ const handleInputSubmit = async (options) => {
    */
   if (ask_files.length !== 0) {
     // 进行文件上传,获取文件信息
-    const file_params = files2Formdata(ask_files);
+
     const chat_id = chat_new_id.value;
 
     try {
-      const uploadResult = await uploadFiles(agent_id, chat_id, file_params);
+      // const file_params = files2Formdata(ask_files);
+      const uploadResult = await uploadFileByAgentInfo(agent_id, chat_id, ask_files, CHAT_AGENT_INFOMATION.value);
 
       if (uploadResult.code / 1 === 200) {
         // 文件上传成功
-        const file_uploaded = uploadResult.data;
-
-        // TODO: 统一文件上传数据
-        // 文档智能的文件上传文件信息在 files 里
-        if (file_uploaded.files) {
-          files_response = file_uploaded.files;
-        } else {
-          if (Array.isArray(file_uploaded)) {
-            files_response = file_uploaded;
-          } else {
-            files_response = [file_uploaded];
-          }
-        }
+        files_response = uploadResult.data;
+
+        // // TODO: 统一文件上传数据
+        // // 文档智能的文件上传文件信息在 files 里
+        // if (file_uploaded.files) {
+        //   files_response = file_uploaded.files;
+        // } else {
+        //   if (Array.isArray(file_uploaded)) {
+        //     files_response = file_uploaded;
+        //   } else {
+        //     files_response = [file_uploaded];
+        //   }
+        // }
       } else {
         // 文件上传异常
         handleChatRequestionException({
@@ -513,8 +531,16 @@ function handleWSSend(chat_id, value) {
    * 1. 初始化链接
    * 2. 发送消息
    */
+
+  /**
+   * 当对话类型为文档报告时,websocket连接地址不同
+   */
+  // const agent = CHAT_AGENT_INFOMATION.value.agent;
+  // const menu_id = agent.menuId / 1;
+  // const chat_type = menu_id === 1 ? 'excel' : '';
+
   //  初始化websocket连接
-  initWSConnection(props.agent_id, chat_id, props.chat_type);
+  initWSConnection(props.agent_id, chat_id, current_chat_type.value);
   // 发送socket连接
   sendWSMessage(value);
   /**

+ 9 - 1
src/views/conversation/ConversationHistoryContainer.vue

@@ -62,6 +62,7 @@ const page_no = ref(1); // 当前页码
 const page_count = ref(50); // 每页显示的数量
 const search_text = ref(''); // 搜索字符串
 const agent_id = ref('');
+// const agent_item = ref(null);
 
 const can_loadmore = ref(true); // 是否可以加载更多
 
@@ -165,6 +166,11 @@ const formatListOptions = () => {
  * 调用api请求
  */
 const handleApiRequest = () => {
+  // const cur_agent = agent_item.value;
+  // if (cur_agent.menuId === 1) {
+  //   // 报表合并: 报表合并需要使用领一个历史记录
+  // }
+
   // 处理查询参数
   const opts = formatListOptions();
 
@@ -264,6 +270,8 @@ const handleTypeSelected = (type_item) => {
     return;
   }
 
+  // agent_item.value = type_item;
+
   // 统计数据归位
   count_today.value = 0;
   count_month.value = 0;
@@ -277,7 +285,7 @@ const handleTypeSelected = (type_item) => {
   list_history.value = []; // 清空数据
 
   // 调用api
-  handleApiRequest();
+  handleApiRequest(type_item);
 };
 
 onMounted(() => {