yangyin
2024-11-08 f41e52e3debf30558d556dc0451776f5422fb9b8
src/components/chat/Chat.vue
@@ -7,6 +7,7 @@
               v-loading="moreIsLoading"
            ></span>
            <div class="h-full relative" v-loading="chatListLoading" :style="{ width: chatWidth }">
               <template v-if="computedMessageList?.length > 0">
               <div
                  class="flex px-4 py-6 rounded-lg relative"
                  :class="{ 'flex-row-reverse': item.role === RoleEnum.user, 'px-10': isShareCheck }"
@@ -48,7 +49,10 @@
                                       <span>
                                          {{ toggleStepLabel(item) }}
                                       </span>
                                       <span class="ywifont" :class="{ 'ywicon-unfold': !item.stepIsShow, 'ywicon-fold': item.stepIsShow }"></span>
                                          <span
                                             class="ywifont"
                                             :class="{ 'ywicon-unfold': !item.stepIsShow, 'ywicon-fold': item.stepIsShow }"
                                          ></span>
                                    </div>
                                 </div>
@@ -67,7 +71,8 @@
                                       </template>
                                       <template #title>
                                          <span class="text-sm"
                                             >{{ subItem.title }}<span v-if="subItem.ms" class="text-green-600">{{ `(${subItem.ms})` }}</span></span
                                                >{{ subItem.title
                                                }}<span v-if="subItem.ms" class="text-green-600">{{ `(${subItem.ms})` }}</span></span
                                          >
                                       </template>
                                    </el-step>
@@ -75,10 +80,12 @@
                              </div>
                              <div
                                 v-if="item.role === RoleEnum.user && item.content?.values && chatDisplayMode === 'default' && !isShareCheck"
                                    v-if="item.role === RoleEnum.user && item.content?.values && !isSharePage && !isShareCheck"
                                 class="absolute flex items-center bottom-0 group invisible"
                              >
                                 <div class="bg-[#fff] flex items-center mr-4 space-x-2 flex-nowrap rounded-[6px] py-2 px-2 group-hover:visible">
                                    <div
                                       class="bg-[#fff] flex items-center mr-4 space-x-2 flex-nowrap rounded-[6px] py-2 px-2 group-hover:visible"
                                    >
                                    <el-tooltip effect="dark" content="复制" placement="top">
                                       <div class="flex items-center justify-center size-[20px]">
                                          <i
@@ -154,9 +161,9 @@
                                 </template>
                              </template>
                           </div>
                           <!-- 操作 -->
                           <div
                              v-if="item.role === RoleEnum.assistant && item.content?.values && chatDisplayMode === 'default' && !isShareCheck"
                                 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"
                           >
                              <div
@@ -227,6 +234,15 @@
                     </div>
                  </div>
               </div>
               </template>
               <el-empty v-else-if="isSharePage && !chatListLoading" :image-size="200"  >
                  <template #description>
                     <span class="text-[15px]">
                        分享的对话不存在或已失效
                     </span>
                  </template>
               </el-empty>
               <div v-if="showAskMore && !isShareCheck" class="ml-4 mt-5 text-sm pb-10">
                  <div class="text-gray-600 mb-5">你可以继续问我:</div>
                  <div class="space-y-2 inline-flex flex-col">
@@ -243,10 +259,7 @@
            </div>
         </div>
         <div
            class="sticky bottom-0 w-full p-6 bg-[rgb(247,248,250)] flex justify-center"
            v-if="chatDisplayMode === 'default' && !isShareCheck"
         >
         <div class="sticky bottom-0 w-full p-6 bg-[rgb(247,248,250)] flex justify-center" v-if="!isSharePage && !isShareCheck">
            <PlayBar
               v-model:voicePageIsShow="voicePageIsShow"
               :isTalking="isTalking"
@@ -281,6 +294,7 @@
import { extCallQuery, questionStreamByPost, shareChatHistoryByPost } from '/@/api/ai/chat';
import PlayBar from '/@/components/chat/components/playBar/PlayBar.vue';
import CustomDrawer from '/@/components/drawer/CustomDrawer.vue';
import { SERVE_URL } from '/@/constants';
import { Logger } from '/@/model/logger/Logger';
import router from '/@/router';
import {
@@ -290,8 +304,8 @@
   activeRoomId,
   activeSampleId,
   activeSectionAId,
   chatDisplayMode,
   getRoomConfig,
   isSharePage,
   roomConfig,
} from '/@/stores/chatRoom';
import { ErrorCode } from '/@/utils/request';
@@ -604,16 +618,18 @@
      messageList.value.at(-1).createTime = currentTime;
   }
};
const { loadRangeData, onChatListScroll, moreIsLoading, nextUserMsgEndIndex } = useScrollLoad({
   isSharePage: isSharePage,
   container: chatListDom,
   historyGroupId: currentRouteId,
   messageList,
   parseAnswerContent: parseContent,
});
const chatListLoading = ref(false);
const chatListLoading = ref(true);
const { scrollToBottom } = useScrollToBottom({
const { scrollToBottom, scrollToTop } = useScrollToBottom({
   chatListDom: chatListDom,
});
@@ -621,17 +637,24 @@
   messageList.value = [];
   // 加载初始数据
   chatListLoading.value = true;
   await loadRangeData().finally(() => {
      chatListLoading.value = false;
   });
   if (messageList.value.length === 0) {
      messageContent.value = {
         type: AnswerType.Text,
         values: activeChatRoom.value.title,
         values: activeChatRoom.value?.title,
      };
      sendChatMessage();
   } else {
      if (isSharePage.value) {
         setTimeout(() => {
            // 滚动到顶部
            scrollToTop();
         }, 300);
   } else {
      setTimeout(() => {
         // 初始状态滚一下
@@ -641,6 +664,7 @@
            chatListDom.value.addEventListener('scroll', onChatListScroll);
         }, 300);
      }, 300);
      }
   }
});
//#region ====================== 关联查询 ======================
@@ -782,8 +806,9 @@
   if (!res.values) return;
   const shareId = Object.values(res.values)[0];
   if (!shareId) return;
   return `${shareId}`;
   const relativeHref = router.resolve(`share?id=${shareId}`).href;
   const shareLink = `${SERVE_URL}${relativeHref}`;
   return shareLink;
};
//#endregion