From 3dc82694061ce3cbe9fcc8602ac1abfc87cb2021 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Sat, 10 Dec 2022 21:21:42 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/assets/js/functions/common.js | 10 +++----- .../manage/components/ChatInput/index.vue | 25 +++++++------------ resources/assets/js/store/actions.js | 16 ++++++++++++ 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/resources/assets/js/functions/common.js b/resources/assets/js/functions/common.js index 137c4e4e0..1327acb9c 100755 --- a/resources/assets/js/functions/common.js +++ b/resources/assets/js/functions/common.js @@ -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) { diff --git a/resources/assets/js/pages/manage/components/ChatInput/index.vue b/resources/assets/js/pages/manage/components/ChatInput/index.vue index 51ff0dbdf..7d67107db 100755 --- a/resources/assets/js/pages/manage/components/ChatInput/index.vue +++ b/resources/assets/js/pages/manage/components/ChatInput/index.vue @@ -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) }, diff --git a/resources/assets/js/store/actions.js b/resources/assets/js/store/actions.js index bbdd5e832..d3b5cec9e 100644 --- a/resources/assets/js/store/actions.js +++ b/resources/assets/js/store/actions.js @@ -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); + }, + /** *****************************************************************************************/ /** ************************************** 消息 **********************************************/ /** *****************************************************************************************/