Browse Source

feat: 文档出卷 文件上传 调整为必填项目

zhupei 1 year ago
parent
commit
8c19de87d3

+ 4 - 1
public/i18n/lang-en.json

@@ -455,7 +455,10 @@
 
     "tag_all": "All",
 
-    "copy": "Copy"
+    "copy": "Copy",
+
+    "please_input_text": "Please enter text",
+    "please_upload_file": "Please upload the file"
   },
   "wendangchujuan": {
     "agent_title": "Document paper",

+ 4 - 1
public/i18n/lang-zh.json

@@ -453,7 +453,10 @@
 
     "tag_all": "全部",
 
-    "copy": "复制"
+    "copy": "复制",
+
+    "please_input_text": "请输入文字",
+    "please_upload_file": "请上传文件"
   },
   "wendangchujuan": {
     "agent_title": "文档出卷",

+ 57 - 4
src/views/conversation/ConversationChatContainer.vue

@@ -79,6 +79,7 @@
 
 <script setup>
 import { ref, onMounted, onUnmounted, computed, nextTick } from 'vue';
+import { useI18n } from 'vue-i18n';
 import { Message } from '@arco-design/web-vue';
 
 import { jsonStringify } from '../../utils/utils';
@@ -126,6 +127,8 @@ const props = defineProps({
   session_id: String
 });
 
+const i18n = useI18n();
+
 /**
  * input的一些操作方法
  */
@@ -287,6 +290,18 @@ const enable_text_input = computed(() => {
   return true;
 });
 
+/**
+ * 对话文本是否必须
+ */
+const is_chat_text_required = computed(() => {
+  const is_enable = enable_text_input.value;
+  if (!is_enable) {
+    return false;
+  }
+
+  return true;
+});
+
 /**
  * 默认的文本值
  */
@@ -324,6 +339,26 @@ const enable_file_upload = computed(() => {
     return true;
   }
 
+  // 文档出卷
+  if (menu_id === 7) {
+    return true;
+  }
+
+  return false;
+});
+
+/**
+ * 对话文件是否必须
+ */
+const is_chat_file_required = computed(() => {
+  const is_enable = enable_file_upload.value;
+  if (!is_enable) {
+    return false;
+  }
+
+  const menu_id = current_menu_id.value;
+
+  // 文档出卷:文件必须上传
   if (menu_id === 7) {
     return true;
   }
@@ -450,16 +485,34 @@ const handleInputSubmit = async (options) => {
   let ask_text = options.text; // 文本
   const ask_files = options.files; // 文件列表
 
-  // TODO: 内容检查,如果文本内容不合法,则不允许发送
-  if (enable_text_input.value) {
+  // 用户选定的文件数量
+  const file_total = ask_files.length;
+
+  const is_text_required = is_chat_text_required.value;
+  const is_file_required = is_chat_file_required.value;
+
+  // 检查对话文字是否必须
+  if (is_text_required) {
     if (!ask_text) {
-      handleErrorMessage('请输入文字');
+      const msg = i18n.t('conversation.please_input_text');
+
+      handleErrorMessage(msg);
       return;
     }
   } else {
     ask_text = default_text_value.value;
   }
 
+  // 检查对话文件是否必须
+  if (is_file_required) {
+    if (file_total === 0) {
+      const msg = i18n.t('conversation.please_upload_file');
+
+      handleErrorMessage(msg);
+      return;
+    }
+  }
+
   // --------------------------------------------
   // --------------------------------------------
   // --------------------------------------------
@@ -560,7 +613,7 @@ const handleInputSubmit = async (options) => {
   /**
    * 如果存在文件数据,则进行文件上传
    */
-  if (ask_files.length !== 0) {
+  if (file_total !== 0) {
     // 进行文件上传,获取文件信息
     const chat_id = chat_new_id.value;