| | |
| | | <div class="h-full flex flex-col items-center overflow-y-auto"> |
| | | <div ref="chatListDom" class="h-full" :style="{ width: chatWidth }"> |
| | | <div |
| | | class="group flex px-4 py-6 hover:bg-slate-100 rounded-lg" |
| | | class="group flex px-4 py-6 hover:bg-slate-100 rounded-lg relative" |
| | | :class="{ 'flex-row-reverse': item.role === RoleEnum.user }" |
| | | v-for="(item, index) of computedMessageList" |
| | | :key="index" |
| | |
| | | /> |
| | | <div class="flex-auto flex" :class="{ 'justify-end': item.role === RoleEnum.user }"> |
| | | <div class="inline-flex flex-col" :class="{ 'w-full': item.role === RoleEnum.assistant }"> |
| | | <div class="relative w-full" v-if="item.content?.values"> |
| | | <div class="w-full" v-if="item.content?.values"> |
| | | <div |
| | | class="text-sm rounded-[6px] p-4 leading-relaxed" |
| | | :style="{ backgroundColor: item.role === RoleEnum.user ? 'rgb(197 224 255)' : 'white' }" |
| | | > |
| | | <div v-if="item.content.errCode === ErrorCode.Message" class="text-red-500 w-full">{{ item.content.msg }}</div> |
| | | <component v-else :is="answerTypeMapCom[item.content.type]" :data="item.content.values" :originData="item"/> |
| | | <component v-else :is="answerTypeMapCom[item.content.type]" :data="item.content.values" :originData="item" /> |
| | | </div> |
| | | |
| | | <div v-if="item.role === RoleEnum.assistant" class="absolute flex items-center right-0 mr-2 mt-2 space-x-2"> |
| | | <div v-if="item.role === RoleEnum.assistant" class="absolute flex items-center right-0 mr-4 mt-2 space-x-2"> |
| | | <div |
| | | class="flex items-center justify-center size-[15px]" |
| | | v-if="item.content?.type === AnswerType.Text || item.content?.type === AnswerType.Knowledge" |
| | | > |
| | | <i class="p-2 ywicon icon-copy cursor-pointer hover:text-[#0284ff] hover:!text-[18px]" @click="copyClick(item)" /> |
| | | </div> |
| | | <div class="flex items-center justify-center size-[15px]"> |
| | | <template v-if="item.content.errCode !== ErrorCode.Message"> |
| | | <div class="flex items-center justify-center size-[15px]"> |
| | | <i |
| | | :class="{ 'text-[#0284ff]': item.state === AnswerState.Like }" |
| | | class="p-2 ywicon icon-dianzan cursor-pointer hover:text-[#0284ff] font-medium hover:!text-[18px]" |
| | | @click="likeClick(item)" |
| | | /> |
| | | </div> |
| | | <div class="flex items-center justify-center size-[15px]"> |
| | | <i |
| | | :class="{ 'text-[#0284ff]': item.state === AnswerState.Unlike }" |
| | | class="p-2 ywicon icon-buzan cursor-pointer hover:text-[#0284ff] !text-[13px] hover:!text-[15px]" |
| | | @click="unLikeClick(item)" |
| | | /> |
| | | </div> |
| | | </template> |
| | | |
| | | <div class="flex items-center justify-center size-[15px] relative"> |
| | | <i |
| | | :class="{ 'text-[#0284ff]': item.state === AnswerState.Like }" |
| | | class="p-2 ywicon icon-dianzan cursor-pointer hover:text-[#0284ff] font-medium hover:!text-[18px]" |
| | | @click="likeClick(item)" |
| | | class="p-2 ywicon icon-wentifankui cursor-pointer hover:text-[#0284ff] !text-[13px] hover:!text-[15px]" |
| | | @click=" |
| | | ($event) => |
| | | feedbackClick( |
| | | $event, |
| | | item, |
| | | computedMessageList |
| | | .filter((v) => v.role === RoleEnum.assistant) |
| | | .findIndex((v) => v.historyId === item.historyId) |
| | | ) |
| | | " |
| | | /> |
| | | </div> |
| | | <div class="flex items-center justify-center size-[15px]"> |
| | | <i |
| | | :class="{ 'text-[#0284ff]': item.state === AnswerState.Unlike }" |
| | | class="p-2 ywicon icon-buzan cursor-pointer hover:text-[#0284ff] !text-[13px] hover:!text-[15px]" |
| | | @click="unLikeClick(item)" |
| | | <FeedbackPanel |
| | | v-show="feedbackIsShow && currentFeedbackMapItem === item" |
| | | ref="feedbackPanelRef" |
| | | v-model:isShow="feedbackIsShow" |
| | | v-model:content="feedbackContent" |
| | | :chatItem="currentFeedbackMapItem" |
| | | :position="feedbackPosition" |
| | | /> |
| | | </div> |
| | | </div> |
| | |
| | | import { v4 as uuidv4 } from 'uuid'; |
| | | import _ from 'lodash'; |
| | | import { ErrorCode } from '/@/utils/request'; |
| | | import FeedbackPanel from './components/FeedbackPanel.vue'; |
| | | import { useClickOther } from '/@/hooks/useClickOther'; |
| | | |
| | | const chatWidth = '75%'; |
| | | |
| | |
| | | const chatListDom = ref<HTMLDivElement>(); |
| | | const messageList = ref<ChatMessage[]>([]); |
| | | const computedMessageList = computed(() => { |
| | | return messageList.value.filter((v) => v.role !== RoleEnum.system); |
| | | return messageList.value.filter((v) => v && v.role !== RoleEnum.system); |
| | | }); |
| | | |
| | | const showAskMore = computed(() => { |
| | |
| | | }); |
| | | |
| | | const parseContent = (res) => { |
| | | if (!res) return null; |
| | | let content: ChatContent = { |
| | | type: AnswerType.Text, |
| | | values: '解析失败!', |
| | |
| | | assistantItem.historyId = questionRes.history_id; |
| | | appendLastMessageContent(resMsgContent); |
| | | } catch (error: any) { |
| | | appendLastMessageContent({ |
| | | type: AnswerType.Text, |
| | | values: '发生错误!', |
| | | }); |
| | | // appendLastMessageContent({ |
| | | // type: AnswerType.Text, |
| | | // values: '发生错误!', |
| | | // }); |
| | | } finally { |
| | | isTalking.value = false; |
| | | } |
| | |
| | | |
| | | resList.map((item, index) => { |
| | | const insertIndex = index + 1 + i; |
| | | messageList.value.splice(insertIndex, 0, { |
| | | historyId: item.answer.history_id, |
| | | role: RoleEnum.assistant, |
| | | content: parseContent(item.answer), |
| | | state: item.answer_state, |
| | | }); |
| | | messageList.value.splice( |
| | | insertIndex, |
| | | 0, |
| | | item.answer === null |
| | | ? null |
| | | : { |
| | | historyId: item.answer?.history_id, |
| | | role: RoleEnum.assistant, |
| | | content: parseContent(item.answer), |
| | | state: item.answer_state, |
| | | } |
| | | ); |
| | | i++; |
| | | }); |
| | | |
| | |
| | | forbidScroll = false; |
| | | }); |
| | | }; |
| | | const feedbackPosition = ref({ |
| | | x: 0, |
| | | y: 0, |
| | | }); |
| | | |
| | | const feedbackIsShow = ref(false); |
| | | const feedbackContent = ref(''); |
| | | const feedbackPanelRef = ref<HTMLDivElement>(null); |
| | | const currentFeedbackMapItem = ref(null); |
| | | const curFeedbackIndex = ref(0); |
| | | const feedbackClick = async (e, item, index) => { |
| | | currentFeedbackMapItem.value = item; |
| | | curFeedbackIndex.value = index; |
| | | const offsetX = -4; |
| | | const offsetY = -8; |
| | | feedbackIsShow.value = true; |
| | | nextTick(() => { |
| | | feedbackPosition.value = { |
| | | x: -feedbackPanelRef.value[index].$el.clientWidth + offsetX, |
| | | y: -feedbackPanelRef.value[index].$el.clientHeight + offsetY, |
| | | }; |
| | | }); |
| | | }; |
| | | useClickOther( |
| | | computed(() => feedbackPanelRef.value[curFeedbackIndex.value]), |
| | | feedbackIsShow, |
| | | () => { |
| | | feedbackIsShow.value = false; |
| | | feedbackContent.value = ''; |
| | | } |
| | | ); |
| | | //#endregion |
| | | </script> |
| | | |