From d7ae67486dc0793fe0596140ca6f13a1b48f848c Mon Sep 17 00:00:00 2001
From: wujingjing <gersonwu@qq.com>
Date: 星期一, 06 一月 2025 16:37:45 +0800
Subject: [PATCH] Merge branch 'test' of http://47.103.154.90:83/r/WI/Web.V1.0 into test

---
 src/stores/chatRoom.ts |   73 ++++++++++++++++++++----------------
 1 files changed, 41 insertions(+), 32 deletions(-)

diff --git a/src/stores/chatRoom.ts b/src/stores/chatRoom.ts
index fb0fd98..21b2af3 100644
--- a/src/stores/chatRoom.ts
+++ b/src/stores/chatRoom.ts
@@ -6,6 +6,7 @@
 import emitter from '../utils/mitt';
 import { gotoRoute } from '../utils/route';
 import { Local } from '../utils/storage';
+
 /**
  * Room 鍏宠仈鐨勪竴浜涢厤缃�
  */
@@ -90,8 +91,8 @@
 };
 const getSelectListSample = async (res1, res2) => {
 	try {
-		const samples = res1?.samples ?? [];
-		const templateSamples = (res2?.templates ?? []).map((item) => ({
+		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,
@@ -117,10 +118,10 @@
  * 鑾峰彇鍏ㄥ眬鎵�鏈夋暟鎹�
  */
 export const getAllData = async () => {
-	Promise.all([getSectionList(), getSelectSample({}), getUserTemplateList()])
+	Promise.allSettled([getSectionList(), getSelectSample({}), getUserTemplateList()])
 		.then((res) => {
 			let [sectionList, selectSample, userTemplateList] = res;
-			sceneGroupList.value = sectionList?.groups ?? [];
+			sceneGroupList.value = sectionList?.value?.groups ?? [];
 			getSelectListSample(selectSample, userTemplateList);
 		})
 		.catch((err) => {});
@@ -196,36 +197,44 @@
 	},
 };
 
+let getHistoryChatRoomsPromise: Promise<any>;
 //鍘嗗彶瀵硅瘽
-const getHistoryChatRooms = () => {
-	return new Promise((resolve, reject) => {
-		GetHistoryGroups()
-			.then((res) => {
-				const resData = (res?.groups || []) as any[];
-				chatRoomList.value = resData
-					.toSorted((a, b) => b.create_time.localeCompare(a.create_time))
-					.map((item) => ({
-						id: item.group_id,
-						title: item.group_title,
-						createTime: item.create_time,
-						isInitial: Number(item.chat_count) === 0,
-					}));
-
-				if (!chatRoomList.value || chatRoomList.value.length === 0) {
-					newChatRoomClick();
-				} else {
-					const toClickRoom = activeChatRoom.value ?? chatRoomList.value[0];
-					activeRoomId.value = toClickRoom.id;
-					gotoAnswerPage(toClickRoom);
-				}
+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);
 			})
-			.then(() => {
-				resolve(true);
-			})
-			.catch((error) => {
-				reject(error);
+			.map((item) => {
+				return {
+					id: item.group_id,
+					title: item.group_title,
+					createTime: item.create_time,
+					isInitial: Number(item.chat_count) === 0,
+				};
 			});
-	}).catch((error) => {
-		reject(error);
+
+		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