From 457cc6cf166d3b6c22be4f78c1db8802a7fbb4c7 Mon Sep 17 00:00:00 2001
From: wujingjing <gersonwu@qq.com>
Date: 星期一, 07 四月 2025 17:53:19 +0800
Subject: [PATCH] DigitalHuman

---
 src/components/chat/smallChat/index.vue |   64 ++++++++++++++++++++++++-------
 1 files changed, 49 insertions(+), 15 deletions(-)

diff --git a/src/components/chat/smallChat/index.vue b/src/components/chat/smallChat/index.vue
index 5f85f39..d7dbd39 100644
--- a/src/components/chat/smallChat/index.vue
+++ b/src/components/chat/smallChat/index.vue
@@ -8,7 +8,7 @@
 				class="small-chat-header h-12 flex items-center justify-between px-4"
 				style="border-bottom: 1px solid #e0e0e0"
 			>
-				<div class="text-lg font-bold py-2">WI姘村姟鏅鸿兘鍔╂墜</div>
+				<div class="text-lg font-bold py-2">WI姘村姟鏅鸿兘骞冲彴</div>
 				<div class="flex items-center gap-2">
 					<!-- <el-icon class="cursor-pointer text-gray-400 hover:text-gray-600">
 					<Refresh />
@@ -39,7 +39,7 @@
 					<!-- 娆㈣繋璇� -->
 					<!-- <div class="flex flex-col items-center gap-1.5 mt-8">
 						<div class="text-lg">浣犲ソ, 鎴戞槸</div>
-						<div class="text-lg text-blue-500">WI姘村姟鏅鸿兘鍔╂墜</div>
+						<div class="text-lg text-blue-500">WI姘村姟鏅鸿兘骞冲彴</div>
 						<span class="text-lg">浣犲彲浠ヨ緭鍏ヤ互涓嬮棶棰橈紝杩涜鍦板浘鎿嶄綔</span>
 					</div> -->
 					<!-- 蹇嵎闂 -->
@@ -134,7 +134,14 @@
 
 			<!-- 搴曢儴杈撳叆妗� -->
 			<div class="p-2 border-t">
-				<ChatInput v-model="inputText" @sendClick="sendClick" @toggleHistory="toggleHistory" :showHistory="showHistory" />
+				<ChatInput
+					:isTalking="lastIsLoading"
+					v-model="inputText"
+					@sendClick="sendClick"
+					@toggleHistory="toggleHistory"
+					@stopGenClick="stopGenClick"
+					:showHistory="showHistory"
+				/>
 			</div>
 		</div>
 		<Teleport to="body">
@@ -144,21 +151,23 @@
 </template>
 
 <script setup lang="ts" name="smallChat">
+import type { CancelTokenSource } from 'axios';
+import axios from 'axios';
 import { cloneDeep, defaults } from 'lodash-es';
+import { fromLonLat } from 'ol/proj';
 import { computed, nextTick, onMounted, ref } from 'vue';
 import ChatInput from './ChatInput.vue';
 import type { ChatMessage } from './types';
 import { AssistantContent } from './types';
 import WorkOrderDlg from './WorkOrderDlg.vue';
 import { agentStreamByPost } from '/@/api/ai/chat';
+import { getSearchMapElement } from '/@/api/map';
 import { useDrag } from '/@/hooks/useDrag';
 import { Logger } from '/@/model/logger/Logger';
 import { GaoDeSourceType, gaoDeSourceTypeMap, type OLMap } from '/@/model/map/OLMap';
-import userPic from '/static/images/role/user-200x206.png';
-import { getSearchMapElement } from '/@/api/map';
-import { formatDate } from '/@/utils/formatTime';
 import { systemGlobalConfig } from '/@/stores/global';
-import { fromLonLat } from 'ol/proj';
+import { formatDate } from '/@/utils/formatTime';
+import userPic from '/static/images/role/user-200x206.png';
 const props = defineProps<{
 	olMap?: OLMap;
 }>();
@@ -199,12 +208,17 @@
 	{ title: '鍒涘缓宸ュ崟', question: '鏉剧澶ч亾DN800鏉惧矖鑱旈�氱洃娴嬭澶囨病鏈夋暟鎹紝鍒涘缓涓�涓澶囩淮淇伐鍗曪紝璇峰強鏃舵淳浜虹淮淇��' },
 ]);
 const chatContentRef = ref<HTMLDivElement>(null);
-
 const getLastAssistantMessage = () => {
 	const last = historyMessages.value[historyMessages.value.length - 1];
-	const result = last.role === 'assistant' ? last : null;
+	const result = last?.role === 'assistant' ? last : null;
 	return result as ChatMessage<AssistantContent>;
 };
+
+const lastIsLoading = computed(() => {
+	const last = getLastAssistantMessage();
+	const loading = last?.content?.isLoading ?? false;
+	return loading;
+});
 
 //#region ====================== 娣诲姞宸ュ崟 ======================
 const optDlgIsShow = ref(false);
@@ -247,13 +261,11 @@
 const handleSwitchLayer = (formData: { layerId: string; visible: boolean }) => {
 	props.olMap.setLayerVisible(formData.layerId, formData.visible);
 	refreshAssistantMessage({ value: `鎴愬姛`, isError: false });
-
 };
 
 const changeTheme = (formData: { themeId: string }) => {
 	props.olMap.setThemeById(formData.themeId);
 	refreshAssistantMessage({ value: `鎴愬姛`, isError: false });
-
 };
 
 const handleQueryObject = async (formData: { objectName: string }) => {
@@ -307,16 +319,20 @@
 	refreshAssistantMessage({ value: `鎴愬姛`, isError: false });
 };
 
-const handleSetBackgroundLayer = (formData: { backgroundLayerId: string }) => {
-	if (!formData.backgroundLayerId) return;
-	props.olMap.setSourceType(Number(formData.backgroundLayerId));
+const handleSetBackgroundLayer = (formData: { LayerId: string }) => {
+	if (!formData.LayerId) return;
+	props.olMap.setSourceType(formData.LayerId as GaoDeSourceType);
 	refreshAssistantMessage({ value: `鎴愬姛`, isError: false });
 };
+let lastAxiosSource: CancelTokenSource = null;
 
 const startStream = (question: string) => {
 	if (lastIsInit) {
 		showHistory.value = false;
 	}
+
+	const currentSource = axios.CancelToken.source();
+	lastAxiosSource = currentSource;
 	// if (question === '鏉剧澶ч亾DN800鏉惧矖鑱旈�氱洃娴嬭澶囨病鏈夋暟鎹紝鍒涘缓涓�涓澶囩淮淇伐鍗曪紝璇峰強鏃舵淳浜虹淮淇��') {
 	// 	setTimeout(() => {
 	// 		openOptDlg();
@@ -337,7 +353,7 @@
 
 			if (
 				chunkRes.type === 'string' &&
-				['create_work_order', 'switch_layers', 'switch_topic', 'query_address', 'query_object'].includes(chunkRes.mode)
+				['create_work_order', 'switch_layers', 'switch_topic', 'query_address', 'query_object', 'map'].includes(chunkRes.mode)
 			) {
 				const jsonData = JSON.parse(chunkRes.value);
 
@@ -371,6 +387,10 @@
 						haveMapOperate = true;
 						handleQueryObject(jsonData);
 						break;
+					case 'map':
+						haveMapOperate = true;
+						handleMapCommand(jsonData);
+						break;
 				}
 			}
 
@@ -379,6 +399,9 @@
 					refreshAssistantMessage({ reason: `鏈瘑鍒埌鎿嶄綔锛�"${question}"` });
 				}
 			}
+		},
+		{
+			cancelToken: currentSource.token,
 		}
 	).catch((error) => {
 		Logger.error('agent stream error锛歕n\n' + error);
@@ -515,6 +538,17 @@
 	});
 };
 //#endregion
+
+//#region ====================== 娴佸仠姝� ======================
+const stopGenClick = () => {
+	lastAxiosSource?.cancel();
+	const last = getLastAssistantMessage();
+	if (!last) return;
+	last.content.isLoading = false;
+	last.content.isError = true;
+	last.content.reason = '鐢ㄦ埛鍋滄鎿嶄綔';
+};
+//#endregion
 onMounted(() => {});
 </script>
 

--
Gitblit v1.9.3