From d43a9b7b743bc27b2a8740e97f55a1f352ac00c0 Mon Sep 17 00:00:00 2001
From: wujingjing <gersonwu@qq.com>
Date: 星期五, 03 一月 2025 10:53:21 +0800
Subject: [PATCH] updateInputValue bug

---
 src/stores/chatRoom.ts |  239 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 233 insertions(+), 6 deletions(-)

diff --git a/src/stores/chatRoom.ts b/src/stores/chatRoom.ts
index 27666f1..21b2af3 100644
--- a/src/stores/chatRoom.ts
+++ b/src/stores/chatRoom.ts
@@ -1,13 +1,240 @@
-import { computed, ref, watch } from 'vue';
-import type { ChatRoomItem } from '../layout/component/sidebar/waterLeftAside/types';
+import { reject } from 'lodash-es';
+import { computed, ref } from 'vue';
+import { CreateHistoryGroup, GetHistoryGroups, getSectionList, getSelectSample, getUserTemplateList } from '../api/ai/chat';
+import type { ChatRoomItem } from '../layout/component/sidebar/components/types';
+import { router } from '../router';
+import emitter from '../utils/mitt';
+import { gotoRoute } from '../utils/route';
 import { Local } from '../utils/storage';
 
+/**
+ * Room 鍏宠仈鐨勪竴浜涢厤缃�
+ */
+export type RoomConfig = {
+	/** 鏄惁鐩存帴璋冪敤澶фā鍨嬶紙閫氫箟鍗冮棶锛夊洖绛� */
+	isAnswerByLLM: boolean;
+	/** @description 浠庨椤佃繘鍘昏幏鍙栫殑绗竴涓洖澶嶏紝鍥炶皟鍑芥暟 */
+	firstResCb: any;
+	/** @description 褰撳墠鑱婂ぉ瀹ょ殑 group_type */
+	activeGroupType: string;
+};
+
+export type RoomConfigKey = keyof RoomConfig;
+export const roomConfig = ref<Record<string, RoomConfig>>(null);
+
+export const setRoomConfig = <T extends RoomConfigKey>(roomId: string, key: T, value: RoomConfig[T]) => {
+	if (!roomId) return;
+	if (!roomConfig.value) {
+		roomConfig.value = {};
+	}
+	if (!roomConfig.value[roomId]) {
+		roomConfig.value[roomId] = {
+			[key]: value,
+		} as any;
+	} else {
+		roomConfig.value[roomId][key] = value;
+	}
+};
+
+export const getRoomConfig = <T extends RoomConfigKey>(roomId: string, key: T) => {
+	if (!roomId) return;
+	if (!roomConfig.value) {
+		return null;
+	}
+	if (!roomConfig.value[roomId]) {
+		return null;
+	} else {
+		return roomConfig.value[roomId][key];
+	}
+};
+
 export const chatRoomList = ref<ChatRoomItem[]>([]);
-
-
 
 export const activeRoomId = ref(null);
 export const activeChatRoom = computed(() => chatRoomList.value?.find((item) => item.id === activeRoomId.value));
 export const activeSampleId = ref(null);
-export const activeSectionAId= ref(null);
-export const activeLLMId= ref(null);
\ No newline at end of file
+export const activeSectionAId = ref(null);
+export const topGroupId = ref(null);
+
+export const activeLLMId = ref(null);
+
+/** @description 褰撳墠鑱婂ぉ瀹� groupType */
+export const activeGroupType = computed({
+	get: () => {
+		const result = getRoomConfig(activeRoomId.value, 'activeGroupType') ?? '涓氬姟鍦烘櫙';
+		return result;
+	},
+	set: (value) => {
+		setRoomConfig(activeRoomId.value, 'activeGroupType', value);
+	},
+});
+
+/**
+ * 鍏ㄥ眬浣跨敤鐨� ref
+ */
+export const sectionAList = ref([]);
+export const isShowLogin = ref(false);
+export const isLoginStatus = ref(false);
+
+//#region ====================== 鍏ㄥ眬浣跨敤鏁版嵁 ======================
+// 涓诲満鏅� 鍒楄〃
+export const sceneGroupList = ref([]);
+// groupType 鍒楄〃
+export const groupTypeList = computed(() => Array.from(new Set(sceneGroupList.value.map((item) => item.group_type))));
+// 鍔炲叕/妯℃澘 鍒楄〃
+export const exampleSceneList = ref([]);
+export const officeList = ref([]);
+export const groupTypeMapIcon = {
+	鍔炲叕鍔╂墜: 'ywicon-bangong',
+	鐭ヨ瘑搴�: 'ywicon-changyonggongjuzhishisuoyin',
+	涓氬姟鍦烘櫙: 'ywicon-yewu',
+};
+const getSelectListSample = async (res1, res2) => {
+	try {
+		const samples = res1?.value?.samples ?? [];
+		const templateSamples = (res2?.value?.templates ?? []).map((item) => ({
+			group_id: item.template_group,
+			sample_id: item.template_id,
+			sample_title: item.template_title,
+			sample_question: item.template_value,
+			template_create_time: item.create_time,
+			template_type: item.template_type,
+			isTemplate: true,
+		}));
+		exampleSceneList.value = samples
+			.concat(templateSamples)
+			.map((item) => ({ ...item, Icon: '/static/images/wave/ChatImg.png', BgColor: randomHexColor() }));
+	} catch (error) {
+		console.error('鑾峰彇閫夋嫨鍒楄〃鏍锋湰鏃跺嚭閿�:', error);
+	}
+};
+//闅忔満鐢熸垚棰滆壊
+const randomHexColor = () => {
+	return `#${Math.floor(Math.random() * 16777215)
+		.toString(16)
+		.padEnd(6, '0')}`;
+};
+/**
+ * 鑾峰彇鍏ㄥ眬鎵�鏈夋暟鎹�
+ */
+export const getAllData = async () => {
+	Promise.allSettled([getSectionList(), getSelectSample({}), getUserTemplateList()])
+		.then((res) => {
+			let [sectionList, selectSample, userTemplateList] = res;
+			sceneGroupList.value = sectionList?.value?.groups ?? [];
+			getSelectListSample(selectSample, userTemplateList);
+		})
+		.catch((err) => {});
+	getHistoryChatRooms();
+};
+
+//#endregion
+/** @description 鑱婂ぉ瀹ゅ睍绀烘ā寮� */
+export type ChatMode = 'share' | 'default';
+
+/** @description 鑱婂ぉ瀹ゅ睍绀烘ā寮� */
+// export const chatDisplayMode = ref<ChatMode>('default');
+
+export const SHARE_PAGE_NAME = 'ShareAnswer';
+export const isSharePage = computed(() => {
+	const isShare = router.currentRoute.value.name === SHARE_PAGE_NAME;
+	return isShare;
+});
+
+export const newChatRoomClick = async () => {
+	const res = await CreateHistoryGroup({
+		group_title: '鏂板缓瀵硅瘽寮�濮�',
+	});
+
+	const newRoom = {
+		id: res.history_group_id,
+		isInitial: true,
+		title: '鏂板缓瀵硅瘽寮�濮�',
+	};
+	if (!chatRoomList.value) {
+		chatRoomList.value = [newRoom];
+	} else {
+		chatRoomList.value.unshift(newRoom);
+	}
+	activeRoomId.value = newRoom.id;
+
+	gotoAnswerPage(newRoom);
+};
+export const gotoAnswerPage = (room: ChatRoomItem) => {
+	if (room.isInitial) {
+		gotoRoute({
+			name: 'Home',
+			query: {
+				id: room.id,
+			},
+		});
+	} else {
+		gotoRoute({
+			name: 'AskAnswer',
+			query: {
+				id: room.id,
+			},
+		});
+	}
+	setTimeout(() => {
+		emitter.emit('isShowHomePage', room.isInitial);
+	}, 300);
+};
+
+// 鐢ㄦ埛淇℃伅
+export const userInfo = {
+	get: () => {
+		return Local.get('userInfo');
+	},
+	set: (val) => {
+		return Local.set('userInfo', val);
+	},
+	clear: () => {
+		Local.remove('userInfo');
+	},
+	get isNew() {
+		return !this.get()?.web_login;
+	},
+};
+
+let getHistoryChatRoomsPromise: Promise<any>;
+//鍘嗗彶瀵硅瘽
+const getHistoryChatRooms = async () => {
+	getHistoryChatRoomsPromise = new Promise(async (resolve, reject) => {
+		if (isSharePage.value) return resolve(null);
+		const res = await GetHistoryGroups();
+		const resData = (res?.groups || []) as any[];
+		// 鎸夋渶鏅氭椂闂村埌鏈�鏃╂椂闂�
+		chatRoomList.value = resData
+			?.toSorted((a, b) => {
+				return b.create_time.localeCompare(a.create_time);
+			})
+			.map((item) => {
+				return {
+					id: item.group_id,
+					title: item.group_title,
+					createTime: item.create_time,
+					isInitial: Number(item.chat_count) === 0,
+				};
+			});
+
+		resolve(chatRoomList.value);
+	});
+};
+
+const roomClick = (room: ChatRoomItem) => {
+	activeRoomId.value = room.id;
+
+	gotoAnswerPage(room);
+};
+
+export const selectFirstRoom = () => {
+	getHistoryChatRoomsPromise.then(() => {
+		if (!chatRoomList.value || chatRoomList.value.length === 0) {
+			newChatRoomClick();
+		} else {
+			const toClickRoom = activeChatRoom.value ?? chatRoomList.value[0];
+			roomClick(toClickRoom);
+		}
+	});
+};

--
Gitblit v1.9.3