From b4d443f4869b8ca0ae7da893c3a4bf7dde38b0fa Mon Sep 17 00:00:00 2001 From: Mengxiong10 <15623530292@163.com> Date: Sun, 7 May 2017 22:29:29 +0800 Subject: [PATCH] init --- .gitignore | 5 + calendar-panel.vue | 243 +++++++++++++++++++++++++++++++++++++++ index.vue | 278 +++++++++++++++++++++++++++++++++++++++++++++ package.json | 15 +++ utils.js | 22 ++++ 5 files changed, 563 insertions(+) create mode 100644 .gitignore create mode 100644 calendar-panel.vue create mode 100644 index.vue create mode 100644 package.json create mode 100644 utils.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c369a4d --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.DS_Store +node_modules/ +dist/ +npm-debug.log +yarn-error.log diff --git a/calendar-panel.vue b/calendar-panel.vue new file mode 100644 index 0000000..c5b433c --- /dev/null +++ b/calendar-panel.vue @@ -0,0 +1,243 @@ + + + + + + diff --git a/index.vue b/index.vue new file mode 100644 index 0000000..1d8b308 --- /dev/null +++ b/index.vue @@ -0,0 +1,278 @@ + + + + + + diff --git a/package.json b/package.json new file mode 100644 index 0000000..3529ead --- /dev/null +++ b/package.json @@ -0,0 +1,15 @@ +{ + "name": "vue2-datepicker", + "version": "1.0.0", + "description": "datepicker for Vue2", + "main": "index.vue", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [ + "vue", + "datepicker" + ], + "author": "xmx", + "license": "MIT" +} diff --git a/utils.js b/utils.js new file mode 100644 index 0000000..c39185e --- /dev/null +++ b/utils.js @@ -0,0 +1,22 @@ +export function formatDate(date, fmt = 'YYYY-MM-DD hh:mm:ss') { + date = date instanceof Date ? date : new Date(date) + const map = { + 'M+': date.getMonth() + 1, // 月份 + '[Dd]+': date.getDate(), // 日 + '[Hh]+': date.getHours(), // 小时 + 'm+': date.getMinutes(), // 分 + 's+': date.getSeconds(), // 秒 + 'q+': Math.floor((date.getMonth() + 3) / 3), // 季度 + 'S': date.getMilliseconds(), // 毫秒 + } + fmt = fmt.replace(/[Yy]+/g, function (str) { + return ('' + date.getFullYear()).slice(4 - str.length) + }) + Object.keys(map).forEach((key) => { + fmt = fmt.replace(new RegExp(key), function (str) { + const value = '' + map[key] + return str.length === 1 ? value : ('00' + value).slice(value.length) + }) + }) + return fmt +} \ No newline at end of file