From 82b2ef3a73bcb70c14033a0d5fdaf135661ef8ab Mon Sep 17 00:00:00 2001 From: kuaifan Date: Mon, 23 May 2022 13:02:31 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E8=81=8A=E5=A4=A9=E8=BE=93=E5=85=A5?= =?UTF-8?q?=E6=A1=86=E8=8D=89=E7=A8=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manage/components/ChatInput/index.vue | 50 ++++++++++++++++--- resources/assets/js/store/state.js | 1 + 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/resources/assets/js/pages/manage/components/ChatInput/index.vue b/resources/assets/js/pages/manage/components/ChatInput/index.vue index 9e9019906..a1407fc98 100755 --- a/resources/assets/js/pages/manage/components/ChatInput/index.vue +++ b/resources/assets/js/pages/manage/components/ChatInput/index.vue @@ -139,6 +139,7 @@ export default { this.observer.observe(this.$refs.editor); }, beforeDestroy() { + this.inputCache(this.dialogId, this.value); if (this.quill) { this.quill = null } @@ -148,9 +149,7 @@ export default { } }, computed: { - ...mapState(['cacheProjects', 'cacheTasks', 'cacheUserBasic', 'userId']), - - ...mapGetters(['dashboardTask', 'transforTasks']), + ...mapState(['dialogInputCache', 'cacheProjects', 'cacheTasks', 'cacheUserBasic', 'userId']), editorStyle() { const {wrapperWidth, editorHeight} = this; @@ -171,7 +170,7 @@ export default { if (this.quill) { if (newVal && newVal !== this._content) { this._content = newVal - this.quill.pasteHTML(newVal) + this.setContent(newVal) } else if(!newVal) { this.quill.setText('') } @@ -186,9 +185,11 @@ export default { }, // Reset lists - dialogId() { + dialogId(id1, id2) { this.userList = null; this.taskList = null; + this.inputCache(id2, this.value) + this.$emit('input', this.inputCache(id1)) }, taskId() { this.userList = null; @@ -206,6 +207,10 @@ export default { this.$refs.moreTip.updatePopper() } }, + + dialogInputCache() { + this.$emit('input', this.inputCache(this.dialogId)) + } }, methods: { init() { @@ -290,7 +295,9 @@ export default { // Set editor content if (this.value) { - this.quill.pasteHTML(this.value) + this.setContent(this.value) + } else { + this.$emit('input', this.inputCache(this.dialogId)) } // Disabled editor @@ -339,6 +346,35 @@ export default { this.$emit('on-ready', this.quill) }, + setText(value) { + if (this.quill) { + this.quill.setText(value) + } + }, + + setContent(value) { + if (this.quill) { + this.quill.setContents(this.quill.clipboard.convert(value)) + } + }, + + inputCache(key, cache) { + if (cache === undefined) { + const item = this.dialogInputCache.find(item => item.key == key); + return item ? item.cache : ''; + } + 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) + } + setTimeout(_ => { + $A.setStorage("cacheDialogInput", this.$store.state.dialogInputCache); + }) + }, + focus() { this.$nextTick(() => { this.quill && this.quill.focus() @@ -523,7 +559,7 @@ export default { }) } // 待完成任务 - let data = this.transforTasks(this.dashboardTask['all']); + let data = this.$store.getters.transforTasks(this.$store.getters.dashboardTask['all']); if (data.length > 0) { data = data.sort((a, b) => { return $A.Date(a.end_at || "2099-12-31 23:59:59") - $A.Date(b.end_at || "2099-12-31 23:59:59"); diff --git a/resources/assets/js/store/state.js b/resources/assets/js/store/state.js index 55f0d8c6f..cc8550c06 100644 --- a/resources/assets/js/store/state.js +++ b/resources/assets/js/store/state.js @@ -54,6 +54,7 @@ const stateData = { // 会话聊天 dialogMsgs: [], + dialogInputCache: $A.getStorageArray("cacheDialogInput"), // 文件 files: [],