Skip to content

Commit

Permalink
pref: 日历任务缓存
Browse files Browse the repository at this point in the history
  • Loading branch information
kuaifan committed Jan 6, 2022
1 parent 818495a commit db6114a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
29 changes: 27 additions & 2 deletions resources/assets/js/pages/manage/calendar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export default {
calendarList: [],
loadIng: 0,
loadTimeout: null,
}
},
Expand Down Expand Up @@ -95,13 +96,16 @@ export default {
category: isAllday ? 'allday' : 'time',
start: $A.Date(data.start_at).toISOString(),
end: $A.Date(data.end_at).toISOString(),
start_at: data.start_at,
end_at: data.end_at,
color: "#515a6e",
bgColor: data.color || '#E3EAFD',
borderColor: data.p_color,
complete_at: data.complete_at,
priority: '',
preventClick: true,
isChecked: false,
_time: data._time,
};
if (data.p_name) {
task.priority = '<span class="priority" style="background-color:' + data.p_color + '">' + data.p_name + '</span>';
Expand Down Expand Up @@ -193,19 +197,40 @@ export default {
getTask(time) {
if (this.loadIng > 0) {
setTimeout(() => {
clearTimeout(this.loadTimeout)
this.loadTimeout = setTimeout(() => {
this.getTask(time)
}, 100)
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.$store.dispatch("getTasks", {
time: time,
time,
complete: "no"
}).then(() => {
this.loadIng--;
call()
}).catch(() => {
this.loadIng--;
call()
})
},
Expand Down
2 changes: 1 addition & 1 deletion resources/assets/js/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ export default {
const time = $A.Time()
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)
dispatch("forgetTask", currentIds.filter(v => newIds.indexOf(v) == -1))
}
Expand Down

0 comments on commit db6114a

Please sign in to comment.