From a2049cefe6558f905ae36fb140413fd23bae3d59 Mon Sep 17 00:00:00 2001 From: leave <> Date: Thu, 22 Oct 2020 14:40:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E8=B5=B7=E8=80=83=E6=A0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.js | 9 +- src/utils/dateFormat.js | 27 ++++ .../workbench/initiateAssessment/index.vue | 140 +++++++++++++----- 3 files changed, 141 insertions(+), 35 deletions(-) create mode 100644 src/utils/dateFormat.js diff --git a/src/main.js b/src/main.js index 33f8cfa..4b0d1d7 100644 --- a/src/main.js +++ b/src/main.js @@ -8,13 +8,20 @@ import './utils/elementConfig' import './utils/permission' import './style/index.less' import '@/icons' +import { + format +} from '@/utils/dateFormat' + console.log('store: ', store) Vue.config.productionTip = false +Vue.prototype.$format = format /* eslint-disable no-new */ new Vue({ el: '#app', router, store, - components: { App }, + components: { + App + }, template: '' }) diff --git a/src/utils/dateFormat.js b/src/utils/dateFormat.js new file mode 100644 index 0000000..9704a2a --- /dev/null +++ b/src/utils/dateFormat.js @@ -0,0 +1,27 @@ +// 日期格式化 + +export const format = (now, fmt = 'yyyy-MM-dd') => { + if (typeof now === 'string') { + now = now.replace(/-/g, '/') + } + now = new Date(now) + const o = { + 'M+': now.getMonth() + 1, // 月份 + 'd+': now.getDate(), // 日 + 'h+': now.getHours(), // 小时 + 'H+': now.getHours(), // 小时 + 'm+': now.getMinutes(), // 分 + 's+': now.getSeconds(), // 秒 + 'q+': Math.floor((now.getMonth() + 3) / 3), // 季度 + 'S': now.getMilliseconds() // 毫秒 + } + if (/(y+)/.test(fmt)) { + fmt = fmt.replace(RegExp.$1, (now.getFullYear() + '').substr(4 - RegExp.$1.length)) + } + for (let k in o) { + if (new RegExp('(' + k + ')').test(fmt)) { + fmt = fmt.replace(RegExp.$1, String(o[k]).padStart(RegExp.$1.length, 0)) + } + } + return fmt +} diff --git a/src/views/kpi/workbench/initiateAssessment/index.vue b/src/views/kpi/workbench/initiateAssessment/index.vue index e858f56..c87242a 100644 --- a/src/views/kpi/workbench/initiateAssessment/index.vue +++ b/src/views/kpi/workbench/initiateAssessment/index.vue @@ -1,36 +1,96 @@