From ff10a2373ed8fc6a95c380b2182e39329ecd6d6d Mon Sep 17 00:00:00 2001 From: xsx <825657193@qq.com> Date: Wed, 16 Jul 2025 17:20:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9=E5=8F=AA=E6=94=AF=E6=8C=81lo?= =?UTF-8?q?calStroage=E7=9A=84=E6=B5=8F=E8=A7=88=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- im-web/src/store/chatStore.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/im-web/src/store/chatStore.js b/im-web/src/store/chatStore.js index cda390f..d38267b 100644 --- a/im-web/src/store/chatStore.js +++ b/im-web/src/store/chatStore.js @@ -372,6 +372,16 @@ export default defineStore('chatStore', { }) // 排序 cacheChats.sort((chat1, chat2) => chat2.lastSendTime - chat1.lastSendTime); + /** + * 由于部分浏览器不支持websql或indexdb,只能使用localstorage,而localstorage大小只有10m,可能会导致缓存空间溢出 + * 解决办法:如果是使用localstorage的浏览器,每个会话只保留1000条消息,防止溢出 + */ + cacheChats.forEach(chat => { + if (localForage.driver().includes("localStorage") && chat.messages.length > 1000) { + let idx = chat.messages.length - 1000; + chat.messages = chat.messages.slice(idx); + } + }) // 记录热数据索引位置 cacheChats.forEach(chat => chat.hotMinIdx = chat.messages.length); // 将消息一次性装载回来