From a12818479aac56a0c08206ce4dcf4ede092e9376 Mon Sep 17 00:00:00 2001 From: yangyin <1850366751@qq.com> Date: 星期四, 14 十一月 2024 16:20:52 +0800 Subject: [PATCH] 判断是否是新老用户 --- src/stores/chatRoom.ts | 181 +++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 174 insertions(+), 7 deletions(-) diff --git a/src/stores/chatRoom.ts b/src/stores/chatRoom.ts index 1036447..75fb5c8 100644 --- a/src/stores/chatRoom.ts +++ b/src/stores/chatRoom.ts @@ -1,13 +1,180 @@ -import { computed } from 'vue'; -import type { ChatRoomItem } from '../layout/component/sidebar/waterLeftAside/types'; -import { Local } from '../utils/storage'; +import { computed, ref } from 'vue'; +import { CreateHistoryGroup, getSectionList, getSelectSample, getUserTemplateList } from '../api/ai/chat'; +import type { ChatRoomItem } from '../layout/component/sidebar/components/types'; +import { router } from '../router'; +import { gotoRoute } from '../utils/route'; +/** + * Room 鍏宠仈鐨勪竴浜涢厤缃� + */ +export type RoomConfig = { + /** 鏄惁鐩存帴璋冪敤澶фā鍨嬶紙閫氫箟鍗冮棶锛夊洖绛� */ + isAnswerByLLM: boolean; + /** @description 浠庨椤佃繘鍘昏幏鍙栫殑绗竴涓洖澶嶏紝鍥炶皟鍑芥暟 */ + firstResCb: any; + /** @description 褰撳墠鑱婂ぉ瀹ょ殑 group_type */ + activeGroupType: string; +}; -export const chatRoomList = computed<ChatRoomItem[]>({ +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 topGroupId = ref(null); + +export const activeLLMId = ref(null); + +/** @description 褰撳墠鑱婂ぉ瀹� groupType */ +export const activeGroupType = computed({ get: () => { - return Local.get('chatRoomList') ?? []; + const result = getRoomConfig(activeRoomId.value, 'activeGroupType') ?? '涓氬姟鍦烘櫙'; + return result; }, set: (value) => { - console.log("馃殌 ~ value:", value) - Local.set('chatRoomList', value); + setRoomConfig(activeRoomId.value, 'activeGroupType', value); }, }); + +/** + * 鍏ㄥ眬浣跨敤鐨� ref + */ +export const sectionAList = ref([]); +export const isShowLogin = ref(false); +export const isLoginStatus = ref(false); + +//#region ====================== 鍏ㄥ眬浣跨敤鏁版嵁 ====================== +// group 鍒楄〃 +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 getSceneGroupList = async () => { + const res = await getSectionList(); + sceneGroupList.value = res?.groups ?? []; +}; +const getSelectListSample = async () => { + const res1 = getSelectSample({}); + const res2 = getUserTemplateList(); + const [sampleListPromise, templateListPromise] = await Promise.allSettled([res1, res2]); + const samples = (sampleListPromise as any).value?.samples ?? []; + const templateSamples = ((templateListPromise as any).value?.templates ?? []).map((item) => ({ + group_id: item.template_group, + sample_id: item.template_id, + sample_title: item.template_title, + sample_question: item.template_value, + + //#region ====================== template 鐗规湁瀛楁 ====================== + template_create_time: item.create_time, + template_type: item.template_type, + isTemplate: true, + //#endregion + })); + exampleSceneList.value = samples + .concat(templateSamples) + .map((item) => ({ ...item, Icon: '/static/images/wave/ChatImg.png', BgColor: randomHexColor() })); +}; +//闅忔満鐢熸垚棰滆壊 +const randomHexColor = () => { + return `#${Math.floor(Math.random() * 16777215) + .toString(16) + .padEnd(6, '0')}`; +}; +/** + * 鑾峰彇鍏ㄥ眬鎵�鏈夋暟鎹� + */ +export const getAllData = async () => { + getSceneGroupList(); + getSelectListSample(); +}; + +//#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, + }, + }); + } +}; +// 鏄惁宸茬粡灞曠ず寮曞 +export const hadShowFirstGuide = ref(false); +//鏄惁鏄柊鑰佺敤鎴� +export const isNewOldUser = ref(null); -- Gitblit v1.9.3