gerson
2024-12-15 fa6de28a6fe7e79891f3b0f74f2501e010e460b1
src/components/chat/Chat.vue
@@ -1,6 +1,6 @@
<template>
   <div class="flex h-full">
      <div class="flex flex-col h-full flex-auto">
      <div class="flex flex-col h-full flex-auto relative">
         <div ref="chatListDom" class="relative h-full flex flex-col items-center overflow-y-auto" style="height: calc(100% - 50px)">
            <span
               class="more-loading absolute text-blue-400 left-[50%] translate-x-[-50%] cursor-pointer w-10"
@@ -39,7 +39,9 @@
                                 :style="{ backgroundColor: item.role === RoleEnum.user ? 'rgb(197 224 255)' : 'white' }"
                                 :class="{ group: item.role === RoleEnum.user }"
                              >
                                 <!-- #region ====================== 意图分析 ======================-->
                                 <div class="flex flex-col" v-if="item?.stepList?.length > 0">
                                    <!-- #region ====================== 意图分析 ======================-->
                                    <div class="flex items-center">
                                       <span class="mr-2">意图分析:</span>
                                       <div
@@ -55,8 +57,9 @@
                                          ></span>
                                       </div>
                                    </div>
                                    <!-- #endregion -->
                                    <!-- 过程输出 -->
                                    <!-- #region ====================== 过程输出 ======================-->
                                    <el-steps v-show="item.stepIsShow" class="mt-3" direction="vertical" :active="activeStep">
                                       <el-step
                                          v-for="(subItem, index) in item.stepList"
@@ -77,8 +80,11 @@
                                          </template>
                                       </el-step>
                                    </el-steps>
                                    <!-- #endregion -->
                                 </div>
                                 <!-- #endregion -->
                                 <!-- #region ====================== 用户操作按钮 ======================-->
                                 <div
                                    v-if="item.role === RoleEnum.user && item.content?.values && !isSharePage && !isShareCheck"
                                    class="absolute flex items-center bottom-0 group invisible"
@@ -114,7 +120,10 @@
                                    </div>
                                 </div>
                                 <!-- #endregion -->
                                 <!-- #region ====================== 消息内容 ======================-->
                                 <template v-if="item.content?.values">
                                    <!-- #region ====================== 报错信息 ======================-->
                                    <div v-if="item.content.errCode === ErrorCode.Message" class="flex-column w-full">
                                       <p class="text-red-500">
                                          {{ item.content.errMsg }}
@@ -135,6 +144,8 @@
                                          </div>
                                       </div>
                                    </div>
                                    <!-- #endregion -->
                                    <!-- #region ====================== 回答组件 ======================-->
                                    <template v-else>
                                       <component
                                          :conclusion="item.conclusion"
@@ -160,9 +171,21 @@
                                          </div>
                                       </div>
                                    </template>
                                    <!-- #endregion -->
                                 </template>
                              </div>
                                 <!-- #endregion -->
                                 <!-- #region ====================== 附加内容 ======================-->
                                 <!-- #region ====================== 停止 ======================-->
                                 <span v-if="item.isStopMsg && item?.role === RoleEnum.assistant" class="text-gray-400 text-[12px]"
                                    >(已停止)</span
                                 >
                                 <!-- parseContent 返回为 null -->
                                 <p v-if="!item.content && !isTalking && !item.isStopMsg" class="text-red-500">暂无数据</p>
                                 <!-- #endregion -->
                                 <!-- #endregion -->
                              </div>
                              <!-- #region ====================== ai 消息操作 ======================-->
                              <div
                                 v-if="item.role === RoleEnum.assistant && item.content?.values && !isSharePage && !isShareCheck"
                                 class="absolute flex items-center right-0 mr-4 mt-2 space-x-2"
@@ -230,6 +253,7 @@
                                    </div>
                                 </el-tooltip>
                              </div>
                              <!-- #endregion -->
                           </div>
                        </div>
                     </div>
@@ -255,6 +279,11 @@
               </div>
            </div>
         </div>
         <div class="absolute right-28 bottom-40 " v-if="!isBottom">
            <div class="flex items-center justify-center size-[38px]  cursor-pointer hover:text-[#0284ff] border rounded-full hover:bg-[#f6f7f9] shadow bg-white" @click="scrollToBottom">
               <i class="ywifont ywicon-xiangxiajiantou !text-[20px]" />
            </div>
         </div>
         <div
            class="sticky bottom-0 w-full px-6 pt-12 pb-6 bg-[rgb(247,248,250)] flex justify-center"
@@ -276,28 +305,26 @@
         <div class="sticky bottom-0 w-full p-6 bg-[rgb(247,248,250)] flex justify-center" v-if="isShareCheck"></div>
      </div>
      <CustomDrawer v-model:isShow="drawerIsShow" @updateChatInput="updateChatInput" />
      <el-dialog title="分享链接" v-model="shareCodeIsShow" width="25%" modal-append-to-body lock-scroll :before-close="closeShareClick">
      <el-dialog title="分享链接" v-model="shareCodeIsShow" width="12%" modal-append-to-body lock-scroll :before-close="closeShareClick">
         <div class="w100 h100 flex justify-center items-center flex-col text-center">
            <div class="qrcode h100" ref="qrcodeRef"></div>
            <div class="h100 w100 flex flex-col justify-center items-center">
               <span class="h100 text-[#8d8e99] text-[12px] mt-2">{{ shareCoderUrl }}</span>
               <span class="text-[#1d86ff] text-[12px] cursor-pointer" @click="copyShareCodeClick">复制</span>
            </div>
         </div>
      </el-dialog>
   </div>
</template>
<script setup lang="ts">
import type { CancelTokenSource } from 'axios';
import axios from 'axios';
import { ElMessage } from 'element-plus';
import { findLast, orderBy } from 'lodash-es';
import moment from 'moment';
import QRCode from 'qrcodejs2-fixes';
import { computed, nextTick, onActivated, onMounted, ref } from 'vue';
import useClipboard from 'vue-clipboard3';
import { loadAmisSource } from '../amis/load';
import FeedbackPanel from './components/FeedbackPanel.vue';
import { useAssistantContentOpt } from './hooks/useAssistantContentOpt';
import { useQueryProcess } from './hooks/useQueryProcess';
import { convertProcessItem, useScrollLoad } from './hooks/useScrollLoad';
import { useScrollToBottom } from './hooks/useScrollToBottom';
import type { ChatContent, StepItem } from './model/types';
@@ -322,7 +349,6 @@
import emitter from '/@/utils/mitt';
import { ErrorCode } from '/@/utils/request';
import { toMyFixed } from '/@/utils/util';
import axios, { CancelTokenSource } from 'axios';
const chatWidth = '75%';
const voicePageIsShow = ref(false);
let isTalking = ref(false);
@@ -401,7 +427,6 @@
   content.origin = res;
   return content;
};
const { clearQueryProcess, process, processId, queryProcess } = useQueryProcess();
//#region ====================== 步骤 step ======================
const activeStep = ref(-1);
@@ -528,7 +553,6 @@
            if (chunkRes.mode === 'finish') {
               stepList.at(-1).ms = ms;
               isTalking.value = false;
               return;
            }
@@ -557,6 +581,8 @@
   });
   questionRes = await resultP;
   isTalking.value = false;
   const content = parseContent(res, true);
   return content;
};
@@ -576,8 +602,7 @@
   isTalking.value = false;
   chatListLoading.value = false;
   resetStep();
   computedMessageList.value.at(-1).stepIsShow = false;
   computedMessageList.value.at(-1).isStopMsg = true;
};
const sendChatMessage = async (content: ChatContent = messageContent.value, cb?: any, isCallExtParams?: any) => {
@@ -611,6 +636,7 @@
         state: AnswerState.Null,
         stepList: [],
         stepIsShow: true,
         isStopMsg: false,
         isChecked: false,
      } as any;
      // 发送当前
@@ -674,7 +700,7 @@
const chatListLoading = ref(true);
const { scrollToBottom, scrollToTop } = useScrollToBottom({
const { scrollToBottom, scrollToTop, isBottom } = useScrollToBottom({
   chatListDom: chatListDom,
});
@@ -717,6 +743,7 @@
         }, 300);
      }
   }
   loadAmisSource();
});
//#region ====================== 关联查询 ======================
const relativeQueryClick = async (val) => {
@@ -842,7 +869,7 @@
         colorLight: '#ffffff',
      });
   });
   // toClipboard(url);
   copyShareCodeClick();
};
//链接复制
const copyShareCodeClick = () => {
@@ -920,4 +947,8 @@
:deep(.el-step__description) {
   height: 20px;
}
:deep(.el-step:last-of-type .el-step__description) {
   display: none;
}
</style>