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