From e3eb002222350bc4d9a26e74b5c66a187d6e04a9 Mon Sep 17 00:00:00 2001 From: LOUSANPANG <1271255653@qq.com> Date: Wed, 14 May 2025 15:15:23 +0800 Subject: [PATCH] =?UTF-8?q?fix:(useChatStore)=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=90=8C=E4=B8=80=E5=9F=9F=E5=90=8D=E4=B8=8B=E7=9A=84=E5=A4=9A?= =?UTF-8?q?=E4=B8=AA=20iframe=20=E5=85=B1=E4=BA=AB=E7=9B=B8=E5=90=8C?= =?UTF-8?q?=E7=9A=84=20sessionStorage=20=E5=92=8C=20localStorage=EF=BC=8C?= =?UTF-8?q?=E8=BF=99=E5=8F=AF=E8=83=BD=E5=AF=BC=E8=87=B4=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E6=B7=B7=E4=B9=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/web/core/chat/context/useChatStore.ts | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/projects/app/src/web/core/chat/context/useChatStore.ts b/projects/app/src/web/core/chat/context/useChatStore.ts index 5cd0f49934ab..deb5823140ac 100644 --- a/projects/app/src/web/core/chat/context/useChatStore.ts +++ b/projects/app/src/web/core/chat/context/useChatStore.ts @@ -23,13 +23,25 @@ type State = { const createCustomStorage = () => { const sessionKeys = ['source', 'chatId', 'appId']; + // 从 URL 中获取 appId 作为存储键的一部分 + const getStorageKey = (name: string) => { + let appId = ''; + if (typeof window !== 'undefined') { + const urlParams = new URLSearchParams(window.location.search); + appId = urlParams.get('appId') || ''; + } + return appId ? `${name}_${appId}` : name; + }; + return { getItem: (name: string) => { - const sessionData = JSON.parse(sessionStorage.getItem(name) || '{}'); - const localData = JSON.parse(localStorage.getItem(name) || '{}'); + const storageKey = getStorageKey(name); + const sessionData = JSON.parse(sessionStorage.getItem(storageKey) || '{}'); + const localData = JSON.parse(localStorage.getItem(storageKey) || '{}'); return JSON.stringify({ ...localData, ...sessionData }); }, setItem: (name: string, value: string) => { + const storageKey = getStorageKey(name); const data = JSON.parse(value); // 分离 session 和 local 数据 @@ -42,15 +54,16 @@ const createCustomStorage = () => { // 分别存储 if (Object.keys(sessionData).length > 0) { - sessionStorage.setItem(name, JSON.stringify({ state: sessionData, version: 0 })); + sessionStorage.setItem(storageKey, JSON.stringify({ state: sessionData, version: 0 })); } if (Object.keys(localData).length > 0) { - localStorage.setItem(name, JSON.stringify({ state: localData, version: 0 })); + localStorage.setItem(storageKey, JSON.stringify({ state: localData, version: 0 })); } }, removeItem: (name: string) => { - sessionStorage.removeItem(name); - localStorage.removeItem(name); + const storageKey = getStorageKey(name); + sessionStorage.removeItem(storageKey); + localStorage.removeItem(storageKey); } }; };