From 5962e0b12d451bc9af2e30251e294145f54b1dd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=20=E5=85=83=E5=B1=B1?= Date: Thu, 20 Mar 2025 17:03:29 +0800 Subject: [PATCH] fix record --- src/hooks/useTalkRecord.js | 2 +- src/store/modules/dialogueList.js | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/hooks/useTalkRecord.js b/src/hooks/useTalkRecord.js index f9dcc76..9b92179 100644 --- a/src/hooks/useTalkRecord.js +++ b/src/hooks/useTalkRecord.js @@ -74,7 +74,7 @@ export const useTalkRecord = (uid) => { // 加载数据列表 const load = async (params) => { const request = { - limit: 30, + limit:10, ...params, talk_type: params.talk_type, receiver_id: params.receiver_id, diff --git a/src/store/modules/dialogueList.js b/src/store/modules/dialogueList.js index 2f57660..7c3f7e3 100644 --- a/src/store/modules/dialogueList.js +++ b/src/store/modules/dialogueList.js @@ -17,7 +17,7 @@ export const useDialogueListStore = createGlobalState(() => { } const addDialogueRecord = (newRecords, type = 'add') => { - console.log(newRecords) + console.log('newRecords',newRecords) const dialogue = lodash.cloneDeep(useDialogueStore()) if (!dialogue || typeof dialogue !== 'object') return @@ -45,6 +45,21 @@ export const useDialogueListStore = createGlobalState(() => { } } }) + + // 限制records数组长度为40条 + const maxRecords = 40 + if (dialogueList.value[existingIndex].records.length > maxRecords) { + const excessCount = dialogueList.value[existingIndex].records.length - maxRecords + // 如果是push添加,则从首部删除多余条目 + if (type === 'add') { + dialogueList.value[existingIndex].records.splice(0, excessCount) + } else { + // 如果是unshift添加,则从尾部删除多余条目 + dialogueList.value[existingIndex].records.splice(-excessCount) + } + } + + console.log('records',dialogueList.value[existingIndex].records) // 更新除 records 和 index_name 外的其他属性 const { index_name, records: _, ...updateProps } = dialogue