diff --git a/electron/electron.js b/electron/electron.js index a43b2121c..21b12e30e 100644 --- a/electron/electron.js +++ b/electron/electron.js @@ -1078,7 +1078,7 @@ autoUpdater.on('update-downloaded', info => { */ ipcMain.on('updateCheckAndDownload', (event, args) => { event.returnValue = "ok" - if (autoUpdating + 3600 > utils.Time()) { + if (autoUpdating + 3600 > utils.dayjs().unix()) { return // 限制1小时仅执行一次 } if (args.provider) { @@ -1094,11 +1094,11 @@ ipcMain.on('updateCheckAndDownload', (event, args) => { if (args.apiVersion) { if (utils.compareVersion(info.updateInfo.version, args.apiVersion) <= 0) { // 客户端版本 <= 接口版本 - autoUpdating = utils.Time() + autoUpdating = utils.dayjs().unix() autoUpdater.downloadUpdate().then(_ => {}).catch(_ => {}) } } else { - autoUpdating = utils.Time() + autoUpdating = utils.dayjs().unix() autoUpdater.downloadUpdate().then(_ => {}).catch(_ => {}) } }) diff --git a/electron/package.json b/electron/package.json index f5787fb64..a11f59a1f 100755 --- a/electron/package.json +++ b/electron/package.json @@ -41,6 +41,7 @@ "dependencies": { "axios": "^1.6.2", "crc": "^3.8.0", + "dayjs": "^1.11.13", "electron-config": "^2.0.0", "electron-log": "^5.1.1", "electron-screenshots-tool": "^1.1.2", diff --git a/electron/utils.js b/electron/utils.js index 9f65d8297..eb52d5daf 100644 --- a/electron/utils.js +++ b/electron/utils.js @@ -1,7 +1,26 @@ const fs = require("fs"); +const dayjs = require("dayjs"); const {shell, dialog, session} = require("electron"); module.exports = { + /** + * 时间对象 + * @param v + * @returns {*|dayjs.Dayjs} + */ + dayjs(v = undefined) { + if (/^\d{13,}$/.test(v)) { + return dayjs(Number(v)); + } + if (/^\d{10,}$/.test(v)) { + return dayjs(Number(v) * 1000); + } + if (v === null) { + v = 0 + } + return dayjs(v); + }, + /** * 是否数组 * @param obj @@ -253,23 +272,6 @@ module.exports = { return ((domain != null && domain.length > 0) ? domain[2] : ""); }, - /** - * 返回10位数时间戳 - * @param v - * @returns {number} - * @constructor - */ - Time(v = undefined) { - let time - if (typeof v === "string" && this.strExists(v, "-")) { - v = v.replace(/-/g, '/'); - time = new Date(v).getTime(); - } else { - time = new Date().getTime(); - } - return Math.round(time / 1000) - }, - /** * 显示窗口 * @param win diff --git a/package.json b/package.json index bed3bc26a..8d94b6a96 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "codemirror": "^5.65.16", "cross-env": "^7.0.3", "css-loader": "^6.7.2", + "dayjs": "^1.11.13", "dexie": "^3.2.3", "echarts": "^5.2.2", "element-sea": "^2.15.10-7", @@ -43,7 +44,6 @@ "lodash": "^4.17.21", "markdown-it": "^13.0.1", "markdown-it-link-attributes": "^4.0.1", - "moment": "^2.29.1", "node-sass": "^9.0.0", "notification-koro1": "^1.1.1", "openpgp_hi": "^5.7.0-1", diff --git a/resources/assets/js/App.vue b/resources/assets/js/App.vue index d190948ca..cc78429c8 100755 --- a/resources/assets/js/App.vue +++ b/resources/assets/js/App.vue @@ -49,7 +49,7 @@ export default { return { routePath: null, appInter: null, - countDown: Math.min(30, 60 - $A.Date(true).getSeconds()), + countDown: Math.min(30, 60 - $A.dayjs().second()), } }, @@ -167,7 +167,7 @@ export default { // this.countDown-- if (this.countDown <= 0) { - this.countDown = Math.min(30, 60 - $A.Date(true).getSeconds()) + this.countDown = Math.min(30, 60 - $A.dayjs().second()) this.$store.dispatch("todayAndOverdue") } }, diff --git a/resources/assets/js/components/DragBallComponent.vue b/resources/assets/js/components/DragBallComponent.vue index 33af5be0b..5f4c20808 100644 --- a/resources/assets/js/components/DragBallComponent.vue +++ b/resources/assets/js/components/DragBallComponent.vue @@ -152,7 +152,7 @@ export default { mouseDown(e) { this.record = { - time: new Date().getTime(), + time: $A.dayjs().valueOf(), top: this.floatDrag.offsetTop, left: this.floatDrag.offsetLeft, x: e.clientX - this.floatDrag.offsetLeft, @@ -183,7 +183,7 @@ export default { this.checkDraggablePosition(); this.floatDrag.style.transition = "all 0.3s"; // 点击事件 - if ((Math.abs(this.record.top - this.floatDrag.offsetTop) < 5 && Math.abs(this.record.left - this.floatDrag.offsetLeft) < 5) || new Date().getTime() - this.record.time < 200) { + if ((Math.abs(this.record.top - this.floatDrag.offsetTop) < 5 && Math.abs(this.record.left - this.floatDrag.offsetLeft) < 5) || $A.dayjs().valueOf() - this.record.time < 200) { this.$emit("on-click") } } diff --git a/resources/assets/js/components/GanttView.vue b/resources/assets/js/components/GanttView.vue index f5e5a5fce..51d670419 100644 --- a/resources/assets/js/components/GanttView.vue +++ b/resources/assets/js/components/GanttView.vue @@ -133,20 +133,19 @@ export default { const {mouseWidth, dateWidth} = this; return function(index) { let mouseDay = mouseWidth == 0 ? 0 : mouseWidth / dateWidth; - let date = new Date(); //今天00:00:00 - let nowDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0); + let nowDay = $A.dayjs().startOf('day'); //当前时间 - let curDay = new Date(nowDay.getTime() + mouseDay * 86400000); + let curDay = nowDay.clone().add(mouseDay, 'day'); //当月最后一天 - let lastDay = new Date(curDay.getFullYear(), curDay.getMonth() + 1, 0, 23, 59, 59); + let lastDay = curDay.clone().endOf('month'); //相差天数 let diffDay = (lastDay - curDay) / 1000 / 60 / 60 / 24; // let width = dateWidth * diffDay; if (index > 0) { - lastDay = new Date(curDay.getFullYear(), curDay.getMonth() + 1 + index, 0); - width = lastDay.getDate() * dateWidth; + lastDay = curDay.clone().add(index + 1, 'month').endOf('month'); + width = lastDay.date() * dateWidth; } return { width: width + 'px', @@ -157,16 +156,15 @@ export default { const {mouseWidth, dateWidth} = this; return function(index) { let mouseDay = mouseWidth == 0 ? 0 : mouseWidth / dateWidth; - let date = new Date(); //开始位置时间(今天00:00:00) - let nowDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0); + let nowDay = $A.dayjs().startOf('day'); //当前时间 - let curDay = new Date(nowDay.getTime() + mouseDay * 86400000); + let curDay = nowDay.clone().add(mouseDay, 'day'); // if (index > 0) { - curDay = new Date(curDay.getFullYear(), curDay.getMonth() + 1 + index, 0); + curDay = curDay.add(index + 1, 'month'); } - return $A.formatDate("Y-m", curDay) + return curDay.format('YYYY-MM') } }, dateNum() { @@ -184,8 +182,8 @@ export default { mouseData--; } let j = mouseWidth == 0 ? index - 1 : mouseData; - let date = new Date(new Date().getTime() + j * 86400000); - if ([0, 6].indexOf(date.getDay()) !== -1) { + let date = $A.dayjs().add(j, 'day'); + if ([0, 6].indexOf(date.day()) !== -1) { style.backgroundColor = '#f9fafb'; } // @@ -206,11 +204,11 @@ export default { mouseData--; } let j = mouseWidth == 0 ? index - 1 : mouseData; - let date = new Date(new Date().getTime() + j * 86400000) + let date = $A.dayjs().add(j, 'day'); if (type == 'day') { - return date.getDate(); + return date.date(); } else if (type == 'week') { - return this.$L(`星期${'日一二三四五六'.charAt(date.getDay())}`); + return this.$L(`星期${'日一二三四五六'.charAt(date.day())}`); } else { return date; } @@ -221,9 +219,8 @@ export default { return function(item) { const {start, end} = item.time; const {style, moveX, moveW} = item; - let date = new Date(); //开始位置时间戳(今天00:00:00时间戳) - let nowTime = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0).getTime(); + let nowTime = $A.dayjs().startOf('day').valueOf(); //距离开始位置多少天 let diffStartDay = (start - nowTime) / 1000 / 60 / 60 / 24; let diffEndDay = (end - nowTime) / 1000 / 60 / 60 / 24; @@ -421,9 +418,8 @@ export default { } }, scrollPosition(pos) { - let date = new Date(); //今天00:00:00 - let nowDay = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0); + let nowDay = $A.dayjs().startOf('day').valueOf(); //一个宽度的时间 let oneWidthTime = 86400000 / this.dateWidth; // diff --git a/resources/assets/js/components/RightBottom.vue b/resources/assets/js/components/RightBottom.vue index 2dd8932d3..f9cb553ca 100644 --- a/resources/assets/js/components/RightBottom.vue +++ b/resources/assets/js/components/RightBottom.vue @@ -190,7 +190,7 @@ export default { let key = "cacheAppdown::" + this.apiVersion let cache = await $A.IDBJson(key); let timeout = 600; - if (cache.time && cache.time + timeout > Math.round(new Date().getTime() / 1000)) { + if (cache.time && cache.time + timeout > $A.dayjs().unix()) { this.downloadUrl = cache.data.html_url; return; } @@ -202,7 +202,7 @@ export default { axios.get(`https://api.github.com/repos/${publish.owner}/${publish.repo}/releases`).then(({status, data}) => { this.loadIng--; if (status === 200 && $A.isArray(data)) { - cache.time = Math.round(new Date().getTime() / 1000) + cache.time = $A.dayjs().unix() cache.data = data.find(({tag_name}) => this.compareVersion(this.tagVersion(tag_name), this.apiVersion) === 0) || {} $A.IDBSave(key, cache); this.downloadUrl = cache.data.html_url; diff --git a/resources/assets/js/components/UserAvatar/tip.vue b/resources/assets/js/components/UserAvatar/tip.vue index 522fc9fec..7c7bda04d 100755 --- a/resources/assets/js/components/UserAvatar/tip.vue +++ b/resources/assets/js/components/UserAvatar/tip.vue @@ -109,9 +109,9 @@ export default { if (this.user.online || this.$store.state.userId === this.userid) { this.$emit('update:online', true) } else { - const now = $A.Time() - const line = $A.Time(this.user.line_at) - const seconds = now - line + const now = $A.dayjs() + const line = $A.dayjs(this.user.line_at) + const seconds = now.unix() - line.unix() let stats = '最后在线于很久以前'; if (seconds < 60) { stats = `最后在线于刚刚` @@ -120,12 +120,12 @@ export default { } else if (seconds < 3600 * 6) { stats = `最后在线于 ${Math.floor(seconds / 3600)} 小时前` } else { - const nowYmd = $A.formatDate('Y-m-d', now) - const lineYmd = $A.formatDate('Y-m-d', line) - const lineHi = $A.formatDate('H:i', line) + const nowYmd = now.format('YYYY-MM-DD') + const lineYmd = line.format('YYYY-MM-DD') + const lineHi = line.format('HH:mm') if (nowYmd === lineYmd) { stats = `最后在线于今天 ${lineHi}` - } else if ($A.formatDate('Y-m-d', now - 86400) === lineYmd) { + } else if (now.clone().subtract(1, 'day').format('YYYY-MM-DD') === lineYmd) { stats = `最后在线于昨天 ${lineHi}` } else if (seconds < 3600 * 24 * 365) { stats = `最后在线于 ${lineYmd}` diff --git a/resources/assets/js/components/UserSelect.vue b/resources/assets/js/components/UserSelect.vue index d5356fddc..2baca06ad 100755 --- a/resources/assets/js/components/UserSelect.vue +++ b/resources/assets/js/components/UserSelect.vue @@ -485,12 +485,12 @@ export default { return this.showDialog || dialog.type === 'user' }).sort((a, b) => { if (a.top_at || b.top_at) { - return $A.Date(b.top_at) - $A.Date(a.top_at); + return $A.dayjs(b.top_at) - $A.dayjs(a.top_at); } if (a.todo_num > 0 || b.todo_num > 0) { return b.todo_num - a.todo_num; } - return $A.Date(b.last_at) - $A.Date(a.last_at); + return $A.dayjs(b.last_at) - $A.dayjs(a.last_at); }).map(({id, name, type, group_type, avatar, dialog_user}) => { return { name, @@ -536,7 +536,7 @@ export default { this.contacts = data // const index = this.searchCache.findIndex(item => item.key == key); - const tmpData = {type: 'contact', key, data, time: $A.Time()}; + const tmpData = {type: 'contact', key, data, time: $A.dayjs().unix()}; if (index > -1) { this.searchCache.splice(index, 1, tmpData) } else { @@ -583,7 +583,7 @@ export default { this.projects = data // const index = this.searchCache.findIndex(item => item.key == key); - const tmpData = {type: 'project', key, data, time: $A.Time()}; + const tmpData = {type: 'project', key, data, time: $A.dayjs().unix()}; if (index > -1) { this.searchCache.splice(index, 1, tmpData) } else { diff --git a/resources/assets/js/directives/touchclick.js b/resources/assets/js/directives/touchclick.js index d6e35bb6c..bf5031c4e 100755 --- a/resources/assets/js/directives/touchclick.js +++ b/resources/assets/js/directives/touchclick.js @@ -12,7 +12,7 @@ export default { start: e => { e.preventDefault(); touchData.move = false; - touchData.time = new Date().getTime(); + touchData.time = $A.dayjs().valueOf(); touchData.x = e.touches ? e.touches[0].clientX : e.clientX; touchData.y = e.touches ? e.touches[0].clientY : e.clientY; }, @@ -27,7 +27,7 @@ export default { }, end: _ => { if (touchData.time > 0) { - if (!touchData.move && new Date().getTime() - touchData.time < 300) { + if (!touchData.move && $A.dayjs().valueOf() - touchData.time < 300) { binding.value(); } touchData.time = 0; diff --git a/resources/assets/js/functions/common.js b/resources/assets/js/functions/common.js index 302aa0003..b127fb4f8 100755 --- a/resources/assets/js/functions/common.js +++ b/resources/assets/js/functions/common.js @@ -1,4 +1,7 @@ const localforage = require("localforage"); +const dayjs = require("dayjs"); +const utc = require("dayjs/plugin/utc") +const timezone = require("dayjs/plugin/timezone"); /** * 基础函数 @@ -8,12 +11,33 @@ const localforage = require("localforage"); window.modalTransferIndex = 1000; localforage.config({name: 'DooTask', storeName: 'common'}); + dayjs.extend(utc); + dayjs.extend(timezone); + dayjs.tz.setDefault("Asia/Shanghai"); /** * ============================================================================= * ******************************* 基础函数类 ******************************* * ============================================================================= */ $.extend({ + /** + * 时间对象 + * @param v + * @returns {*|dayjs.Dayjs} + */ + dayjs(v = undefined) { + if (/^\d{13,}$/.test(v)) { + return dayjs(Number(v)); + } + if (/^\d{10,}$/.test(v)) { + return dayjs(Number(v) * 1000); + } + if (v === null) { + v = 0 + } + return dayjs(v); + }, + /** * 是否数组 * @param obj @@ -249,62 +273,6 @@ const localforage = require("localforage"); return _s; }, - /** - * 返回10位数时间戳 - * @param v - * @returns {number} - * @constructor - */ - Time(v = undefined) { - let time - if (typeof v === "string" && this.strExists(v, "-")) { - v = v.replace(/-/g, '/'); - time = new Date(v).getTime(); - } else { - time = new Date().getTime(); - } - return Math.round(time / 1000) - }, - - /** - * 返回毫秒时间戳 - * @param v - * @param cm 使用当前的毫秒 - * @returns {number} - * @constructor - */ - TimeM(v = undefined, cm = true) { - let time - if (typeof v === "string" && this.strExists(v, "-")) { - v = v.replace(/-/g, '/'); - time = new Date(v).getTime(); - if (cm && v.indexOf('.') === -1) { - time = parseInt(`${Math.round(time / 1000)}${new Date().getMilliseconds()}`) - } - } else { - time = new Date().getTime(); - } - return time - }, - - /** - * 返回 时间对象|时间戳 - * @param v 支持时间戳|时间格式字符串|时间对象|boolean(当前时间) - * @param timestamp 是否返回时间戳 - * @returns {Date|number} - * @constructor - */ - Date(v, timestamp = false) { - if (typeof v === "string" && this.strExists(v, "-")) { - v = v.replace(/-/g, '/'); - } - const d = typeof v === "boolean" ? new Date() : new Date(v); - if (timestamp === true) { - return Math.round(d.getTime() / 1000) - } - return d; - }, - /** * 补零 * @param str @@ -329,47 +297,6 @@ const localforage = require("localforage"); return _ret; }, - /** - * 时间戳转时间格式 - * @param format - * @param v - * @returns {string} - */ - formatDate(format, v) { - if (typeof format === 'undefined' || format === '') { - format = 'Y-m-d H:i:s'; - } - let dateObj; - if (v instanceof Date) { - dateObj = v; - }else { - if (typeof v === 'undefined') { - v = new Date().getTime(); - }else if (/^(-)?\d{1,10}$/.test(v)) { - v = v * 1000; - } else if (/^(-)?\d{1,13}$/.test(v)) { - v = v * 1000; - } else if (/^(-)?\d{1,14}$/.test(v)) { - v = v * 100; - } else if (/^(-)?\d{1,15}$/.test(v)) { - v = v * 10; - } else if (/^(-)?\d{1,16}$/.test(v)) { - v = v * 1; - } else { - return v; - } - dateObj = $A.Date(v); - } - // - format = format.replace(/Y/g, dateObj.getFullYear()); - format = format.replace(/m/g, this.zeroFill(dateObj.getMonth() + 1, 2)); - format = format.replace(/d/g, this.zeroFill(dateObj.getDate(), 2)); - format = format.replace(/H/g, this.zeroFill(dateObj.getHours(), 2)); - format = format.replace(/i/g, this.zeroFill(dateObj.getMinutes(), 2)); - format = format.replace(/s/g, this.zeroFill(dateObj.getSeconds(), 2)); - return format; - }, - /** * 租用时间差(不够1个小时算一个小时) * @param s @@ -378,7 +305,7 @@ const localforage = require("localforage"); */ timeDiff(s, e) { if (typeof e === 'undefined') { - e = $A.Time(); + e = $A.dayjs().unix(); } let d = e - s; if (d > 86400) { @@ -793,7 +720,7 @@ const localforage = require("localforage"); let url = window.location.href; let key = '_=' let reg = new RegExp(key + '\\d+'); - let timestamp = this.Time(); + let timestamp = $A.dayjs().valueOf(); if (url.indexOf(key) > -1) { url = url.replace(reg, key + timestamp); } else { @@ -1117,7 +1044,7 @@ const localforage = require("localforage"); /** * 对象中有Date格式的转成指定格式 * @param params - * @param format 默认格式:Y-m-d H:i:s + * @param format 默认格式:YYYY-MM-DD HH:mm:ss * @returns {*} */ date2string(params, format) { @@ -1125,10 +1052,12 @@ const localforage = require("localforage"); return params; } if (typeof format === "undefined") { - format = "Y-m-d H:i:s"; + format = "YYYY-MM-DD HH:mm:ss"; } - if (params instanceof Date) { - params = $A.formatDate(format, params); + if (params instanceof dayjs) { + params = params.format(format); + } else if (params instanceof Date) { + params = $A.dayjs(params).format(format); } else if ($A.isJson(params)) { params = Object.assign({}, params) for (let key in params) { @@ -1375,7 +1304,7 @@ const localforage = require("localforage"); async IDBTest() { try { if ($A.isIos()) { - await localforage.setItem('__test__', $A.Time()) + await localforage.setItem('__test__', $A.dayjs().valueOf()) } $A.openLog && console.log('IDBTest OK') } catch (error) { diff --git a/resources/assets/js/functions/web.js b/resources/assets/js/functions/web.js index 12841a323..6af2847bd 100755 --- a/resources/assets/js/functions/web.js +++ b/resources/assets/js/functions/web.js @@ -92,7 +92,7 @@ import {MarkdownPreview} from "../store/markdown"; * @returns {*} */ onlinePreviewUrl(name, key) { - return $A.mainUrl(`online/preview/${name}?key=${key}&version=${window.systemInfo.version}&__=${new Date().getTime()}`) + return $A.mainUrl(`online/preview/${name}?key=${key}&version=${window.systemInfo.version}&__=${$A.dayjs().valueOf()}`) }, /** @@ -120,18 +120,18 @@ import {MarkdownPreview} from "../store/markdown"; * @returns {*|string} */ formatTime(date) { - let now = $A.Time(), - time = $A.Date(date, true); - if ($A.formatDate('Ymd', now) === $A.formatDate('Ymd', time)) { - return $A.formatDate('H:i', time) + let now = $A.dayjs(), + time = $A.dayjs(date); + if (now.format("YYYY-MM-DD") === time.format("YYYY-MM-DD")) { + return time.format("HH:mm") } - if ($A.formatDate('Ymd', now - 86400) === $A.formatDate('Ymd', time)) { - return `${$A.L('昨天')} ${$A.formatDate('H:i', time)}` + if (now.clone().subtract(1, 'day').format('YYYY-MM-DD') === time.format("YYYY-MM-DD")) { + return `${$A.L('昨天')} ${time.format("HH:mm")}` } - if ($A.formatDate('Y', now) === $A.formatDate('Y', time)) { - return $A.formatDate('m-d', time) + if (now.year() === time.year()) { + return time.format("MM-DD") } - return $A.formatDate('Y-m-d', time) || ''; + return time.format("YYYY-MM-DD") || ''; }, /** @@ -174,7 +174,7 @@ import {MarkdownPreview} from "../store/markdown"; * @returns {string|*} */ countDownFormat(date, nowTime) { - let time = Math.round(this.Date(date).getTime() / 1000) - nowTime; + let time = $A.dayjs(date).unix() - nowTime; if (time < 86400 * 7 && time > 0 ) { return this.formatSeconds(time); } else if (time < 0) { @@ -185,439 +185,46 @@ import {MarkdownPreview} from "../store/markdown"; return this.formatTime(date) }, - /** - * 时间工具 - */ - dateRangeUtil: { - /*** - * 获得当前时间 - */ - getCurrentDate() { - return new Date(); - }, - - /*** - * 获得本周起止时间 - */ - getCurrentWeek() { - //起止日期数组 - let startStop = []; - //获取当前时间 - let currentDate = this.getCurrentDate(); - //返回date是一周中的某一天 - let week = currentDate.getDay(); - - //一天的毫秒数 - let millisecond = 1000 * 60 * 60 * 24; - //减去的天数 - let minusDay = week != 0 ? week - 1 : 6; - //alert(minusDay); - //本周 周一 - let monday = new Date(currentDate.getTime() - (minusDay * millisecond)); - //本周 周日 - let sunday = new Date(monday.getTime() + (6 * millisecond)); - //添加本周时间 - startStop.push(monday); //本周起始时间 - //添加本周最后一天时间 - startStop.push(sunday); //本周终止时间 - //返回 - return startStop; - }, - - /*** - * 获得本月的起止时间 - */ - getCurrentMonth() { - //起止日期数组 - let startStop = []; - //获取当前时间 - let currentDate = this.getCurrentDate(); - //获得当前月份0-11 - let currentMonth = currentDate.getMonth(); - //获得当前年份4位年 - let currentYear = currentDate.getFullYear(); - //求出本月第一天 - let firstDay = new Date(currentYear, currentMonth, 1); - - - //当为12月的时候年份需要加1 - //月份需要更新为0 也就是下一年的第一个月 - if (currentMonth == 11) { - currentYear++; - currentMonth = 0; //就为 - } else { - //否则只是月份增加,以便求的下一月的第一天 - currentMonth++; - } - - - //一天的毫秒数 - let millisecond = 1000 * 60 * 60 * 24; - //下月的第一天 - let nextMonthDayOne = new Date(currentYear, currentMonth, 1); - //求出上月的最后一天 - let lastDay = new Date(nextMonthDayOne.getTime() - millisecond); - - //添加至数组中返回 - startStop.push(firstDay); - startStop.push(lastDay); - //返回 - return startStop; - }, - - /** - * 得到本季度开始的月份 - * @param month 需要计算的月份 - ***/ - getQuarterSeasonStartMonth(month) { - let spring = 0; //春 - let summer = 3; //夏 - let fall = 6; //秋 - let winter = 9; //冬 - //月份从0-11 - if (month < 3) { - return spring; - } - - if (month < 6) { - return summer; - } - - if (month < 9) { - return fall; - } - - return winter; - }, - - /** - * 获得该月的天数 - * @param year 年份 - * @param month 月份 - * */ - getMonthDays(year, month) { - //本月第一天 1-31 - let relativeDate = new Date(year, month, 1); - //获得当前月份0-11 - let relativeMonth = relativeDate.getMonth(); - //获得当前年份4位年 - let relativeYear = relativeDate.getFullYear(); - - //当为12月的时候年份需要加1 - //月份需要更新为0 也就是下一年的第一个月 - if (relativeMonth == 11) { - relativeYear++; - relativeMonth = 0; - } else { - //否则只是月份增加,以便求的下一月的第一天 - relativeMonth++; - } - //一天的毫秒数 - let millisecond = 1000 * 60 * 60 * 24; - //下月的第一天 - let nextMonthDayOne = new Date(relativeYear, relativeMonth, 1); - //返回得到上月的最后一天,也就是本月总天数 - return new Date(nextMonthDayOne.getTime() - millisecond).getDate(); - }, - - /** - * 获得本季度的起止日期 - */ - getCurrentSeason() { - //起止日期数组 - let startStop = []; - //获取当前时间 - let currentDate = this.getCurrentDate(); - //获得当前月份0-11 - let currentMonth = currentDate.getMonth(); - //获得当前年份4位年 - let currentYear = currentDate.getFullYear(); - //获得本季度开始月份 - let quarterSeasonStartMonth = this.getQuarterSeasonStartMonth(currentMonth); - //获得本季度结束月份 - let quarterSeasonEndMonth = quarterSeasonStartMonth + 2; - - //获得本季度开始的日期 - let quarterSeasonStartDate = new Date(currentYear, quarterSeasonStartMonth, 1); - //获得本季度结束的日期 - let quarterSeasonEndDate = new Date(currentYear, quarterSeasonEndMonth, this.getMonthDays(currentYear, quarterSeasonEndMonth)); - //加入数组返回 - startStop.push(quarterSeasonStartDate); - startStop.push(quarterSeasonEndDate); - //返回 - return startStop; - }, - - /*** - * 得到本年的起止日期 - * - */ - getCurrentYear() { - //起止日期数组 - let startStop = []; - //获取当前时间 - let currentDate = this.getCurrentDate(); - //获得当前年份4位年 - let currentYear = currentDate.getFullYear(); - - //本年第一天 - let currentYearFirstDate = new Date(currentYear, 0, 1); - //本年最后一天 - let currentYearLastDate = new Date(currentYear, 11, 31); - //添加至数组 - startStop.push(currentYearFirstDate); - startStop.push(currentYearLastDate); - //返回 - return startStop; - }, - - /** - * 返回上一个月的第一天Date类型 - * @param year 年 - * @param month 月 - **/ - getPriorMonthFirstDay(year, month) { - //年份为0代表,是本年的第一月,所以不能减 - if (month == 0) { - month = 11; //月份为上年的最后月份 - year--; //年份减1 - return new Date(year, month, 1); - } - //否则,只减去月份 - month--; - return new Date(year, month, 1); - }, - - /** - * 获得上一月的起止日期 - * ***/ - getPreviousMonth() { - //起止日期数组 - let startStop = []; - //获取当前时间 - let currentDate = this.getCurrentDate(); - //获得当前月份0-11 - let currentMonth = currentDate.getMonth(); - //获得当前年份4位年 - let currentYear = currentDate.getFullYear(); - //获得上一个月的第一天 - let priorMonthFirstDay = this.getPriorMonthFirstDay(currentYear, currentMonth); - //获得上一月的最后一天 - let priorMonthLastDay = new Date(priorMonthFirstDay.getFullYear(), priorMonthFirstDay.getMonth(), this.getMonthDays(priorMonthFirstDay.getFullYear(), priorMonthFirstDay.getMonth())); - //添加至数组 - startStop.push(priorMonthFirstDay); - startStop.push(priorMonthLastDay); - //返回 - return startStop; - }, - - - /** - * 获得上一周的起止日期 - * **/ - getPreviousWeek() { - //起止日期数组 - let startStop = []; - //获取当前时间 - let currentDate = this.getCurrentDate(); - //返回date是一周中的某一天 - let week = currentDate.getDay(); - //一天的毫秒数 - let millisecond = 1000 * 60 * 60 * 24; - //减去的天数 - let minusDay = week != 0 ? week - 1 : 6; - //获得当前周的第一天 - let currentWeekDayOne = new Date(currentDate.getTime() - (millisecond * minusDay)); - //上周最后一天即本周开始的前一天 - let priorWeekLastDay = new Date(currentWeekDayOne.getTime() - millisecond); - //上周的第一天 - let priorWeekFirstDay = new Date(priorWeekLastDay.getTime() - (millisecond * 6)); - - //添加至数组 - startStop.push(priorWeekFirstDay); - startStop.push(priorWeekLastDay); - - return startStop; - }, - - /** - * 得到上季度的起始日期 - * year 这个年应该是运算后得到的当前本季度的年份 - * month 这个应该是运算后得到的当前季度的开始月份 - * */ - getPriorSeasonFirstDay(year, month) { - let spring = 0; //春 - let summer = 3; //夏 - let fall = 6; //秋 - let winter = 9; //冬 - //月份从0-11 - switch (month) {//季度的其实月份 - case spring: - //如果是第一季度则应该到去年的冬季 - year--; - month = winter; - break; - case summer: - month = spring; - break; - case fall: - month = summer; - break; - case winter: - month = fall; - break; - - } - - return new Date(year, month, 1); - }, - - /** - * 得到上季度的起止日期 - * **/ - getPreviousSeason() { - //起止日期数组 - let startStop = []; - //获取当前时间 - let currentDate = this.getCurrentDate(); - //获得当前月份0-11 - let currentMonth = currentDate.getMonth(); - //获得当前年份4位年 - let currentYear = currentDate.getFullYear(); - //上季度的第一天 - let priorSeasonFirstDay = this.getPriorSeasonFirstDay(currentYear, currentMonth); - //上季度的最后一天 - let priorSeasonLastDay = new Date(priorSeasonFirstDay.getFullYear(), priorSeasonFirstDay.getMonth() + 2, this.getMonthDays(priorSeasonFirstDay.getFullYear(), priorSeasonFirstDay.getMonth() + 2)); - //添加至数组 - startStop.push(priorSeasonFirstDay); - startStop.push(priorSeasonLastDay); - return startStop; - }, - - /** - * 得到去年的起止日期 - * **/ - getPreviousYear() { - //起止日期数组 - let startStop = []; - //获取当前时间 - let currentDate = this.getCurrentDate(); - //获得当前年份4位年 - let currentYear = currentDate.getFullYear(); - currentYear--; - let priorYearFirstDay = new Date(currentYear, 0, 1); - let priorYearLastDay = new Date(currentYear, 11, 1); - //添加至数组 - startStop.push(priorYearFirstDay); - startStop.push(priorYearLastDay); - return startStop; - } - }, - - /** - * 获取一些指定时间 - * @param str - * @param retDate - * @returns {*|string} - */ - getSpecifyDate(str, retDate = false) { - let time = new Date().getTime(); - switch (str) { - case '昨天': - time -= 86400 * 1000; - break; - case '前天': - time -= 86400 * 2000; - break; - case '本周': - time = $A.dateRangeUtil.getCurrentWeek()[0].getTime(); - break; - case '本周结束': - time = $A.dateRangeUtil.getCurrentWeek()[1].getTime(); - break; - case '上周': - time = $A.dateRangeUtil.getPreviousWeek()[0].getTime(); - break; - case '上周结束': - time = $A.dateRangeUtil.getPreviousWeek()[1].getTime(); - break; - case '本月': - time = $A.dateRangeUtil.getCurrentMonth()[0].getTime(); - break; - case '本月结束': - time = $A.dateRangeUtil.getCurrentMonth()[1].getTime(); - break; - case '上个月': - time = $A.dateRangeUtil.getPreviousMonth()[0].getTime(); - break; - case '上个月结束': - time = $A.dateRangeUtil.getPreviousMonth()[1].getTime(); - break; - case '本季度': - time = $A.dateRangeUtil.getCurrentSeason()[0].getTime(); - break; - case '本季度结束': - time = $A.dateRangeUtil.getCurrentSeason()[1].getTime(); - break; - } - time = $A.formatDate("Y-m-d", Math.floor(time / 1000)) - if (retDate === true) { - return new Date(time); - } - return time - }, - /** * 获取日期选择器的 shortcuts 模板参数 * @returns {(*)[]|[{text, value(): [Date,*]},{text, value(): [Date,*]},{text, value(): [*,*]},{text, value(): [*,*]},{text, value(): [Date,*]},null,null]|(Date|*)[]} */ timeOptionShortcuts() { - const startSecond = $A.Date($A.formatDate("Y-m-d 00:00:00", Math.round(new Date().getTime() / 1000))); - const lastSecond = (e) => { - return $A.Date($A.formatDate("Y-m-d 00:00:00", Math.round(e / 1000))) - }; + const startSecond = $A.dayjs().startOf('day').toDate(); return [{ text: $A.L('今天'), value() { - return [startSecond, lastSecond(new Date().getTime())]; + return [startSecond, $A.dayjs().endOf('day').toDate()]; } }, { text: $A.L('明天'), value() { - let e = new Date(); - e.setDate(e.getDate() + 1); - return [startSecond, lastSecond(e.getTime())]; + return [startSecond, $A.dayjs().add(1, 'day').endOf('day').toDate()]; } }, { text: $A.L('本周'), value() { - return [startSecond, lastSecond($A.getSpecifyDate('本周结束', true).getTime())]; + return [startSecond, $A.dayjs().endOf('week').toDate()]; } }, { text: $A.L('本月'), value() { - return [startSecond, lastSecond($A.getSpecifyDate('本月结束', true).getTime())]; + return [startSecond, $A.dayjs().endOf('month').toDate()]; } }, { text: $A.L('3天'), value() { - let e = new Date(); - e.setDate(e.getDate() + 2); - return [startSecond, lastSecond(e.getTime())]; + return [startSecond, $A.dayjs().add(2, 'day').endOf('day').toDate()]; } }, { text: $A.L('5天'), value() { - let e = new Date(); - e.setDate(e.getDate() + 4); - return [startSecond, lastSecond(e.getTime())]; + return [startSecond, $A.dayjs().add(4, 'day').endOf('day').toDate()]; } }, { text: $A.L('7天'), value() { - let e = new Date(); - e.setDate(e.getDate() + 6); - return [startSecond, lastSecond(e.getTime())]; + return [startSecond, $A.dayjs().add(6, 'day').endOf('day').toDate()]; } }]; }, diff --git a/resources/assets/js/language/utils.js b/resources/assets/js/language/utils.js index d7df84a93..b4d0d3f0a 100644 --- a/resources/assets/js/language/utils.js +++ b/resources/assets/js/language/utils.js @@ -8,10 +8,10 @@ export default { "en": "English", "ko": "한국어", "ja": "日本語", - "ru": "俄语", "de": "Deutsch", "fr": "Français", "id": "Indonesia", + "ru": "Русский язык", }, /** diff --git a/resources/assets/js/pages/manage.vue b/resources/assets/js/pages/manage.vue index c60cdd1aa..a7a00498c 100644 --- a/resources/assets/js/pages/manage.vue +++ b/resources/assets/js/pages/manage.vue @@ -660,7 +660,7 @@ export default { const {projectKeyValue, cacheProjects} = this; const data = $A.cloneJSON(cacheProjects).sort((a, b) => { if (a.top_at || b.top_at) { - return $A.Date(b.top_at) - $A.Date(a.top_at); + return $A.dayjs(b.top_at) - $A.dayjs(a.top_at); } return b.id - a.id; }); diff --git a/resources/assets/js/pages/manage/approve/details.vue b/resources/assets/js/pages/manage/approve/details.vue index c4cef6b7b..01cf561ff 100644 --- a/resources/assets/js/pages/manage/approve/details.vue +++ b/resources/assets/js/pages/manage/approve/details.vue @@ -281,8 +281,7 @@ export default { }, // 把时间转成几小时前 getTimeAgo(time, type) { - const currentTime = new Date(); - const timeDiff = (currentTime - new Date((time + '').replace(/-/g, "/"))) / 1000; // convert to seconds + const timeDiff = $A.dayjs().unix() - $A.dayjs(time).unix(); // convert to seconds if (timeDiff < 60) { return type == 2 ? "0" + this.$L('分钟') : this.$L('刚刚'); } else if (timeDiff < 3600) { @@ -301,23 +300,23 @@ export default { }, // 时间转为周几 getWeekday(dateString) { - return ['周日', '周一', '周二', '周三', '周四', '周五', '周六'][new Date(dateString).getDay()]; + return ['周日', '周一', '周二', '周三', '周四', '周五', '周六'][$A.dayjs(dateString).day()]; }, // 获取时间差 getTimeDifference(startTime, endTime) { - const currentTime = new Date((endTime + '').replace(/-/g, "/")); - const endTimes = new Date((startTime + '').replace(/-/g, "/")); - const timeDiff = (currentTime - endTimes) / 1000; // convert to seconds + const currentTime = $A.dayjs(endTime); + const endTimes = $A.dayjs(startTime); + const timeDiff = currentTime.unix() - endTimes.unix(); // convert to seconds if (timeDiff < 60) { return {time: timeDiff, unit: this.$L('秒')}; } else if (timeDiff < 3600) { const minutes = Math.floor(timeDiff / 60); return {time: minutes, unit: this.$L('分钟')}; } else if (timeDiff < 3600 * 24) { - const hours = (currentTime - endTimes) / (1000 * 60 * 60); + const hours = Math.floor(timeDiff / 60 / 60); return {time: hours, unit: this.$L('小时')}; } else { - const days = Math.floor(timeDiff / 3600 / 24); + const days = Math.floor(timeDiff / 60 / 60 / 24); return {time: days + 1, unit: this.$L('天')}; } }, diff --git a/resources/assets/js/pages/manage/approve/index.vue b/resources/assets/js/pages/manage/approve/index.vue index bc43603bc..3ae11cef7 100644 --- a/resources/assets/js/pages/manage/approve/index.vue +++ b/resources/assets/js/pages/manage/approve/index.vue @@ -262,10 +262,6 @@ export default { isShowIcon: false, modalTransferIndex: window.modalTransferIndex, - minDate: new Date(2020, 0, 1), - maxDate: new Date(2025, 10, 1), - currentDate: new Date(2021, 0, 17), - procdefList: [], page: 1, pageSize: 10, @@ -408,7 +404,7 @@ export default { this.getUnreadList(); } this.addData.department_id = this.userInfo.department[0] || 0; - this.addData.startTime = this.addData.endTime = this.getCurrentDate(); + this.addData.startTime = this.addData.endTime = $A.dayjs().format('YYYY-MM-DD'); this.isShowIcon = this.windowWidth < 515 }, @@ -432,15 +428,6 @@ export default { }); }, - // 获取当前时间 - getCurrentDate() { - const today = new Date(); - const year = today.getFullYear(); - const month = String(today.getMonth() + 1).padStart(2, '0'); - const date = String(today.getDate()).padStart(2, '0'); - return `${year}-${month}-${date}`; - }, - // tab切换事件 tabsClick(val, time = 1000) { if (!val && this.__tabsClick && time > 0) { diff --git a/resources/assets/js/pages/manage/calendar.vue b/resources/assets/js/pages/manage/calendar.vue index 005a5a326..94f6c657e 100644 --- a/resources/assets/js/pages/manage/calendar.vue +++ b/resources/assets/js/pages/manage/calendar.vue @@ -46,7 +46,6 @@