From cf41e714941b4500b49474bd71a9d279d04e8be3 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Sat, 25 Dec 2021 01:06:32 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BB=AA=E8=A1=A8=E7=9B=98=E5=AE=8C?= =?UTF-8?q?=E6=88=90=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pages/manage/components/ProjectList.vue | 61 ++++++++------- .../assets/js/pages/manage/dashboard.vue | 76 +++++++++++++------ .../assets/sass/pages/page-dashboard.scss | 9 +++ 3 files changed, 98 insertions(+), 48 deletions(-) diff --git a/resources/assets/js/pages/manage/components/ProjectList.vue b/resources/assets/js/pages/manage/components/ProjectList.vue index 07747a02..4c34b796 100644 --- a/resources/assets/js/pages/manage/components/ProjectList.vue +++ b/resources/assets/js/pages/manage/components/ProjectList.vue @@ -430,7 +430,7 @@ export default { columnTopShow: {}, taskLoad: {}, - completeJust: [], + completeTask: [], sortField: 'end_at', sortType: 'desc', @@ -534,13 +534,13 @@ export default { }, myList() { - const {projectId, tasks, searchText, userId, completeJust, sortField, sortType} = this; + const {projectId, tasks, searchText, userId, completeTask, sortField, sortType} = this; const array = tasks.filter((task) => { if (task.project_id != projectId) { return false; } if (!this.tablePanel('completedTask')) { - if (task.complete_at && !completeJust.find(id => id == task.id)) { + if (task.complete_at && !completeTask.find(id => id == task.id)) { return false; } } @@ -567,13 +567,13 @@ export default { }, helpList() { - const {projectId, tasks, searchText, userId, completeJust, sortField, sortType} = this; + const {projectId, tasks, searchText, userId, completeTask, sortField, sortType} = this; const array = tasks.filter((task) => { if (task.project_id != projectId) { return false; } if (!this.tablePanel('completedTask')) { - if (task.complete_at && !completeJust.find(id => id == task.id)) { + if (task.complete_at && !completeTask.find(id => id == task.id)) { return false; } } @@ -600,13 +600,13 @@ export default { }, undoneList() { - const {projectId, tasks, searchText, completeJust, sortField, sortType} = this; + const {projectId, tasks, searchText, completeTask, sortField, sortType} = this; const array = tasks.filter((task) => { if (task.project_id != projectId) { return false; } if (!this.tablePanel('completedTask')) { - if (task.complete_at && !completeJust.find(id => id == task.id)) { + if (task.complete_at && !completeTask.find(id => id == task.id)) { return false; } } @@ -615,7 +615,7 @@ export default { return false; } } - return !task.complete_at || completeJust.find(id => id == task.id); + return !task.complete_at || completeTask.find(id => id == task.id); }); return array.sort((a, b) => { if (sortType == 'asc') { @@ -681,7 +681,7 @@ export default { this.sortData = this.getSort(); }, '$route'() { - this.completeJust = []; + this.completeTask = []; } }, @@ -885,7 +885,7 @@ export default { this.updateTask(task, { complete_at: $A.formatDate("Y-m-d H:i:s") }) - this.completeJust.push(task.id) + this.completeTask.push(task.id) break; case 'uncomplete': @@ -893,6 +893,10 @@ export default { this.updateTask(task, { complete_at: false }) + let index = this.completeTask.findIndex(id => id == task.id) + if (index > -1) { + this.completeTask.splice(index, 1) + } break; case 'archived': @@ -903,21 +907,26 @@ export default { }, updateTask(task, updata) { - if (this.taskLoad[task.id] === true) { - return; - } - this.$set(this.taskLoad, task.id, true); - // - Object.keys(updata).forEach(key => this.$set(task, key, updata[key])); - // - this.$store.dispatch("taskUpdate", Object.assign(updata, { - task_id: task.id, - })).then(() => { - this.$set(this.taskLoad, task.id, false); - }).catch(({msg}) => { - $A.modalError(msg); - this.$set(this.taskLoad, task.id, false); - this.$store.dispatch("getTaskOne", task.id); + return new Promise((resolve, reject) => { + if (this.taskLoad[task.id] === true) { + reject() + return; + } + this.$set(this.taskLoad, task.id, true); + // + Object.keys(updata).forEach(key => this.$set(task, key, updata[key])); + // + this.$store.dispatch("taskUpdate", Object.assign(updata, { + task_id: task.id, + })).then(() => { + this.$set(this.taskLoad, task.id, false); + resolve() + }).catch(({msg}) => { + $A.modalError(msg); + this.$set(this.taskLoad, task.id, false); + this.$store.dispatch("getTaskOne", task.id); + reject() + }); }); }, @@ -1140,7 +1149,7 @@ export default { toggleCompleted() { this.$store.dispatch('toggleTablePanel', 'completedTask'); - this.completeJust = []; + this.completeTask = []; }, formatTime(date) { diff --git a/resources/assets/js/pages/manage/dashboard.vue b/resources/assets/js/pages/manage/dashboard.vue index 79917881..5d72e89f 100644 --- a/resources/assets/js/pages/manage/dashboard.vue +++ b/resources/assets/js/pages/manage/dashboard.vue @@ -33,16 +33,20 @@
  • - +
    - +
    @@ -111,7 +115,7 @@ export default { taskLoad: {}, - downList: [] + completeTask: [], } }, @@ -147,16 +151,23 @@ export default { }, list() { - const {dashboard} = this; + const {dashboard, completeTask} = this; let data = []; switch (dashboard) { case 'today': - data = this.dashboardData.today; + data = $A.cloneJSON(this.dashboardData.today); break case 'overdue': - data = this.dashboardData.overdue; + data = $A.cloneJSON(this.dashboardData.overdue); break } + if (completeTask.length > 0) { + completeTask.forEach(task => { + if (!data.find(({id}) => id == task.id)) { + data.push(task); + } + }) + } return data.sort((a, b) => { return $A.Date(a.end_at) - $A.Date(b.end_at); }); @@ -176,6 +187,15 @@ export default { }, }, + watch: { + '$route'() { + this.completeTask = []; + }, + dashboard() { + this.completeTask = []; + } + }, + methods: { dropTask(task, command) { switch (command) { @@ -183,12 +203,19 @@ export default { if (task.complete_at) return; this.updateTask(task, { complete_at: $A.formatDate("Y-m-d H:i:s") + }).then(() => { + this.completeTask.push(task) }) break; case 'uncomplete': if (!task.complete_at) return; this.updateTask(task, { complete_at: false + }).then(() => { + let index = this.completeTask.findIndex(({id}) => id == task.id) + if (index > -1) { + this.completeTask.splice(index, 1) + } }) break; case 'archived': @@ -206,22 +233,27 @@ export default { }, updateTask(task, updata) { - if (this.taskLoad[task.id] === true) { - return; - } - this.$set(this.taskLoad, task.id, true); - // - Object.keys(updata).forEach(key => this.$set(task, key, updata[key])); - // - this.$store.dispatch("taskUpdate", Object.assign(updata, { - task_id: task.id, - })).then(() => { - this.$set(this.taskLoad, task.id, false); - }).catch(({msg}) => { - $A.modalError(msg); - this.$set(this.taskLoad, task.id, false); - this.$store.dispatch("getTaskOne", task.id); - }); + return new Promise((resolve, reject) => { + if (this.taskLoad[task.id] === true) { + reject() + return; + } + this.$set(this.taskLoad, task.id, true); + // + Object.keys(updata).forEach(key => this.$set(task, key, updata[key])); + // + this.$store.dispatch("taskUpdate", Object.assign(updata, { + task_id: task.id, + })).then(() => { + this.$set(this.taskLoad, task.id, false); + resolve() + }).catch(({msg}) => { + $A.modalError(msg); + this.$set(this.taskLoad, task.id, false); + this.$store.dispatch("getTaskOne", task.id); + reject(); + }); + }) }, archivedOrRemoveTask(task, type) { diff --git a/resources/assets/sass/pages/page-dashboard.scss b/resources/assets/sass/pages/page-dashboard.scss index 4c32a074..8cf2c43a 100644 --- a/resources/assets/sass/pages/page-dashboard.scss +++ b/resources/assets/sass/pages/page-dashboard.scss @@ -102,6 +102,15 @@ &:last-child { margin-bottom: 12px; } + &.complete { + .item-title { + opacity: 0.5; + text-decoration: line-through; + } + .item-icon { + display: none; + } + } .priority-color { position: absolute; top: 50%;