分离子任务缓存

This commit is contained in:
aipaw 2021-06-22 09:51:26 +08:00
parent 06663dd1a9
commit db37cce011
8 changed files with 31 additions and 42 deletions

View File

@ -81,9 +81,6 @@ export default {
list() { list() {
let datas = $A.cloneJSON(this.tasks); let datas = $A.cloneJSON(this.tasks);
datas = datas.filter((data) => { datas = datas.filter((data) => {
if (data.parent_id > 0) {
return false;
}
if (data.complete_at) { if (data.complete_at) {
return false; return false;
} }

View File

@ -444,9 +444,6 @@ export default {
myList() { myList() {
const {projectId, tasks, searchText, projectCompleteShow, userId} = this; const {projectId, tasks, searchText, projectCompleteShow, userId} = this;
const array = tasks.filter((task) => { const array = tasks.filter((task) => {
if (task.parent_id > 0) {
return false;
}
if (task.project_id != projectId) { if (task.project_id != projectId) {
return false; return false;
} }
@ -476,9 +473,6 @@ export default {
undoneList() { undoneList() {
const {projectId, tasks, searchText, projectCompleteShow} = this; const {projectId, tasks, searchText, projectCompleteShow} = this;
const array = tasks.filter((task) => { const array = tasks.filter((task) => {
if (task.parent_id > 0) {
return false;
}
if (task.project_id != projectId) { if (task.project_id != projectId) {
return false; return false;
} }
@ -508,9 +502,6 @@ export default {
completedCount() { completedCount() {
const {projectId, tasks} = this; const {projectId, tasks} = this;
return tasks.filter((task) => { return tasks.filter((task) => {
if (task.parent_id > 0) {
return false;
}
if (task.project_id != projectId) { if (task.project_id != projectId) {
return false; return false;
} }
@ -521,9 +512,6 @@ export default {
completedList() { completedList() {
const {projectId, tasks, searchText} = this; const {projectId, tasks, searchText} = this;
const array = tasks.filter((task) => { const array = tasks.filter((task) => {
if (task.parent_id > 0) {
return false;
}
if (task.project_id != projectId) { if (task.project_id != projectId) {
return false; return false;
} }

View File

@ -466,7 +466,7 @@ export default {
}, },
computed: { computed: {
...mapState(['userId', 'projects', 'columns', 'taskId', 'tasks', 'taskContents', 'taskFiles', 'taskPriority']), ...mapState(['userId', 'projects', 'columns', 'taskId', 'taskSubs', 'taskContents', 'taskFiles', 'taskPriority']),
projectName() { projectName() {
if (!this.taskDetail.project_id) { if (!this.taskDetail.project_id) {
@ -513,7 +513,7 @@ export default {
if (!this.taskId) { if (!this.taskId) {
return []; return [];
} }
return this.tasks.filter(({parent_id}) => { return this.taskSubs.filter(({parent_id}) => {
return parent_id == this.taskId return parent_id == this.taskId
}).sort((a, b) => { }).sort((a, b) => {
return a.id - b.id; return a.id - b.id;

View File

@ -142,11 +142,11 @@ export default {
}, },
computed: { computed: {
...mapState(['tasks', 'columns']), ...mapState(['taskSubs', 'columns']),
subTask() { subTask() {
return function(task_id) { return function(task_id) {
return this.tasks.filter(({parent_id}) => { return this.taskSubs.filter(({parent_id}) => {
return parent_id == task_id return parent_id == task_id
}).sort((a, b) => { }).sort((a, b) => {
return a.id - b.id; return a.id - b.id;

View File

@ -139,9 +139,6 @@ export default {
todayEnd = new Date($A.formatDate("Y-m-d 23:59:59")); todayEnd = new Date($A.formatDate("Y-m-d 23:59:59"));
let datas = $A.cloneJSON(this.tasks); let datas = $A.cloneJSON(this.tasks);
datas = datas.filter((data) => { datas = datas.filter((data) => {
if (data.parent_id > 0) {
return false;
}
if (data.complete_at) { if (data.complete_at) {
return false; return false;
} }

View File

@ -275,7 +275,6 @@ export default {
data.forEach((project) => { data.forEach((project) => {
dispatch("saveProject", project) dispatch("saveProject", project)
}); });
return;
} else if (state.method.isJson(data)) { } else if (state.method.isJson(data)) {
let index = state.projects.findIndex(({id}) => id == data.id); let index = state.projects.findIndex(({id}) => id == data.id);
if (index > -1) { if (index > -1) {
@ -283,10 +282,10 @@ export default {
} else { } else {
state.projects.push(data); state.projects.push(data);
} }
setTimeout(() => {
state.method.setStorage("cacheProjects", state.cacheProjects = state.projects);
})
} }
setTimeout(() => {
state.method.setStorage("cacheProjects", state.cacheProjects = state.projects);
})
}, },
/** /**
@ -433,7 +432,6 @@ export default {
data.forEach((column) => { data.forEach((column) => {
dispatch("saveColumn", column) dispatch("saveColumn", column)
}); });
return;
} else if (state.method.isJson(data)) { } else if (state.method.isJson(data)) {
let index = state.columns.findIndex(({id}) => id == data.id); let index = state.columns.findIndex(({id}) => id == data.id);
if (index > -1) { if (index > -1) {
@ -441,10 +439,10 @@ export default {
} else { } else {
state.columns.push(data); state.columns.push(data);
} }
setTimeout(() => {
state.method.setStorage("cacheColumns", state.cacheColumns = state.columns);
})
} }
setTimeout(() => {
state.method.setStorage("cacheColumns", state.cacheColumns = state.columns);
})
}, },
/** /**
@ -485,6 +483,9 @@ export default {
} }
}).then(result => { }).then(result => {
const ids = result.data.data.map(({id}) => id) const ids = result.data.data.map(({id}) => id)
if (ids.length == 0) {
return;
}
state.columns = state.columns.filter((item) => item.project_id != project_id || ids.includes(item.id)); state.columns = state.columns.filter((item) => item.project_id != project_id || ids.includes(item.id));
dispatch("saveColumn", result.data.data); dispatch("saveColumn", result.data.data);
}).catch(e => { }).catch(e => {
@ -530,13 +531,13 @@ export default {
data.forEach((task) => { data.forEach((task) => {
dispatch("saveTask", task) dispatch("saveTask", task)
}); });
return;
} else if (state.method.isJson(data)) { } else if (state.method.isJson(data)) {
let index = state.tasks.findIndex(({id}) => id == data.id); let key = data.parent_id > 0 ? 'taskSubs' : 'tasks';
let index = state[key].findIndex(({id}) => id == data.id);
if (index > -1) { if (index > -1) {
state.tasks.splice(index, 1, Object.assign(state.tasks[index], data)); state[key].splice(index, 1, Object.assign(state[key][index], data));
} else { } else {
state.tasks.push(data); state[key].push(data);
} }
// //
if (data.is_subtask) { if (data.is_subtask) {
@ -548,10 +549,15 @@ export default {
if (data.is_update_content) { if (data.is_update_content) {
dispatch("getTaskContent", data.id); dispatch("getTaskContent", data.id);
} }
//
setTimeout(() => {
if (data.parent_id > 0) {
state.method.setStorage("cacheTaskSubs", state.cacheTaskSubs = state[key]);
} else {
state.method.setStorage("cacheTasks", state.cacheTasks = state[key]);
}
})
} }
setTimeout(() => {
state.method.setStorage("cacheTasks", state.cacheTasks = state.tasks);
})
}, },
/** /**
@ -595,11 +601,14 @@ export default {
}).then(result => { }).then(result => {
const resData = result.data; const resData = result.data;
const ids = resData.data.map(({id}) => id) const ids = resData.data.map(({id}) => id)
if (ids.length == 0) {
return;
}
if (data.project_id) { if (data.project_id) {
state.tasks = state.tasks.filter((item) => item.project_id != data.project_id || ids.includes(item.id)); state.tasks = state.tasks.filter((item) => item.project_id != data.project_id || ids.includes(item.id));
} }
if (data.parent_id) { if (data.parent_id) {
state.tasks = state.tasks.filter((item) => item.parent_id != data.parent_id || ids.includes(item.id)); state.taskSubs = state.taskSubs.filter((item) => item.parent_id != data.parent_id || ids.includes(item.id));
} }
dispatch("saveTask", resData.data); dispatch("saveTask", resData.data);
// //

View File

@ -1,6 +1,5 @@
export default { export default {
projectData(state) { projectData(state) {
console.log(111);
let projectId = state.projectId; let projectId = state.projectId;
if (projectId == 0) { if (projectId == 0) {
projectId = state.method.runNum(window.__projectId); projectId = state.method.runNum(window.__projectId);
@ -19,9 +18,6 @@ export default {
}); });
project.columns.forEach((column) => { project.columns.forEach((column) => {
column.tasks = state.method.cloneJSON(state.tasks.filter((task) => { column.tasks = state.method.cloneJSON(state.tasks.filter((task) => {
if (task.parent_id > 0) {
return false;
}
return task.column_id == column.id; return task.column_id == column.id;
})).sort((a, b) => { })).sort((a, b) => {
if (a.sort != b.sort) { if (a.sort != b.sort) {

View File

@ -254,6 +254,7 @@ state.cacheDialogMsg = state.method.getStorageJson("cacheDialogMsg");
state.cacheProjects = state.method.getStorageArray("cacheProjects"); state.cacheProjects = state.method.getStorageArray("cacheProjects");
state.cacheColumns = state.method.getStorageArray("cacheColumns"); state.cacheColumns = state.method.getStorageArray("cacheColumns");
state.cacheTasks = state.method.getStorageArray("cacheTasks"); state.cacheTasks = state.method.getStorageArray("cacheTasks");
state.cacheTaskSubs = state.method.getStorageArray("cacheTaskSubs");
// 会员信息 // 会员信息
state.userInfo = state.method.getStorageJson("userInfo"); state.userInfo = state.method.getStorageJson("userInfo");
@ -276,6 +277,7 @@ state.projects = [];
state.projectStatistics = {}; state.projectStatistics = {};
state.columns = []; state.columns = [];
state.tasks = []; state.tasks = [];
state.taskSubs = [];
state.taskContents = []; state.taskContents = [];
state.taskFiles = []; state.taskFiles = [];
state.taskLogs = []; state.taskLogs = [];