Selaa lähdekoodia

feat: 调整websocket链接地址和文件下载地址

以适应后端关于报表合并的调整
zhupei@smartai.com 1 vuosi sitten
vanhempi
sitoutus
951600858d

+ 10 - 1
src/modules/conversation-chat/DialogInput.vue

@@ -4,7 +4,7 @@
     <div class="dialog-input-area-container">
       <slot name="top"></slot>
 
-      <div class="textarea-container">
+      <div class="textarea-container" v-if="enable_text_input">
         <a-textarea
           ref="chat_input_textarea"
           class="chat-textarea-input"
@@ -68,6 +68,15 @@ const props = defineProps({
     required: false
   },
 
+  /**
+   * 是否支持文本输入
+   */
+  enable_text_input: {
+    type: Boolean,
+    default: true,
+    required: false
+  },
+
   /**
    * 是否开启文件上传功能
    * 默认 true,即默认开启

+ 5 - 1
src/modules/conversation-content/DialogContent.vue

@@ -4,7 +4,7 @@
       <a-spin></a-spin>
     </div>
 
-    <div v-if="!is_loading" v-html="content" />
+    <div v-if="!is_loading" v-html="content" class="answer-content-text" />
 
     <slot></slot>
   </div>
@@ -66,4 +66,8 @@ const custom_style = computed(() => {
 .dialog-chat-answer-content code {
   overflow-x: auto;
 }
+
+.answer-content-text {
+  line-height: 20px;
+}
 </style>

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

@@ -1,4 +1,27 @@
 import { formatStaticAssetsUrl } from '../../utils/utils';
+import { kuky_Authorization } from '../../base/storage';
+
+/**
+ * 在一个URL后拼接键值参数
+ * @param {string} url - 一个URL字符串
+ * @param {string} key - 参数键
+ * @param {string} value - 参数值
+ */
+function useAttachQueryValue(url, key, value) {
+  let real_url = url;
+
+  const url_arr = real_url.split('?');
+  const query_str = url_arr[1];
+  if (query_str) {
+    // 原有URL存在其他query参数
+    real_url = real_url + '&' + `${key}=${value}`;
+  } else {
+    // 原有URL不存在其他query参数
+    real_url = real_url + '?' + `${key}=${value}`;
+  }
+
+  return real_url;
+}
 
 /**
  * 格式化文档引用的数据
@@ -86,6 +109,9 @@ export function formatFileDownloadStr(file_name, file_url, file_id) {
   real_url = file_url.replace('./', '/');
   real_url = formatStaticAssetsUrl(real_url);
 
+  const token = kuky_Authorization.get();
+  real_url = useAttachQueryValue(real_url, 'token', token);
+
   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">

+ 1 - 12
src/modules/conversation-dialog/use-websocket-chat.js

@@ -15,21 +15,10 @@ function getWSUrl(menu_id, agent_id, chat_id) {
   const ws_server = getConfigField('WEBSOCKET_BASE_URL'); // websocket连接地址
 
   if (menu_id === 1) {
-    return `${ws_server}/api/document/ws/excel`;
+    return `${ws_server}/api/document/ws/excel?token=${token}`;
   } else {
-    // return `${host}/api/${type}/ws/${agent_id}/${chat_id}?token=${token}`;
     return `${ws_server}/api/chat/ws/${agent_id}/${chat_id}?token=${token}`;
   }
-
-  // if (type === 'report') {
-  //   return `ws://${host}/api/${type}/ws/${agent_id}/${chat_id}?token=${token}`;
-  // } else if (type === 'chat') {
-  //   return `ws://${host}/api/${type}/ws/${agent_id}/${chat_id}?token=${token}`;
-  // } else if (type === 'excel') {
-  //   return `ws://${host}/api/document/ws/excel`;
-  // } else {
-  //   return `ws://${host}/api/chat/ws/${agent_id}/${chat_id}?token=${token}`;
-  // }
 }
 
 /**

+ 66 - 27
src/views/conversation/ConversationChatContainer.vue

@@ -1,13 +1,9 @@
 <template>
   <div class="conversation-chat-container">
     <div class="conversation-chat-main" ref="chat_scrren_container">
-      <DialogHeader
-        class="conversation-chat-header"
-        :agent_info="CHAT_AGENT_INFOMATION"
-        :style="{ height: header_height + 'px' }"
-      />
+      <DialogHeader class="conversation-chat-header" :agent_info="CHAT_AGENT_INFOMATION" :style="style_header" />
 
-      <div class="conversation-chat-content" :style="{ height: chat_height - 30 - 30 + 'px' }">
+      <div class="conversation-chat-content" :style="style_body">
         <div class="conversation-chat-main-container">
           <template v-if="show_welcome">
             <!-- 有会话ID 获取历史记录,显示加载中状态 -->
@@ -48,6 +44,7 @@
           class="conversation-chat-input"
           :style="input_style"
           :disabled="input_disabled"
+          :enable_text_input="enable_text_input"
           :enable_file_upload="enable_file_upload"
           :file_accept="file_accept"
           @sizeChange="handleInputSizeChange"
@@ -66,35 +63,26 @@
         </DialogInput>
       </div>
 
-      <DialogFooter class="conversation-chat-footer" :style="{ height: footer_height + 'px' }" />
+      <DialogFooter class="conversation-chat-footer" :style="style_footer" />
     </div>
   </div>
 </template>
 
 <script setup>
-import { ref, getCurrentInstance, onMounted, onUnmounted, computed, nextTick } from 'vue';
+import { ref, onMounted, onUnmounted, computed, nextTick } from 'vue';
 import { Message } from '@arco-design/web-vue';
 
-import { jsonParse, jsonStringify } from '../../utils/utils';
+import { jsonStringify } from '../../utils/utils';
 
-import DialogAsideLeft from '../../modules/conversation-chat/DialogAsideLeft.vue';
 import DialogHeader from '../../modules/conversation-chat/DialogHeader.vue';
 import DialogWelcome from '../../modules/conversation-chat/DialogWelcome.vue';
 import DialogList from '../../modules/conversation-chat/DialogList.vue';
 import DialogInput from '../../modules/conversation-chat/DialogInput.vue';
 import DialogInputTop from '../../modules/conversation-chat/DialogInputTop.vue';
 import DialogFooter from '../../modules/conversation-chat/DialogFooter.vue';
-import DialogAsideRight from '../../modules/conversation-chat/DialogAsideRight.vue';
 
 import useWebSocketChat from '../../modules/conversation-dialog/use-websocket-chat';
-import {
-  getHistoryLogs,
-  getDialogChatId,
-  uploadFiles,
-  uploadCombineExcelFiles,
-  uploadFileByAgentInfo
-} from '../../modules/conversation-dialog/api-dialog';
-import { files2Formdata } from '../../modules/file-preview/files-2-formdata';
+import { getHistoryLogs, getDialogChatId, uploadFileByAgentInfo } from '../../modules/conversation-dialog/api-dialog';
 
 import formatDialogSendOptions from '../../modules/conversation-dialog/format-dialog-send-options';
 
@@ -106,7 +94,6 @@ import formatDialogAnswerForException from '../../modules/conversation-dialog/fo
 import formatDialogAnswerFromWebsocketReceiveMessage from '../../modules/conversation-dialog/format-dialog-answer-from-websocket_receive_message';
 
 import useEleSizeV1 from '../../utils/use-ele-size-v1';
-import useEleSizeV2 from '../../utils/use-ele-size-v2';
 import useInputClear from './use-input-clear';
 import useInputGetOptions from './use-input-get-options';
 import useScroll2Bottom from './use-scroll-bottom';
@@ -171,6 +158,16 @@ const input_style = computed(() => {
   };
 });
 
+const style_header = computed(() => {
+  return { height: header_height + 'px' };
+});
+const style_body = computed(() => {
+  return { height: chat_height - 30 - 30 + 'px' };
+});
+const style_footer = computed(() => {
+  return { height: footer_height + 'px' };
+});
+
 // ------------------------------------------------------------------
 // ------------------------------------------------------------------
 // ------------------------------------------------------------------
@@ -240,7 +237,7 @@ const current_menu_id = computed(() => {
 const show_welcome = ref(true);
 
 /**
- * 表单区域:是否显示附参数表单
+ * 表单区域:是否显示附参数表单
  * 文档报告场景下需要显示此组件
  */
 const show_input_others_opts = computed(() => {
@@ -257,8 +254,47 @@ const show_input_others_opts = computed(() => {
   return false;
 });
 
+/**
+ * 是否支持文本输入
+ * 返回 true,输入区域将不存在文本输入框
+ * 返回 false,输入区域将可以进行文本输入
+ */
+const enable_text_input = computed(() => {
+  const menu_id = current_menu_id.value;
+
+  /**
+   * 1 报表合并:上传几个文档,进行合并  允许 .xlsx
+   * 无需输入
+   */
+  if (menu_id === 1) {
+    return false;
+  }
+
+  return true;
+});
+
+/**
+ * 默认的文本值
+ */
+const default_text_value = computed(() => {
+  const menu_id = current_menu_id.value;
+
+  /**
+   * 某些情况下,无需输入文本
+   * 但是在对话部分,需要展示用户的提问,此时可以给一个默认的文本值
+   * 例如在报表合并情况下,仅需要上传文件,不需要输入文字
+   */
+  if (menu_id === 1) {
+    return '合并Excel';
+  }
+
+  return '';
+});
+
 /**
  * 表单区域:是否允许文件上传
+ * 返回 ture,输入区域将会有文件上传按钮
+ * 返回 false,输入区域将没有文件上传按钮
  */
 const enable_file_upload = computed(() => {
   const menu_id = current_menu_id.value;
@@ -277,7 +313,7 @@ const enable_file_upload = computed(() => {
   return false;
 });
 /**
- * 表单区域:是否允许文件上传的类型
+ * 表单区域:文件上传允许文件类型
  * 对应表单参数的 accept
  */
 const file_accept = computed(() => {
@@ -290,7 +326,6 @@ const file_accept = computed(() => {
    * 6 小数绘图:上传图片,描述图片的内容 允许 .png/jpg/jpeg
    * 9 文档报告: 允许 .docx
    */
-
   if (menu_id === 1) {
     return '.xlsx';
   }
@@ -394,13 +429,17 @@ const handleInputSizeChange = (size) => {
  * 4. 接收 socket 返回的数据项
  */
 const handleInputSubmit = async (options) => {
-  const ask_text = options.text; // 文本
+  let ask_text = options.text; // 文本
   const ask_files = options.files; // 文件列表
 
   // TODO: 内容检查,如果文本内容不合法,则不允许发送
-  if (!ask_text) {
-    handleErrorMessage('请输入文字');
-    return;
+  if (enable_text_input.value) {
+    if (!ask_text) {
+      handleErrorMessage('请输入文字');
+      return;
+    }
+  } else {
+    ask_text = default_text_value.value;
   }
 
   // --------------------------------------------