From 0e1d9c99e8a7c266225d7d9e132637771579b204 Mon Sep 17 00:00:00 2001
From: wujingjing <gersonwu@qq.com>
Date: 星期三, 09 十月 2024 14:10:03 +0800
Subject: [PATCH] isTalking && index === computedMessageList.length - 1和 maxHeight

---
 src/components/chat/Chat.vue |   63 +++++++++++++++++++------------
 1 files changed, 38 insertions(+), 25 deletions(-)

diff --git a/src/components/chat/Chat.vue b/src/components/chat/Chat.vue
index 7991371..0b727ce 100644
--- a/src/components/chat/Chat.vue
+++ b/src/components/chat/Chat.vue
@@ -1,5 +1,5 @@
 <template>
-	<div class="flex h-full">
+	<div class="flex h-full px-5">
 		<div class="flex flex-col h-full flex-auto">
 			<div class="h-full flex flex-col items-center overflow-y-auto">
 				<div ref="chatListDom" class="h-full" :style="{ width: chatWidth }">
@@ -17,7 +17,7 @@
 							srcset=""
 						/>
 						<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="inline-flex flex-col w-full" :class="{ 'w-full': item.role === RoleEnum.assistant }">
 								<div class="w-full" v-if="item.content?.values">
 									<div
 										class="text-sm rounded-[6px] p-4 leading-relaxed"
@@ -76,7 +76,7 @@
 												@click="copyClick(item)"
 											/>
 										</div>
-										<template v-if="item.content.errCode !== ErrorCode.Message">
+										<!-- <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 }"
@@ -91,9 +91,9 @@
 													@click="unLikeClick(item)"
 												/>
 											</div>
-										</template>
+										</template> -->
 
-										<div class="flex items-center justify-center size-[15px] relative">
+										<!-- <div class="flex items-center justify-center size-[15px] relative">
 											<i
 												class="p-2 ywifont ywicon-wentifankui cursor-pointer hover:text-[#0284ff] !text-[13px] hover:!text-[15px]"
 												@click="
@@ -115,11 +115,11 @@
 												:chatItem="currentFeedbackMapItem"
 												:position="feedbackPosition"
 											/>
-										</div>
+										</div> -->
 									</div>
 								</div>
 
-								<Loading v-if="isTalking && index === messageList.length - 1" class="w-fit" />
+								<Loading v-if="isTalking && index === computedMessageList.length - 1" class="w-fit my-auto" />
 							</div>
 						</div>
 					</div>
@@ -139,7 +139,7 @@
 				</div>
 			</div>
 
-			<div class="sticky bottom-0 w-full p-6 pb-8 bg-[rgb(247,248,250)] flex justify-center">
+			<div class="sticky bottom-0 w-full py-6 flex justify-center">
 				<PlayBar
 					v-model:voicePageIsShow="voicePageIsShow"
 					:isTalking="isTalking"
@@ -157,8 +157,8 @@
 
 <script setup lang="ts">
 import _ from 'lodash';
+import type { PropType } from 'vue';
 import { computed, ref } from 'vue';
-import FeedbackPanel from './components/FeedbackPanel.vue';
 import Loading from './components/Loading/Loading.vue';
 import { useAssistantContentOpt } from './hooks/useAssistantContentOpt';
 import { useScrollToBottom } from './hooks/useScrollToBottom';
@@ -167,13 +167,13 @@
 import { GetHistoryAnswer, extCallQuery } from '/@/api/ai/chat';
 import PlayBar from '/@/components/chat/components/playBar/PlayBar.vue';
 import { ErrorCode } from '/@/utils/request';
-import { checkSupervisorValidate } from '/@/api/supervisorAdmin';
+import { CancelTokenSource } from 'axios';
 
-const emit = defineEmits<{
-	(event: 'question',inputText): any;
-}>();
+const props = defineProps({
+	questionApi: Function as PropType<(text: string, sourceObj: { source: CancelTokenSource }) => any>,
+});
 
-const chatWidth = '75%';
+const chatWidth = '100%';
 const voicePageIsShow = ref(false);
 let isTalking = ref(false);
 let messageContent = ref<ChatContent>({
@@ -193,7 +193,6 @@
 		type: AnswerType.Text,
 		values: '瑙f瀽澶辫触锛�',
 	};
-
 	switch (res.answer_type) {
 		case AnswerType.RecordSet:
 			content = {
@@ -248,14 +247,13 @@
 };
 
 let questionRes = null;
-const questionAi = async (text) => {
-	const params = {
-		id: 'net3_summary',
-		question: text,
-	} as any;
+// 浣滀负鍙傛暟浼犺繘鍘伙紝鎼哄甫鍙傛暟鍑烘潵
+let lastSourceObj: { source: CancelTokenSource } = {
+	source:null
+};
 
-	// const res = await emit('question',text);
-	const res = await checkSupervisorValidate(params);
+const questionAi = async (text) => {
+	const res = await props.questionApi(text, lastSourceObj);
 	questionRes = res?.values;
 	const content = parseContent(res?.values);
 	return content;
@@ -272,11 +270,9 @@
 		history_id: historyId,
 	});
 };
-
 const sendChatMessage = async (content: ChatContent = messageContent.value, cb?: any, isCallExtParams?: any) => {
 	if (!content?.values || isTalking.value) return;
 	const isNewChat = messageList.value.length === 0;
-
 	let resMsgContent: ChatContent = null;
 
 	try {
@@ -312,7 +308,7 @@
 	}
 };
 
-const sendClick = (cb) => {
+const sendClick = (cb?) => {
 	sendChatMessage(messageContent.value, cb);
 };
 const appendLastMessageContent = (content: ChatContent) => {
@@ -326,6 +322,23 @@
 	displayMessageList: computedMessageList,
 });
 
+const autoSend = (text) => {
+	messageContent.value.values = text;
+	sendClick();
+};
+
+const clearContent = () => {
+	lastSourceObj.source?.cancel();
+	messageList.value = [];
+	// 娓呯┖杈撳叆妗�
+	clearMessageContent();
+};
+
+defineExpose({
+	autoSend,
+	clear: clearContent,
+});
+
 //#region ====================== 鍏宠仈鏌ヨ ======================
 // const relativeQueryClick = async (val) => {
 // 	sendChatMessage(

--
Gitblit v1.9.3