From 319dfc2de3db01f11ccdda006e8555a5f06a6e1b Mon Sep 17 00:00:00 2001 From: RuoYi Date: Wed, 9 Oct 2019 17:21:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=87=BD=E6=95=B0=E5=91=BD?= =?UTF-8?q?=E5=90=8D=E9=98=B2=E6=AD=A2=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-ui/src/main.js | 4 +- ruoyi-ui/src/utils/ruoyi.js | 62 +++++++++++-------- .../src/views/monitor/logininfor/index.vue | 2 +- ruoyi-ui/src/views/monitor/operlog/index.vue | 4 +- ruoyi-ui/src/views/system/config/index.vue | 2 +- ruoyi-ui/src/views/system/dept/index.vue | 2 +- ruoyi-ui/src/views/system/dict/data.vue | 2 +- ruoyi-ui/src/views/system/dict/index.vue | 2 +- ruoyi-ui/src/views/system/menu/index.vue | 2 +- ruoyi-ui/src/views/system/notice/index.vue | 2 +- ruoyi-ui/src/views/system/post/index.vue | 2 +- ruoyi-ui/src/views/system/role/index.vue | 2 +- ruoyi-ui/src/views/system/user/index.vue | 2 +- 13 files changed, 51 insertions(+), 39 deletions(-) diff --git a/ruoyi-ui/src/main.js b/ruoyi-ui/src/main.js index c0056eebd..2b5419d26 100644 --- a/ruoyi-ui/src/main.js +++ b/ruoyi-ui/src/main.js @@ -18,13 +18,13 @@ import './assets/icons' // icon import './permission' // permission control import { getDicts } from "@/api/system/dict/data"; import { getConfigKey } from "@/api/system/config"; -import { dateFormat, resetForm, addDateRange, selectDictLabel } from "@/utils/ruoyi"; +import { parseTime, resetForm, addDateRange, selectDictLabel } from "@/utils/ruoyi"; import Pagination from "@/components/Pagination"; // 全局方法挂载 Vue.prototype.getDicts = getDicts Vue.prototype.getConfigKey = getConfigKey -Vue.prototype.dateFormat = dateFormat +Vue.prototype.parseTime = parseTime Vue.prototype.resetForm = resetForm Vue.prototype.addDateRange = addDateRange Vue.prototype.selectDictLabel = selectDictLabel diff --git a/ruoyi-ui/src/utils/ruoyi.js b/ruoyi-ui/src/utils/ruoyi.js index acef7f9d8..6442ce23a 100644 --- a/ruoyi-ui/src/utils/ruoyi.js +++ b/ruoyi-ui/src/utils/ruoyi.js @@ -4,12 +4,42 @@ */ // 日期格式化 -export function dateFormat(date, pattern) { - var d = new Date(date).Format("yyyy-MM-dd hh:mm:ss"); - if (pattern) { - d = new Date(date).Format(pattern); - } - return d.toLocaleString(); +export function parseTime(time, pattern) { + if (arguments.length === 0) { + return null + } + const format = pattern || '{y}-{m}-{d} {h}:{i}:{s}' + let date + if (typeof time === 'object') { + date = time + } else { + if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) { + time = parseInt(time) + } + if ((typeof time === 'number') && (time.toString().length === 10)) { + time = time * 1000 + } + date = new Date(time) + } + const formatObj = { + y: date.getFullYear(), + m: date.getMonth() + 1, + d: date.getDate(), + h: date.getHours(), + i: date.getMinutes(), + s: date.getSeconds(), + a: date.getDay() + } + const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => { + let value = formatObj[key] + // Note: getDay() returns 0 on Sunday + if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value ] } + if (result.length > 0 && value < 10) { + value = '0' + value + } + return value || 0 + }) + return time_str } // 表单重置 @@ -55,22 +85,4 @@ export function sprintf(str) { return arg; }); return flag ? str : ''; -} - -Date.prototype.Format = function (fmt) { - var o = { - "M+": this.getMonth() + 1, // 月份 - "d+": this.getDate(), // 日 - "h+": this.getHours(), // 小时 - "m+": this.getMinutes(), // 分 - "s+": this.getSeconds(), // 秒 - "q+": Math.floor((this.getMonth() + 3) / 3), // 季度 - "S": this.getMilliseconds() // 毫秒 - }; - if (/(y+)/.test(fmt)) - fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); - for (var k in o) - if (new RegExp("(" + k + ")").test(fmt)) - fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); - return fmt; -} \ No newline at end of file +} \ No newline at end of file diff --git a/ruoyi-ui/src/views/monitor/logininfor/index.vue b/ruoyi-ui/src/views/monitor/logininfor/index.vue index 7bc42aabe..1e3811e12 100644 --- a/ruoyi-ui/src/views/monitor/logininfor/index.vue +++ b/ruoyi-ui/src/views/monitor/logininfor/index.vue @@ -65,7 +65,7 @@ diff --git a/ruoyi-ui/src/views/monitor/operlog/index.vue b/ruoyi-ui/src/views/monitor/operlog/index.vue index b7d4f991e..9ea7f77ec 100644 --- a/ruoyi-ui/src/views/monitor/operlog/index.vue +++ b/ruoyi-ui/src/views/monitor/operlog/index.vue @@ -81,7 +81,7 @@ @@ -135,7 +135,7 @@ - {{ dateFormat(form.operTime) }} + {{ parseTime(form.operTime) }} {{ form.errorMsg }} diff --git a/ruoyi-ui/src/views/system/config/index.vue b/ruoyi-ui/src/views/system/config/index.vue index 5e0046d19..957bb833f 100644 --- a/ruoyi-ui/src/views/system/config/index.vue +++ b/ruoyi-ui/src/views/system/config/index.vue @@ -58,7 +58,7 @@ diff --git a/ruoyi-ui/src/views/system/dept/index.vue b/ruoyi-ui/src/views/system/dept/index.vue index c5bb19746..735c3b9b3 100644 --- a/ruoyi-ui/src/views/system/dept/index.vue +++ b/ruoyi-ui/src/views/system/dept/index.vue @@ -51,7 +51,7 @@ diff --git a/ruoyi-ui/src/views/system/dict/data.vue b/ruoyi-ui/src/views/system/dict/data.vue index fe1b12d25..8c4db3f3e 100644 --- a/ruoyi-ui/src/views/system/dict/data.vue +++ b/ruoyi-ui/src/views/system/dict/data.vue @@ -45,7 +45,7 @@ diff --git a/ruoyi-ui/src/views/system/dict/index.vue b/ruoyi-ui/src/views/system/dict/index.vue index f9e5d17de..86de17bed 100644 --- a/ruoyi-ui/src/views/system/dict/index.vue +++ b/ruoyi-ui/src/views/system/dict/index.vue @@ -69,7 +69,7 @@ diff --git a/ruoyi-ui/src/views/system/menu/index.vue b/ruoyi-ui/src/views/system/menu/index.vue index 090a2325a..440cdc30b 100644 --- a/ruoyi-ui/src/views/system/menu/index.vue +++ b/ruoyi-ui/src/views/system/menu/index.vue @@ -44,7 +44,7 @@ diff --git a/ruoyi-ui/src/views/system/notice/index.vue b/ruoyi-ui/src/views/system/notice/index.vue index 6aa32bd6c..f65e8eabb 100644 --- a/ruoyi-ui/src/views/system/notice/index.vue +++ b/ruoyi-ui/src/views/system/notice/index.vue @@ -60,7 +60,7 @@ diff --git a/ruoyi-ui/src/views/system/post/index.vue b/ruoyi-ui/src/views/system/post/index.vue index b1f0c9fbf..f380b2390 100644 --- a/ruoyi-ui/src/views/system/post/index.vue +++ b/ruoyi-ui/src/views/system/post/index.vue @@ -43,7 +43,7 @@ diff --git a/ruoyi-ui/src/views/system/role/index.vue b/ruoyi-ui/src/views/system/role/index.vue index 332dc8f54..7f0feb96b 100644 --- a/ruoyi-ui/src/views/system/role/index.vue +++ b/ruoyi-ui/src/views/system/role/index.vue @@ -78,7 +78,7 @@ diff --git a/ruoyi-ui/src/views/system/user/index.vue b/ruoyi-ui/src/views/system/user/index.vue index 295f9c78a..2d57670fd 100644 --- a/ruoyi-ui/src/views/system/user/index.vue +++ b/ruoyi-ui/src/views/system/user/index.vue @@ -100,7 +100,7 @@