mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-14 21:02:49 +00:00
feat: 优化共同群聊计数缓存
This commit is contained in:
parent
b62c580d5e
commit
22b3598704
@ -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,
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
1
resources/assets/js/store/actions.js
vendored
1
resources/assets/js/store/actions.js
vendored
@ -1140,6 +1140,7 @@ export default {
|
||||
json: [
|
||||
'userInfo',
|
||||
'taskRelatedCache',
|
||||
'dialogCommonCountCache',
|
||||
]
|
||||
};
|
||||
|
||||
|
||||
30
resources/assets/js/store/mutations.js
vendored
30
resources/assets/js/store/mutations.js
vendored
@ -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] = {
|
||||
|
||||
1
resources/assets/js/store/state.js
vendored
1
resources/assets/js/store/state.js
vendored
@ -147,6 +147,7 @@ export default {
|
||||
dialogDroupWordChain: {},
|
||||
dialogGroupVote: {},
|
||||
dialogModalShow: false,
|
||||
dialogCommonCountCache: {},
|
||||
|
||||
// 搜索关键词(主要用于移动端判断滑动返回)
|
||||
messengerSearchKey: {dialog: '', contacts: ''},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user