diff --git a/app/Http/Controllers/Api/SystemController.php b/app/Http/Controllers/Api/SystemController.php index c078c7149..e4f0a8c2a 100755 --- a/app/Http/Controllers/Api/SystemController.php +++ b/app/Http/Controllers/Api/SystemController.php @@ -133,6 +133,7 @@ class SystemController extends AbstractController $setting['file_upload_limit'] = $setting['file_upload_limit'] ?: ''; $setting['unclaimed_task_reminder'] = $setting['unclaimed_task_reminder'] ?: 'close'; $setting['unclaimed_task_reminder_time'] = $setting['unclaimed_task_reminder_time'] ?: ''; + $setting['server_timezone'] = config('app.timezone'); $setting['server_version'] = Base::getVersion(); // return Base::retSuccess('success', $setting ?: json_decode('{}')); diff --git a/resources/assets/js/functions/common.js b/resources/assets/js/functions/common.js index ef4d80085..717832327 100755 --- a/resources/assets/js/functions/common.js +++ b/resources/assets/js/functions/common.js @@ -11,33 +11,12 @@ const timezone = require("dayjs/plugin/timezone"); 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 @@ -280,51 +259,11 @@ const timezone = require("dayjs/plugin/timezone"); * @param after * @returns {*} */ - zeroFill(str, length, after) { - str+= ""; - if (str.length >= length) { - return str; - } - let _str = '', _ret = ''; - for (let i = 0; i < length; i++) { - _str += '0'; - } - if (after || typeof after === 'undefined') { - _ret = (_str + "" + str).substr(length * -1); - } else { - _ret = (str + "" + _str).substr(0, length); - } - return _ret; - }, - - /** - * 租用时间差(不够1个小时算一个小时) - * @param s - * @param e - * @returns {*} - */ - timeDiff(s, e) { - if (typeof e === 'undefined') { - e = $A.dayjs().unix(); - } - let d = e - s; - if (d > 86400) { - let day = Math.floor(d / 86400); - let hour = Math.ceil((d - (day * 86400)) / 3600); - if (hour > 0) { - return day + '天' + hour + '小时'; - } else { - return day + '天'; - } - } else if (d > 3600) { - return Math.ceil(d / 3600) + '小时'; - } else if (d > 60) { - return Math.ceil(d / 60) + '分钟'; - } else if (d > 10) { - return d + '秒'; - } else { - return '刚刚'; + zeroFill(str, length, after = false) { + if (after) { + return `${str}`.padEnd(length, '0') } + return `${str}`.padStart(length, '0') }, /** @@ -1041,69 +980,6 @@ const timezone = require("dayjs/plugin/timezone"); }, __loadIframe: {}, - /** - * 对象中有Date格式的转成指定格式 - * @param value - * @param format 默认格式:YYYY-MM-DD HH:mm:ss - * @returns {*} - */ - newDateString(value, format = "YYYY-MM-DD HH:mm:ss") { - if (value === null) { - return value; - } - if (value instanceof dayjs || value instanceof Date) { - value = $A.dayjs(value).format(format); - } else if ($A.isJson(value)) { - value = Object.assign({}, value) - for (let key in value) { - if (!value.hasOwnProperty(key)) continue; - value[key] = $A.newDateString(value[key], format); - } - } else if ($A.isArray(value)) { - value = Object.assign([], value) - value.forEach((val, index) => { - value[index] = $A.newDateString(val, format); - }); - } - return value; - }, - - /** - * 对象中有Date格式的转成时间戳 - * @param value - * @returns {number|*} - */ - newTimestamp(value) { - if (value === null) { - return value; - } - if (value instanceof dayjs || value instanceof Date || $A.isDateString(value)) { - value = $A.dayjs(value).unix(); - } else if ($A.isJson(value)) { - value = Object.assign({}, value) - for (let key in value) { - if (!value.hasOwnProperty(key)) continue; - value[key] = $A.newTimestamp(value[key]); - } - } else if ($A.isArray(value)) { - value = Object.assign([], value) - value.forEach((val, index) => { - value[index] = $A.newTimestamp(val); - }); - } - return value; - }, - - /** - * 判断是否是日期格式 - * 支持格式:YYYY-MM-DD HH:mm:ss、YYYY-MM-DD HH:mm、YYYY-MM-DD HH、YYYY-MM-DD - * @param value - * @returns {boolean} - */ - isDateString(value) { - return typeof value === "string" && /^\d{4}-\d{2}-\d{2}( \d{2}(:\d{2}(:\d{2})?)?)?$/i.test(value); - }, - /** * 字节转换 * @param bytes @@ -1984,5 +1860,174 @@ const timezone = require("dayjs/plugin/timezone"); __ajaxList: [], }); + /** + * ============================================================================= + * *********************************** time ******************************** + * ============================================================================= + */ + + dayjs.extend(utc); + dayjs.extend(timezone); + $.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 tz + */ + setTimezone(tz) { + const local = $A.dayjs().startOf('hour'); + const server = local.tz(tz); + $A.timezoneDifference = local.startOf('hour').diff(server.format("YYYY-MM-DD HH:mm:ss"), 'hour') + }, + timezoneDifference: 0, + + /** + * 对象中有Date格式的转成指定格式 + * @param value + * @param format 默认格式:YYYY-MM-DD HH:mm:ss + * @returns {*} + */ + newDateString(value, format = "YYYY-MM-DD HH:mm:ss") { + if (value === null) { + return value; + } + if (value instanceof dayjs || value instanceof Date) { + value = $A.dayjs(value).format(format); + } else if ($A.isJson(value)) { + value = Object.assign({}, value) + for (let key in value) { + if (!value.hasOwnProperty(key)) continue; + value[key] = $A.newDateString(value[key], format); + } + } else if ($A.isArray(value)) { + value = Object.assign([], value) + value.forEach((val, index) => { + value[index] = $A.newDateString(val, format); + }); + } + return value; + }, + + /** + * 对象中有Date格式的转成时间戳 + * @param value + * @returns {number|*} + */ + newTimestamp(value) { + if (value === null) { + return value; + } + if (value instanceof dayjs || value instanceof Date || $A.isDateString(value)) { + value = $A.dayjs(value).unix(); + } else if ($A.isJson(value)) { + value = Object.assign({}, value) + for (let key in value) { + if (!value.hasOwnProperty(key)) continue; + value[key] = $A.newTimestamp(value[key]); + } + } else if ($A.isArray(value)) { + value = Object.assign([], value) + value.forEach((val, index) => { + value[index] = $A.newTimestamp(val); + }); + } + return value; + }, + + /** + * 判断是否是日期格式 + * 支持格式:YYYY-MM-DD HH:mm:ss、YYYY-MM-DD HH:mm、YYYY-MM-DD HH、YYYY-MM-DD + * @param value + * @returns {boolean} + */ + isDateString(value) { + return typeof value === "string" && /^\d{4}-\d{2}-\d{2}( \d{2}(:\d{2}(:\d{2})?)?)?$/i.test(value); + }, + + /** + * 秒数倒计时,格式:00:00:00, 00:00, 0s + * @param s + * @returns {string} + */ + secondsToTime(s) { + let pre = ''; + if (s < 0) { + pre = '-'; + s = -s; + } + let duration + const days = Math.floor(s / 86400); + const hours = Math.floor((s % 86400) / 3600); + const minutes = Math.floor(((s % 86400) % 3600) / 60); + const seconds = Math.floor(((s % 86400) % 3600) % 60); + if (days > 0) { + if (hours > 0) duration = days + "d," + $A.zeroFill(hours, 2) + "h"; + else if (minutes > 0) duration = days + "d," + $A.zeroFill(minutes, 2) + "min"; + else if (seconds > 0) duration = days + "d," + $A.zeroFill(seconds, 2) + "s"; + else duration = days + "d"; + } + else if (hours > 0) duration = $A.zeroFill(hours, 2) + ":" + $A.zeroFill(minutes, 2) + ":" + $A.zeroFill(seconds, 2); + else if (minutes > 0) duration = $A.zeroFill(minutes, 2) + ":" + $A.zeroFill(seconds, 2); + else if (seconds > 0) duration = $A.zeroFill(seconds, 2) + "s"; + return pre + duration; + }, + + /** + * 格式化时间(本地时间自动减去时区差) + * @param date + * @returns {string} + */ + timeFormat(date) { + const local = $A.dayjs().subtract($A.timezoneDifference, "hour"), + time = $A.dayjs(date); + if (local.format("YYYY-MM-DD") === time.format("YYYY-MM-DD")) { + return time.format("HH:mm") + } + if (local.clone().subtract(1, 'day').format('YYYY-MM-DD') === time.format("YYYY-MM-DD")) { + return `${$A.L('昨天')} ${time.format("HH:mm")}` + } + if (local.year() === time.year()) { + return time.format("MM-DD") + } + return time.format("YYYY-MM-DD") || ''; + }, + + /** + * 倒计时 + * @param s 开始时间自动减去时区差 + * @param e + * @returns {string} + */ + countDownFormat(s, e) { + s = $A.dayjs(s).subtract($A.timezoneDifference, "hour") + e = $A.dayjs(e) + const diff = e.diff(s, 'second'); + if (diff == 0) { + return '0s'; + } + if (Math.abs(diff) < 86400 * 7) { + return $A.secondsToTime(diff); + } + return $A.timeFormat(e) + }, + }); + window.$A = $; })(window, window.$ = window.jQuery = require('jquery')); diff --git a/resources/assets/js/functions/web.js b/resources/assets/js/functions/web.js index 6af2847bd..dd44157b8 100755 --- a/resources/assets/js/functions/web.js +++ b/resources/assets/js/functions/web.js @@ -114,77 +114,6 @@ import {MarkdownPreview} from "../store/markdown"; } }, - /** - * 格式化时间 - * @param date - * @returns {*|string} - */ - formatTime(date) { - 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 (now.clone().subtract(1, 'day').format('YYYY-MM-DD') === time.format("YYYY-MM-DD")) { - return `${$A.L('昨天')} ${time.format("HH:mm")}` - } - if (now.year() === time.year()) { - return time.format("MM-DD") - } - return time.format("YYYY-MM-DD") || ''; - }, - - /** - * 小于9补0 - * @param val - * @returns {number|string} - */ - formatBit(val) { - val = +val - return val > 9 ? val : '0' + val - }, - - /** - * 秒转时间 - * @param second - * @returns {string} - */ - formatSeconds(second) { - let duration - let days = Math.floor(second / 86400); - let hours = Math.floor((second % 86400) / 3600); - let minutes = Math.floor(((second % 86400) % 3600) / 60); - let seconds = Math.floor(((second % 86400) % 3600) % 60); - if (days > 0) { - if (hours > 0) duration = days + "d," + this.formatBit(hours) + "h"; - else if (minutes > 0) duration = days + "d," + this.formatBit(minutes) + "min"; - else if (seconds > 0) duration = days + "d," + this.formatBit(seconds) + "s"; - else duration = days + "d"; - } - else if (hours > 0) duration = this.formatBit(hours) + ":" + this.formatBit(minutes) + ":" + this.formatBit(seconds); - else if (minutes > 0) duration = this.formatBit(minutes) + ":" + this.formatBit(seconds); - else if (seconds > 0) duration = this.formatBit(seconds) + "s"; - return duration; - }, - - /** - * 倒计时格式 - * @param date - * @param nowTime - * @returns {string|*} - */ - countDownFormat(date, nowTime) { - let time = $A.dayjs(date).unix() - nowTime; - if (time < 86400 * 7 && time > 0 ) { - return this.formatSeconds(time); - } else if (time < 0) { - return '-' + this.formatSeconds(time * -1); - } else if (time == 0) { - return 0 + 's'; - } - return this.formatTime(date) - }, - /** * 获取日期选择器的 shortcuts 模板参数 * @returns {(*)[]|[{text, value(): [Date,*]},{text, value(): [Date,*]},{text, value(): [*,*]},{text, value(): [*,*]},{text, value(): [Date,*]},null,null]|(Date|*)[]} diff --git a/resources/assets/js/pages/manage/components/DialogView.vue b/resources/assets/js/pages/manage/components/DialogView.vue index 2302678d7..ef9b8913c 100644 --- a/resources/assets/js/pages/manage/components/DialogView.vue +++ b/resources/assets/js/pages/manage/components/DialogView.vue @@ -248,7 +248,7 @@