mirror of
https://github.com/kuaifan/dootask.git
synced 2026-03-17 19:23:26 +00:00
perf: 优化会话保留
This commit is contained in:
parent
a3725ca164
commit
4ef5deac69
@ -560,6 +560,7 @@ export default {
|
|||||||
|
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
this.$store.dispatch('forgetInDialog', this._uid)
|
this.$store.dispatch('forgetInDialog', this._uid)
|
||||||
|
this.$store.dispatch('closeDialog', this.dialogId)
|
||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
@ -788,7 +789,7 @@ export default {
|
|||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
dialogId: {
|
dialogId: {
|
||||||
handler(dialog_id) {
|
handler(dialog_id, old_id) {
|
||||||
if (dialog_id) {
|
if (dialog_id) {
|
||||||
this.msgNew = 0
|
this.msgNew = 0
|
||||||
this.msgType = ''
|
this.msgType = ''
|
||||||
@ -816,6 +817,7 @@ export default {
|
|||||||
this.inputFocus()
|
this.inputFocus()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.$store.dispatch('closeDialog', old_id)
|
||||||
},
|
},
|
||||||
immediate: true
|
immediate: true
|
||||||
},
|
},
|
||||||
@ -1718,7 +1720,7 @@ export default {
|
|||||||
|
|
||||||
handleBack() {
|
handleBack() {
|
||||||
const {name, params} = this.$store.state.routeHistoryLast;
|
const {name, params} = this.$store.state.routeHistoryLast;
|
||||||
if (name === this.$route.name && /\d+/.test(params.dialogId)) {
|
if (name === this.$route.name && /^\d+$/.test(params.dialogId)) {
|
||||||
this.goForward({name: this.$route.name});
|
this.goForward({name: this.$route.name});
|
||||||
} else {
|
} else {
|
||||||
this.goBack();
|
this.goBack();
|
||||||
|
|||||||
33
resources/assets/js/store/actions.js
vendored
33
resources/assets/js/store/actions.js
vendored
@ -2107,8 +2107,8 @@ export default {
|
|||||||
search_msg_id = dialog_id.search_msg_id;
|
search_msg_id = dialog_id.search_msg_id;
|
||||||
dialog_id = dialog_id.dialog_id;
|
dialog_id = dialog_id.dialog_id;
|
||||||
}
|
}
|
||||||
state.dialogSearchMsgId = /\d+/.test(search_msg_id) ? search_msg_id : 0;
|
state.dialogSearchMsgId = /^\d+$/.test(search_msg_id) ? search_msg_id : 0;
|
||||||
state.dialogId = /\d+/.test(dialog_id) ? dialog_id : 0;
|
state.dialogId = /^\d+$/.test(dialog_id) ? dialog_id : 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2174,9 +2174,9 @@ export default {
|
|||||||
} else {
|
} else {
|
||||||
state.dialogIns.push(data);
|
state.dialogIns.push(data);
|
||||||
}
|
}
|
||||||
// 会话消息总数量大于500时只保留最近打开的10个会话
|
// 会话消息总数量大于1000时只保留最近打开的20个会话
|
||||||
const msg_max = 500
|
const msg_max = 1000
|
||||||
const retain_num = 10
|
const retain_num = 20
|
||||||
state.dialogHistory = state.dialogHistory.filter(id => id != data.dialog_id)
|
state.dialogHistory = state.dialogHistory.filter(id => id != data.dialog_id)
|
||||||
state.dialogHistory.push(data.dialog_id)
|
state.dialogHistory.push(data.dialog_id)
|
||||||
if (state.dialogMsgs.length > msg_max && state.dialogHistory.length > retain_num) {
|
if (state.dialogMsgs.length > msg_max && state.dialogHistory.length > retain_num) {
|
||||||
@ -2212,6 +2212,29 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关闭对话
|
||||||
|
* @param state
|
||||||
|
* @param dispatch
|
||||||
|
* @param dialog_id
|
||||||
|
*/
|
||||||
|
closeDialog({state, dispatch}, dialog_id) {
|
||||||
|
$A.execMainDispatch("closeDialog", dialog_id)
|
||||||
|
//
|
||||||
|
if (!/^\d+$/.test(dialog_id)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 关闭会话后只保留会话最后50条数据
|
||||||
|
const retain = 5
|
||||||
|
const msgs = state.dialogMsgs.filter(item => item.dialog_id == dialog_id)
|
||||||
|
if (msgs.length > retain) {
|
||||||
|
const delIds = msgs.sort((a, b) => {
|
||||||
|
return b.id - a.id
|
||||||
|
}).splice(retain).map(item => item.id)
|
||||||
|
state.dialogMsgs = state.dialogMsgs.filter(item => !delIds.includes(item.id))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存待办数据
|
* 保存待办数据
|
||||||
* @param state
|
* @param state
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user