diff --git a/resources/assets/js/App.vue b/resources/assets/js/App.vue index 5b4bd55a9..c8032be9a 100755 --- a/resources/assets/js/App.vue +++ b/resources/assets/js/App.vue @@ -48,7 +48,8 @@ export default { data() { return { routePath: null, - searchInter: null, + appInter: null, + countDown: Math.min(30, 60 - $A.Date().getSeconds()), } }, @@ -62,7 +63,7 @@ export default { window.addEventListener('resize', this.windowSizeListener) window.addEventListener('scroll', this.windowScrollListener) window.addEventListener('message', this.windowHandleMessage) - this.searchInter = setInterval(this.searchEnter, 1000) + this.appInter = setInterval(this.appTimerHandler, 1000) $A.loadVConsole() }, @@ -70,7 +71,7 @@ export default { window.removeEventListener('resize', this.windowSizeListener) window.removeEventListener('scroll', this.windowScrollListener) window.removeEventListener('message', this.windowHandleMessage) - this.searchInter && clearInterval(this.searchInter) + this.appInter && clearInterval(this.appInter) }, computed: { @@ -161,6 +162,15 @@ export default { }, methods: { + appTimerHandler() { + this.searchEnter() + // + this.countDown-- + if (this.countDown <= 0) { + this.countDown = Math.min(30, 60 - $A.Date().getSeconds()) + this.$store.dispatch("todayAndOverdue") + } + }, searchEnter() { let row = $A(".sreachBox"); if (row.length === 0) { diff --git a/resources/assets/js/functions/common.js b/resources/assets/js/functions/common.js index 972f26f13..dd7f4c2bb 100755 --- a/resources/assets/js/functions/common.js +++ b/resources/assets/js/functions/common.js @@ -289,19 +289,20 @@ const localforage = require("localforage"); /** * 返回 时间对象|时间戳 - * @param v - * @param stamp 是否返回时间戳 + * @param v 支持时间戳|时间格式字符串|时间对象|空 + * @param timestamp 是否返回时间戳 * @returns {Date|number} * @constructor */ - Date(v, stamp = false) { + Date(v = undefined, timestamp = false) { if (typeof v === "string" && this.strExists(v, "-")) { v = v.replace(/-/g, '/'); } - if (stamp === true) { - return Math.round(new Date(v).getTime() / 1000) + const d = v === undefined || v === null ? new Date() : new Date(v); + if (timestamp === true) { + return Math.round(d.getTime() / 1000) } - return new Date(v); + return d; }, /** diff --git a/resources/assets/js/store/actions.js b/resources/assets/js/store/actions.js index 2f967650b..c9e506cff 100644 --- a/resources/assets/js/store/actions.js +++ b/resources/assets/js/store/actions.js @@ -1611,6 +1611,30 @@ export default { $A.IDBSave("cacheTasks", state.cacheTasks); }, + /** + * 更新任务“今日任务”、“过期任务” + * @param state + * @param dispatch + */ + todayAndOverdue({state, dispatch}) { + state.cacheTasks.some(task => { + if (!task.end_at) { + return false; + } + const data = {today: false, overdue: false}; + const endAt = $A.Date(task.end_at, true) + if (!task.today) { + data.today = $A.formatDate('Y-m-d', endAt) == $A.formatDate('Y-m-d') + } + if (!task.overdue) { + data.overdue = endAt < $A.Time(); + } + if (data.today || data.overdue) { + dispatch("saveTask", Object.assign(task, data)); + } + }) + }, + /** * 增加任务消息数量 * @param state