Przeglądaj źródła

feat: 碳源投加修改, 解决文件上传以及showVal取值问题

sunxiao 7 miesięcy temu
rodzic
commit
bf51657d6a

+ 8 - 21
src/components/Chat/ChatAgentInput.vue

@@ -47,7 +47,6 @@ const agentOptions = computed(() => helperList.value.filter(({ tools }) => tools
 const lastFileListIndex = computed(() => uploadFileList.value.length == 0 ? 0 : uploadFileList.value.length - 1);
 
 const focusInput = _ => isFocusState.value = true;
-
 const blurInput = _ => isFocusState.value = false;
 
 watch(inpVal, (curVal) => {
@@ -91,7 +90,7 @@ const commonEmitEvent = (eventName) => {
     return message.warning('文件上传中,请稍后');
   }
 
-  emit(eventName, { question: val, selectedOption: selectedOption.value || {}, uploadFileList: uploadFileList.value });
+  emit(eventName, { showVal: val,  question: val, selectedOption: selectedOption.value || {}, uploadFileList: uploadFileList.value });
 
   inpVal.value = '';
   uploadFileList.value = [];
@@ -201,7 +200,7 @@ const selectOption = (index) => {
 
 const beforeUpload = ({ file }) => {
   if (( file.file?.size / ( 1024 * 2 ) ) > 5) {
-    message.warning("只能上传.doc.txt格式的文件, 请重新上传");
+    message.warning("只能上传.doc、.docx、.txt格式的文件, 请重新上传");
     return false;
   }
 
@@ -214,8 +213,6 @@ const beforeUpload = ({ file }) => {
 
   uploadLoading.value = true
 
-  console.log( "开始上传", uploadFileList.value );
-
   return true;
 }
 
@@ -224,7 +221,6 @@ const handleUploadChange = ({ file }) => {
 
   if (file.status === 'uploading') {
     uploadFileList.value[lastFileListIndex.value].percentage = file.percentage;
-    console.log( "上传中", uploadFileList.value );
   }
 
 }
@@ -244,15 +240,6 @@ const handleFinish = ({ file, event }) => {
         ...uploadFileList.value[lastFileListIndex.value],
         url: res.data,
       }
-
-      console.log( "上传完成", uploadFileList.value );
-
-      // uploadFileList.value.push({
-      //   name: name.substring(0, name.lastIndexOf('.')),
-      //   url: res.data,
-      //   size: (file.file.size / 1024).toFixed(2) + "KB",
-      //   suffix: name.substring( name.lastIndexOf('.') + 1 ).toUpperCase()
-      // })
     }
 
   } catch (error) {
@@ -271,12 +258,11 @@ const onRemoveFile = (i) => {
   uploadFileList.value.splice(i, 1);
 }
 
-onMounted(async () => {
-  const url = import.meta.env.VITE_BASE_URL;
-const prefix = import.meta.env.VITE_BASE_PREFIX;
-const baseURL = url + prefix;
+const clearFileList = () => {
+  uploadFileList.value = [];
+}
 
-console.log( "baseURL", baseURL );
+onMounted(async () => {
   const { data } = await helperApi.getHelperList();
   
   const result = getFormatYesterDay(data)
@@ -292,6 +278,7 @@ onUnmounted(() => {
 })
 
 defineExpose({
+  clearFileList,
   clearInpVal,
   handleInpFocus,
   inpVal,
@@ -351,7 +338,7 @@ defineExpose({
             <div class="inp-wrapper flex-1" @click="handleInpFocus">
               <div class="upload-inner">
                 <NUpload
-                  accept=".doc,.txt"
+                  accept=".doc, .docx, .txt"
                   :disabled="uploadLoading"
                   :show-file-list="false"
                   :action="baseURL + '/qiniuyun/upLoadImage'"

+ 1 - 1
src/components/Layout/TheMenu.vue

@@ -74,7 +74,7 @@ const menuOptions = [
     key: '/control',
     children: [
       {
-        label: '智能投药',
+        label: '智适应碳源投加',
         icon: renderChildrenIcon({ name: 'menu-cost-drug' }),
         key: 'medicinal',
       },

+ 1 - 1
src/router/index.js

@@ -121,7 +121,7 @@ const constantRouterMap = [
         name: 'MedicinalView',
         component: () => import('@/views/control/MedicinalView.vue'),
         meta: {
-          title: '智能投药'
+          title: '智适应碳源投加'
         }
       },
     ]

+ 55 - 15
src/views/answer/AnswerView.vue

@@ -36,6 +36,8 @@ const isExistInHistory = computed(() => (recordList.value.findIndex(({ sessionId
 const handleCreateDialog = async () => {
   message.destroyAll();
 
+  inputRef.value.clearFileList();
+
   if (unref(isLoading)) {
     return message.warning('当前对话生成中');
   }
@@ -64,21 +66,53 @@ const handleChatDetail = async ({ sessionId }) => {
 
   const { data } = await chatApi.getAnswerHistoryDetail({ sessionId });
 
-  chatDataSource.value = data.map(item => ({ ...item, loading: false, }));
+  chatDataSource.value = data.map(item => {
+
+    const uploadFileList = []
+
+    if ( item.question.includes('file:') ) {
+      
+      const fileInfo = item.question.split("||");
+      const fileArr = fileInfo[0].split(":");
+      const file = fileArr[1];
+      const url = fileInfo[1];
+      const suffix = file.substring( file.lastIndexOf('.') + 1 ).toUpperCase();
+      const originSuffix = file.substring( file.lastIndexOf('.') );
+      const name = file.substring(0, file.lastIndexOf('.'))
+
+      uploadFileList.push({
+        name,
+        originSuffix,
+        suffix,
+        url
+      })
+    }
+
+    return ({ ...item, loading: false, uploadFileList})
+  });
+
   currenSessionId.value = sessionId;
 
   scrollToBottom();
 }
 
-const onRegenerate = async ({ question, realQuestion, tools }) => {
+const onRegenerate = async ({ showVal, question, realQuestion, tools, uploadFileList }) => {
   controller = new AbortController();
 
   const sessionId = unref(currenSessionId);
+
+  let fileQuestionStr = '';
+
+  if ( uploadFileList && uploadFileList.length ) {
+    const [ fileItem ] = uploadFileList;
+    fileQuestionStr = `file:${fileItem.name + fileItem.originSuffix}||${fileItem.url}||${question}`
+  }
+
   const params = {
     data: {
       sessionId,
-      showVal: question,
-      question: realQuestion || question,
+      showVal: showVal,
+      question: realQuestion || fileQuestionStr || question,
       module: 0,
       isStrong: Number(unref(switchActive)),
       tools,
@@ -95,10 +129,12 @@ const onRegenerate = async ({ question, realQuestion, tools }) => {
 
       updateChat({
         sessionId,
+        showVal: showVal,
         question,
         answer,
         loading: true,
-        delayLoading: false
+        delayLoading: false,
+        uploadFileList
       })
 
       scrollToBottomIfAtBottom();
@@ -112,11 +148,13 @@ const onRegenerate = async ({ question, realQuestion, tools }) => {
 
     updateChat({
       id,
+      showVal: showVal,
       sessionId,
       question,
       answer,
       loading: false,
-      delayLoading: false
+      delayLoading: false,
+      uploadFileList
     })
 
     scrollToBottomIfAtBottom();
@@ -130,7 +168,7 @@ const onRegenerate = async ({ question, realQuestion, tools }) => {
   }
 }
 // 提交问题
-const handleSubmit = async ({question, selectedOption, realQuestion = ''}) => {
+const handleSubmit = async ({ showVal, question, selectedOption, realQuestion = '', uploadFileList = []}) => {
   // 用于模拟 - 内容生成前置等待状态
   if (unref(isExistInHistory)) {
     const { data: sessionId } = await chatApi.getChatSessionTag();
@@ -141,21 +179,23 @@ const handleSubmit = async ({question, selectedOption, realQuestion = ''}) => {
 
   addChat({
     sessionId: unref(currenSessionId),
+    showVal,
     question,
     realQuestion,
     answer: '',
     loading: true,
-    delayLoading: true
+    delayLoading: true,
+    uploadFileList
   })
 
   scrollToBottom();
 
-  setTimeout(() => onRegenerate({ question, realQuestion, tools: selectedOption?.tools || null }), 2 * 1000);
+  setTimeout(() => onRegenerate({ showVal, question, realQuestion, tools: selectedOption?.tools || null, uploadFileList }), 2 * 1000);
 }
 
 // 处理推荐问题
 const handleWelcomeRecommend = ({ question, realQuestion }) => {
-  handleSubmit({question, realQuestion});
+  handleSubmit({showVal: question, question, realQuestion});
 }
 
 // 删除历史对话
@@ -173,8 +213,10 @@ const onStopChatStream  = async ({ sessionId }) => {
 }
 
 // 重新生成问题
-const onChatResetStream = ({ question }) => {
-  handleSubmit({question});
+const onChatResetStream = (item) => {
+  const { question, uploadFileList, showVal } = item;
+  console.log(item);
+  handleSubmit({showVal, question, uploadFileList});
 }
 
 onMounted(() => {
@@ -215,7 +257,7 @@ onUnmounted(() => {
 
       <div class="conversation-item" v-if="chatDataSource.length">
         <template v-for="item, index in chatDataSource" :key="item.id">
-          <ChatAsk :content="item.question" :sessionId="item.sessionId"></ChatAsk>
+          <ChatAsk :content="item.showVal" :sessionId="item.sessionId" :uploadFileList="item.uploadFileList"></ChatAsk>
           <ChatAnswer
             :id="item.id"
             :content="item.answer"
@@ -241,8 +283,6 @@ onUnmounted(() => {
           @on-click="handleSubmit"
           @on-enter="handleSubmit"
         ></ChatAgentInput>
-        <!-- <ChatInput ref="inputRef" v-model:loading="isLoading" v-model:switch="switchActive" @on-click="handleSubmit"
-          @on-enter="handleSubmit"></ChatInput> -->
       </template>
     </TheChatView>
   </section>

+ 11 - 4
src/views/control/MedicinalView.vue

@@ -53,14 +53,14 @@ const paramData = ref({
 // 基础系数 - input输入
 const factorData = ref({
   hfksd: 12.00,   // 后反馈设置定
-  jzxs: 3.00,     // 基准系数
+  jzxs: 3.10,     // 基准系数
   xzxs: 1.00,     // 修正系数
   kzxs: 5.20,     // 控制系数
   sffpxs: 1.00,   // 水量分配系数
   tydl: 0.90,     // 碳源当量
-  zhxs: 0.90,     // 转换系数
+  zhxs: 0.50,     // 转换系数
   xsbs: 1.00,     // 稀释倍数
-  yjmd: 1.00,     // 药剂密度
+  yjmd: 1.10,     // 药剂密度
   zxqdll: 0.02,   // 最小启动流量
   tdb: 3.54       // 碳氮比
 })
@@ -175,6 +175,13 @@ const onEditCancel = () => {
   factorInpData.value = JSON.parse(JSON.stringify(factorData.value));
 }
 
+const onFinalResult = () => {
+  if ( !flowNum.value ) {
+    return message.warning('您还未完成投加计算,请完成后再试');
+  }
+  message.warning('您还未接入组态系统,请接入后再试');
+}
+
 onMounted(async () => {
   const { data } = await controlApi.getNumValue();
   let result = {};
@@ -328,7 +335,7 @@ onMounted(async () => {
             </n-scrollbar>
           </div>
           <div class="right-section">
-            <TheResultPanel :doseNum="doseNum" :flowNum="flowNum"></TheResultPanel>
+            <TheResultPanel :doseNum="doseNum" :flowNum="flowNum" @on-click="onFinalResult"></TheResultPanel>
             <TheEchartPanel></TheEchartPanel>
           </div>
         </div>

+ 11 - 3
src/views/control/components/TheResultPanel.vue

@@ -37,7 +37,7 @@ const emitEvent = () => emit('on-click');
           </li>
         </ul>
       </div>
-      <div class="round-btn" @click="emitEvent">
+      <div :class="['round-btn', { active: doseNum }]" @click="emitEvent">
         <div class="inner space-y-[4px]">
           <SvgIcon name="control-icon-result-btn" size="24" />
           <span>一键投放</span>
@@ -127,12 +127,20 @@ const emitEvent = () => emit('on-click');
       }
 
       &:hover {
-        background: #898EFE;
+        // background: #898EFE;
         .inner {
-          background: #2454FF;
+          // background: #2454FF;
         }
       }
     }
+
+    .active {
+      transition: all 0.5s;
+      background: #898EFE;
+      .inner {
+        background: #2454FF;
+      }
+    }
   }
 }
 </style>

+ 30 - 6
src/views/work/WorkView.vue

@@ -65,14 +65,35 @@ const handleChatDetail = async ({ sessionId }) => {
 
   const { data } = await chatApi.getAnswerHistoryDetail({ sessionId });
 
-  chatDataSource.value = data.map(item => ({ ...item, loading: false, }));
+  chatDataSource.value = data.map(item => {
+    const uploadFileList = []
+
+    if ( item.question.includes('file:') ) {
+      
+      const fileInfo = item.question.split("||");
+      const fileArr = fileInfo[0].split(":");
+      const file = fileArr[1];
+      const url = fileInfo[1];
+      const suffix = file.substring( file.lastIndexOf('.') + 1 ).toUpperCase();
+      const originSuffix = file.substring( file.lastIndexOf('.') );
+      const name = file.substring(0, file.lastIndexOf('.'))
+
+      uploadFileList.push({
+        name,
+        originSuffix,
+        suffix,
+        url
+      })
+    }
+    return ({ ...item, loading: false, uploadFileList})
+  });
 
   currenSessionId.value = sessionId;
 
   scrollToBottom();
 }
 
-const onRegenerate = async ({ question, tools, uploadFileList }) => {
+const onRegenerate = async ({ showVal, question, tools, uploadFileList }) => {
   controller = new AbortController();
 
   const sessionId = unref(currenSessionId);
@@ -86,7 +107,7 @@ const onRegenerate = async ({ question, tools, uploadFileList }) => {
   const params = {
     data: {
       sessionId,
-      showVal: question,                        // 展示问题
+      showVal,                        // 展示问题
       question: fileQuestionStr || question,    // 给大模型的问题
       module: 2,
       tools: activeItem.value.tools || tools,
@@ -100,6 +121,7 @@ const onRegenerate = async ({ question, tools, uploadFileList }) => {
 
       updateChat({
         sessionId,
+        showVal,   
         question,
         answer,
         uploadFileList,
@@ -119,6 +141,7 @@ const onRegenerate = async ({ question, tools, uploadFileList }) => {
     updateChat({
       id,
       sessionId,
+      showVal,
       question,
       answer,
       uploadFileList,
@@ -137,7 +160,7 @@ const onRegenerate = async ({ question, tools, uploadFileList }) => {
   }
 }
 // 提交问题
-const handleSubmit = async ({question, selectedOption, uploadFileList}) => {
+const handleSubmit = async ({showVal, question, selectedOption, uploadFileList = []}) => {
 
   if (unref(isExistInHistory)) {
     const { data: sessionId } = await chatApi.getChatSessionTag();
@@ -148,6 +171,7 @@ const handleSubmit = async ({question, selectedOption, uploadFileList}) => {
 
   addChat({
     sessionId: unref(currenSessionId),
+    showVal: showVal,
     question,
     answer: '',
     loading: true,
@@ -157,7 +181,7 @@ const handleSubmit = async ({question, selectedOption, uploadFileList}) => {
 
   scrollToBottom();
 
-  setTimeout(() => onRegenerate({ question, tools: selectedOption?.tools || null,  uploadFileList}), 2 * 1000);
+  setTimeout(() => onRegenerate({ showVal, question, tools: selectedOption?.tools || null,  uploadFileList}), 2 * 1000);
 }
 
 // 处理推荐问题
@@ -246,7 +270,7 @@ onUnmounted(() => {
 
       <div class="conversation-item" v-if="chatDataSource.length">
         <template v-for="item in chatDataSource" :key="item.id">
-          <ChatAsk :content="item.question" :sessionId="item.sessionId" :uploadFileList="item.uploadFileList"></ChatAsk>
+          <ChatAsk :content="item.showVal" :sessionId="item.sessionId" :uploadFileList="item.uploadFileList"></ChatAsk>
           <ChatAnswer :id="item.id" :content="item.answer" :loading="item.loading" :delay-loading="item.delayLoading"
             :isSatisfied="item.isSatisfied" @on-click-icon="params => updateById(params)"></ChatAnswer>
         </template>