diff --git a/resources/assets/js/pages/manage/components/UserDetail.vue b/resources/assets/js/pages/manage/components/UserDetail.vue index c5652fde5..9ea46ceb2 100755 --- a/resources/assets/js/pages/manage/components/UserDetail.vue +++ b/resources/assets/js/pages/manage/components/UserDetail.vue @@ -107,6 +107,7 @@ export default { showModal: false, commonDialog: { + userid: null, total: null, list: [], page: 1, @@ -182,9 +183,39 @@ export default { loadCommonDialogCount() { const target_userid = this.userData.userid; - if (this.commonDialog.userid !== target_userid) { - this.commonDialog.total = null; + const previousUserId = this.commonDialog.userid; + if (!target_userid) { + this.commonDialog = { + ...this.commonDialog, + userid: target_userid || null, + total: null, + list: [], + page: 1, + has_more: false, + }; + return; } + + if (previousUserId !== target_userid) { + this.commonDialog = { + ...this.commonDialog, + userid: target_userid, + total: null, + list: [], + page: 1, + has_more: false, + }; + } + + const cacheMap = this.$store.state.dialogCommonCountCache || {}; + const cached = cacheMap[String(target_userid)]; + if (cached && typeof cached.total !== 'undefined') { + this.commonDialog = { + ...this.commonDialog, + total: cached.total, + }; + } + this.$store.dispatch('call', { url: 'dialog/common/list', data: { @@ -195,10 +226,19 @@ export default { if (target_userid !== this.userData.userid) { return } - this.commonDialog = Object.assign(data, { + const parsedTotal = Number(data.total); + const total = Number.isNaN(parsedTotal) ? 0 : parsedTotal; + this.commonDialog = { + ...this.commonDialog, userid: target_userid, + total, list: [], + page: 1, has_more: false, + }; + this.$store.commit('common/dialog/count/save', { + userid: target_userid, + total, }); }); }, diff --git a/resources/assets/js/store/actions.js b/resources/assets/js/store/actions.js index 895fd2f64..5d64def7d 100644 --- a/resources/assets/js/store/actions.js +++ b/resources/assets/js/store/actions.js @@ -1140,6 +1140,7 @@ export default { json: [ 'userInfo', 'taskRelatedCache', + 'dialogCommonCountCache', ] }; diff --git a/resources/assets/js/store/mutations.js b/resources/assets/js/store/mutations.js index 56a2100c5..a79e3d19a 100644 --- a/resources/assets/js/store/mutations.js +++ b/resources/assets/js/store/mutations.js @@ -30,6 +30,33 @@ export default { $A.IDBSave("cacheUserBasic", state.cacheUserBasic, 600) }, + // 共同群聊 + 'common/dialog/count/save': function(state, {userid, total, updatedAt = Date.now()}) { + if (!userid) { + return; + } + const key = String(userid); + const cache = Object.assign({}, state.dialogCommonCountCache); + const parsedTotal = Number(total); + cache[key] = { + total: Number.isNaN(parsedTotal) ? 0 : parsedTotal, + updated_at: updatedAt, + }; + state.dialogCommonCountCache = cache; + $A.IDBSave("dialogCommonCountCache", state.dialogCommonCountCache, 600); + }, + + 'common/dialog/count/clear': function(state, userid) { + if (typeof userid === 'number' || typeof userid === 'string') { + const cache = Object.assign({}, state.dialogCommonCountCache); + delete cache[String(userid)]; + state.dialogCommonCountCache = cache; + } else { + state.dialogCommonCountCache = {}; + } + $A.IDBSave("dialogCommonCountCache", state.dialogCommonCountCache, 600); + }, + // 消息管理 'message/push': function(state, data) { state.dialogMsgs.push(data) @@ -65,7 +92,7 @@ export default { $A.IDBSave("cacheTasks", state.cacheTasks, 600) }, - // taskContents + // 任务内容 'task/content/push': function(state, data) { state.taskContents.push(data) }, @@ -78,6 +105,7 @@ export default { } }, + // 任务关联 'task/related/save': function(state, {taskId, list, updatedAt = Date.now()}) { const cache = Object.assign({}, state.taskRelatedCache); cache[taskId] = { diff --git a/resources/assets/js/store/state.js b/resources/assets/js/store/state.js index 3be407977..7230de5d2 100644 --- a/resources/assets/js/store/state.js +++ b/resources/assets/js/store/state.js @@ -147,6 +147,7 @@ export default { dialogDroupWordChain: {}, dialogGroupVote: {}, dialogModalShow: false, + dialogCommonCountCache: {}, // 搜索关键词(主要用于移动端判断滑动返回) messengerSearchKey: {dialog: '', contacts: ''},