perf: 仪表盘列表新增显示协助的任务

This commit is contained in:
kuaifan 2022-06-24 10:45:42 +08:00
parent 707c74264b
commit d4d3f1245b
3 changed files with 48 additions and 43 deletions

View File

@ -300,6 +300,7 @@ class ProjectTask extends AbstractModel
'project_tasks.*', 'project_tasks.*',
'project_task_users.owner' 'project_task_users.owner'
]) ])
->selectRaw("1 AS assist")
->join('project_task_users', 'project_tasks.id', '=', 'project_task_users.task_id') ->join('project_task_users', 'project_tasks.id', '=', 'project_task_users.task_id')
->where('project_task_users.userid', $userid); ->where('project_task_users.userid', $userid);
if ($owner !== null) { if ($owner !== null) {

View File

@ -118,12 +118,12 @@ export default {
}, },
computed: { computed: {
...mapState(['userInfo', 'loadDashboardTasks']), ...mapState(['userInfo', 'cacheTasks', 'taskCompleteTemps', 'loadDashboardTasks']),
...mapGetters(['dashboardTask', 'transforTasks']), ...mapGetters(['dashboardTask', 'transforTasks']),
columns() { columns() {
let list = []; const list = [];
['today', 'overdue', 'all'].some(type => { ['today', 'overdue', 'all'].some(type => {
let data = this.transforTasks(this.dashboardTask[type]); let data = this.transforTasks(this.dashboardTask[type]);
list.push({ list.push({
@ -134,9 +134,37 @@ export default {
}) })
}) })
}) })
list.push({
type: 'assist',
title: this.getTitle('assist'),
list: this.assistList.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");
})
})
return list; return list;
}, },
assistList() {
const filterTask = (task, chackCompleted = true) => {
if (task.archived_at) {
return false;
}
if (task.complete_at && chackCompleted === true) {
return false;
}
return task.assist && !task.owner;
}
let array = this.cacheTasks.filter(task => filterTask(task));
if (this.taskCompleteTemps.length > 0) {
let tmps = this.cacheTasks.filter(task => this.taskCompleteTemps.includes(task.id) && filterTask(task, false));
if (tmps.length > 0) {
array = $A.cloneJSON(array)
array.push(...tmps);
}
}
return array
},
total() { total() {
const {dashboardTask} = this; const {dashboardTask} = this;
return dashboardTask.today_count + dashboardTask.overdue_count + dashboardTask.all_count; return dashboardTask.today_count + dashboardTask.overdue_count + dashboardTask.all_count;
@ -152,6 +180,8 @@ export default {
return this.$L('超期任务'); return this.$L('超期任务');
case 'all': case 'all':
return this.$L('待完成任务'); return this.$L('待完成任务');
case 'assist':
return this.$L('协助的任务');
default: default:
return ''; return '';
} }

View File

@ -1238,62 +1238,36 @@ export default {
* @param timeout * @param timeout
*/ */
getTaskForDashboard({state, dispatch, getters}, timeout) { getTaskForDashboard({state, dispatch, getters}, timeout) {
window.__getTaskForDashboard && clearTimeout(window.__getTaskForDashboard)
if (typeof timeout === "number") { if (typeof timeout === "number") {
window.__getTaskForDashboard && clearTimeout(window.__getTaskForDashboard)
if (timeout > -1) { if (timeout > -1) {
window.__getTaskForDashboard = setTimeout(() => { window.__getTaskForDashboard = setTimeout(_ => dispatch("getTaskForDashboard", null), timeout)
dispatch("getTaskForDashboard", null)
}, timeout)
} }
return; return;
} }
//
if (state.loadDashboardTasks === true) { if (state.loadDashboardTasks === true) {
return; return;
} }
state.loadDashboardTasks = true; state.loadDashboardTasks = true;
// //
const time = $A.Time() const time = $A.Time()
const {today, overdue,all} = getters.dashboardTask; const {today, overdue, all} = getters.dashboardTask;
const currentIds = today.map(({id}) => id) const currentIds = today.map(({id}) => id)
currentIds.push(...overdue.map(({id}) => id)) currentIds.push(...overdue.map(({id}) => id))
currentIds.push(...all.map(({id}) => id)) currentIds.push(...all.map(({id}) => id))
// //
let loadIng = 3; dispatch("getTasks", {
let call = () => { complete: "no",
if (loadIng <= 0) { }).finally(_ => {
state.loadDashboardTasks = false; state.loadDashboardTasks = false;
// //
const {today, overdue,all} = getters.dashboardTask; const {today, overdue, all} = getters.dashboardTask;
const newIds = today.filter(task => task._time >= time).map(({id}) => id) const newIds = today.filter(task => task._time >= time).map(({id}) => id)
newIds.push(...overdue.filter(task => task._time >= time).map(({id}) => id)) newIds.push(...overdue.filter(task => task._time >= time).map(({id}) => id))
newIds.push(...all.filter(task => task._time >= time).map(({id}) => id)) newIds.push(...all.filter(task => task._time >= time).map(({id}) => id))
dispatch("forgetTask", currentIds.filter(v => newIds.indexOf(v) == -1)) dispatch("forgetTask", currentIds.filter(v => newIds.indexOf(v) == -1))
return; })
}
loadIng--;
if (loadIng == 2) {
// 获取今日任务
dispatch("getTasks", {
complete: "no",
time: [
$A.formatDate("Y-m-d 00:00:00"),
$A.formatDate("Y-m-d 23:59:59")
],
}).then(call).catch(call)
} else if (loadIng == 1) {
// 获取过期任务
dispatch("getTasks", {
complete: "no",
time_before: $A.formatDate("Y-m-d H:i:s"),
}).then(call).catch(call)
} else if((loadIng == 0)) {
// 获取待处理任务
dispatch("getTasks", {
complete: "no",
}).then(call).catch(call)
}
}
call();
}, },
/** /**