pref: 日历任务缓存

This commit is contained in:
kuaifan 2022-01-07 00:56:03 +08:00
parent 818495a697
commit db6114a4ee
2 changed files with 28 additions and 3 deletions

View File

@ -67,6 +67,7 @@ export default {
calendarList: [], calendarList: [],
loadIng: 0, loadIng: 0,
loadTimeout: null,
} }
}, },
@ -95,6 +96,8 @@ export default {
category: isAllday ? 'allday' : 'time', category: isAllday ? 'allday' : 'time',
start: $A.Date(data.start_at).toISOString(), start: $A.Date(data.start_at).toISOString(),
end: $A.Date(data.end_at).toISOString(), end: $A.Date(data.end_at).toISOString(),
start_at: data.start_at,
end_at: data.end_at,
color: "#515a6e", color: "#515a6e",
bgColor: data.color || '#E3EAFD', bgColor: data.color || '#E3EAFD',
borderColor: data.p_color, borderColor: data.p_color,
@ -102,6 +105,7 @@ export default {
priority: '', priority: '',
preventClick: true, preventClick: true,
isChecked: false, isChecked: false,
_time: data._time,
}; };
if (data.p_name) { if (data.p_name) {
task.priority = '<span class="priority" style="background-color:' + data.p_color + '">' + data.p_name + '</span>'; task.priority = '<span class="priority" style="background-color:' + data.p_color + '">' + data.p_name + '</span>';
@ -193,19 +197,40 @@ export default {
getTask(time) { getTask(time) {
if (this.loadIng > 0) { if (this.loadIng > 0) {
setTimeout(() => { clearTimeout(this.loadTimeout)
this.loadTimeout = setTimeout(() => {
this.getTask(time) this.getTask(time)
}, 100) }, 100)
return; return;
} }
//
const timeStart = $A.Date($A.formatDate(time[0] + " 00:00:00")),
timeEnd = $A.Date($A.formatDate(time[1] + " 23:59:59")),
now = $A.Time();
const find = (item, n) => {
if (n === true && item._time < now) {
return false
}
const start = $A.Date(item.start_at),
end = $A.Date(item.end_at);
return (start <= timeStart && timeStart <= end) || (start <= timeEnd && timeEnd <= end) || (start > timeStart && timeEnd > end);
}
const currentIds = this.list.filter(item => find(item)).map(({id}) => id);
const call = () => {
const newIds = this.list.filter(item => find(item, true)).map(({id}) => id);
this.$store.dispatch("forgetTask", currentIds.filter(v => newIds.indexOf(v) == -1))
}
//
this.loadIng++; this.loadIng++;
this.$store.dispatch("getTasks", { this.$store.dispatch("getTasks", {
time: time, time,
complete: "no" complete: "no"
}).then(() => { }).then(() => {
this.loadIng--; this.loadIng--;
call()
}).catch(() => { }).catch(() => {
this.loadIng--; this.loadIng--;
call()
}) })
}, },

View File

@ -1085,7 +1085,7 @@ export default {
const time = $A.Time() const time = $A.Time()
const currentIds = state.tasks.filter(task => task.project_id == project_id).map(({id}) => id) const currentIds = state.tasks.filter(task => task.project_id == project_id).map(({id}) => id)
// //
let call = () => { const call = () => {
const newIds = state.tasks.filter(task => task.project_id == project_id && task._time >= time).map(({id}) => id) const newIds = state.tasks.filter(task => task.project_id == project_id && task._time >= time).map(({id}) => id)
dispatch("forgetTask", currentIds.filter(v => newIds.indexOf(v) == -1)) dispatch("forgetTask", currentIds.filter(v => newIds.indexOf(v) == -1))
} }