From c508ab04b00fd52430d34fcdd869d321af26993d Mon Sep 17 00:00:00 2001 From: xsx <825657193@qq.com> Date: Fri, 6 Jun 2025 00:11:45 +0800 Subject: [PATCH] =?UTF-8?q?H5=E5=92=8C=E5=B0=8F=E7=A8=8B=E5=BA=8F=E6=AF=8F?= =?UTF-8?q?=E4=B8=AA=E4=BC=9A=E8=AF=9D=E5=8F=AA=E4=BF=9D=E7=95=991000?= =?UTF-8?q?=E6=9D=A1=E6=B6=88=E6=81=AF=EF=BC=8C=E9=98=B2=E6=AD=A2storage?= =?UTF-8?q?=E6=BA=A2=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- im-uniapp/store/chatStore.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/im-uniapp/store/chatStore.js b/im-uniapp/store/chatStore.js index 13ac0aa..9a88579 100644 --- a/im-uniapp/store/chatStore.js +++ b/im-uniapp/store/chatStore.js @@ -1,7 +1,6 @@ import { defineStore } from 'pinia'; import { MESSAGE_TYPE, MESSAGE_STATUS } from '@/common/enums.js'; import useUserStore from './userStore'; -import UNI_APP from '../.env'; let cacheChats = []; export default defineStore('chatStore', { @@ -20,11 +19,6 @@ export default defineStore('chatStore', { this.chats = []; for (let chat of chatsData.chats) { chat.stored = false; - // 清理多余的消息,避免消息过多导致卡顿 - if (UNI_APP.MAX_MESSAGE_SIZE > 0 && chat.messages.length > UNI_APP.MAX_MESSAGE_SIZE) { - let idx = chat.messages.length - UNI_APP.MAX_MESSAGE_SIZE; - chat.messages = chat.messages.slice(idx); - } // 暂存至缓冲区 cacheChats.push(JSON.parse(JSON.stringify(chat))); // 加载期间显示只前15个会话做做样子,一切都为了加快初始化时间 @@ -346,6 +340,18 @@ export default defineStore('chatStore', { if (!cacheChats) return; // 排序 cacheChats.sort((chat1, chat2) => chat2.lastSendTime - chat1.lastSendTime); + // #ifndef APP-PLUS + /** + * 由于h5和小程序的stroge只有5m,大约只能存储2w条消息, + * 所以这里每个会话只保留1000条消息,防止溢出 + */ + cacheChats.forEach(chat =>{ + if(chat.messages.length > 1000){ + let idx = chat.messages.length - 1000; + chat.messages = chat.messages.slice(idx); + } + }) + // #endif // 记录热数据索引位置 cacheChats.forEach(chat => chat.hotMinIdx = chat.messages.length); // 将消息一次性装载回来