mirror of
https://github.com/kuaifan/dootask.git
synced 2026-02-28 12:50:48 +00:00
perf: 优化缓存
This commit is contained in:
parent
0077925fc0
commit
3dc8269406
10
resources/assets/js/functions/common.js
vendored
10
resources/assets/js/functions/common.js
vendored
@ -1222,16 +1222,14 @@ const localforage = require("localforage");
|
||||
$.extend({
|
||||
__IDBTimer: {},
|
||||
|
||||
IDBSave(key, value, delay = 0) {
|
||||
IDBSave(key, value, delay = 100) {
|
||||
if (typeof this.__IDBTimer[key] !== "undefined") {
|
||||
clearTimeout(this.__IDBTimer[key])
|
||||
delete this.__IDBTimer[key]
|
||||
}
|
||||
if (delay > 0) {
|
||||
this.__IDBTimer[key] = setTimeout(_ => this.IDBSave(key, value, 0), delay)
|
||||
} else {
|
||||
localforage.setItem(key, value).then(_ => {})
|
||||
}
|
||||
this.__IDBTimer[key] = setTimeout(async _ => {
|
||||
await localforage.setItem(key, value)
|
||||
}, delay)
|
||||
},
|
||||
|
||||
IDBDel(key) {
|
||||
|
||||
@ -387,6 +387,10 @@ export default {
|
||||
return this.dialogMsgs.find(item => item.id === replyId)
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
cacheKey() {
|
||||
return this.dialogId || `t_${this.taskId}`
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
@ -400,7 +404,10 @@ export default {
|
||||
this.quill.setText('')
|
||||
}
|
||||
}
|
||||
this.setInputCache(val)
|
||||
this.$store.dispatch("saveDialogInputCache", {
|
||||
key: this.cacheKey,
|
||||
cache: val
|
||||
})
|
||||
},
|
||||
|
||||
// Watch disabled change
|
||||
@ -777,24 +784,10 @@ export default {
|
||||
},
|
||||
|
||||
getInputCache() {
|
||||
const key = this.dialogId || `t_${this.taskId}`;
|
||||
const item = this.dialogInputCache.find(item => item.key == key);
|
||||
const item = this.dialogInputCache.find(item => item.key == this.cacheKey);
|
||||
return item ? item.cache : '';
|
||||
},
|
||||
|
||||
setInputCache(cache) {
|
||||
const key = this.dialogId || `t_${this.taskId}`;
|
||||
const index = this.dialogInputCache.findIndex(item => item.key == key);
|
||||
const data = {key, cache}
|
||||
if (index > -1) {
|
||||
this.$store.state.dialogInputCache.splice(index, 1, data)
|
||||
} else {
|
||||
this.$store.state.dialogInputCache.push(data)
|
||||
}
|
||||
//
|
||||
$A.IDBSave("dialogInputCache", this.$store.state.dialogInputCache, 600);
|
||||
},
|
||||
|
||||
onClickEditor() {
|
||||
this.updateEmojiQuick(this.value)
|
||||
},
|
||||
|
||||
16
resources/assets/js/store/actions.js
vendored
16
resources/assets/js/store/actions.js
vendored
@ -2346,6 +2346,22 @@ export default {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 保存聊天草稿
|
||||
* @param state
|
||||
* @param data {key, cache}
|
||||
*/
|
||||
saveDialogInputCache({state}, data) {
|
||||
const index = state.dialogInputCache.findIndex(item => item.key == data.key);
|
||||
if (index > -1) {
|
||||
state.dialogInputCache.splice(index, 1, data)
|
||||
} else {
|
||||
state.dialogInputCache.push(data)
|
||||
}
|
||||
//
|
||||
$A.IDBSave("dialogInputCache", state.dialogInputCache, 600);
|
||||
},
|
||||
|
||||
/** *****************************************************************************************/
|
||||
/** ************************************** 消息 **********************************************/
|
||||
/** *****************************************************************************************/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user