From b2222d128ead3d657175e7ee8acebe0ba25b847d Mon Sep 17 00:00:00 2001
From: mxie <15623530290@163.com>
Date: Tue, 15 Aug 2017 23:48:41 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0shortcuts=20=E8=87=AA?=
=?UTF-8?q?=E5=AE=9A=E4=B9=89?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.gitignore | 1 +
README.md | 22 +++++++++++++++++-
datepicker/index.vue | 55 +++++++++++++++++++++++++-------------------
3 files changed, 53 insertions(+), 25 deletions(-)
diff --git a/.gitignore b/.gitignore
index 219fb81..0d09221 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@
node_modules/
npm-debug.log
yarn-error.log
+package-lock.json
diff --git a/README.md b/README.md
index 78d14c4..5bbace7 100644
--- a/README.md
+++ b/README.md
@@ -25,6 +25,13 @@ export default {
return {
time1: '',
time2: '',
+ shortcuts: [
+ {
+ text: 'Today',
+ start: new Date(),
+ end: new Date()
+ }
+ ]
}
}
}
@@ -33,7 +40,7 @@ export default {
-
+
```
@@ -50,5 +57,18 @@ export default {
| showYearNav | Boolean | true | Show the year nav in the calendar |
| notBefore | String | '' | Disable all dates before date in YYY-MM-DD format |
| notAfter | String | '' | Disable all dates after date in YYY-MM-DD format |
+| shortcuts | Boolean/Array | true | the shortcuts for the range picker |
+
+## shortcuts
+* true - show the default shortcuts
+* false - hide the shortcuts
+* Object[] - custom shortcuts, [{text, start, end}]
+
+| Prop | Type | Description |
+|-----------------|---------------|------------------------|
+| text | String | Text |
+| start | Date | Start Date |
+| end | Date | End Date |
+
diff --git a/datepicker/index.vue b/datepicker/index.vue
index 231cf60..4f6cfda 100644
--- a/datepicker/index.vue
+++ b/datepicker/index.vue
@@ -29,7 +29,7 @@
:notAfter="notAfter">
-
+
{{range.text}}
{
- v.text = this.translation.pickers[i]
- })
+ if (Array.isArray(this.shortcuts)) {
+ this.ranges = this.shortcuts
+ } else if (this.shortcuts) {
+ this.ranges = [{
+ text: '未来7天',
+ start: new Date(),
+ end: new Date(Date.now() + 3600 * 1000 * 24 * 7)
+ }, {
+ text: '未来30天',
+ start: new Date(),
+ end: new Date(Date.now() + 3600 * 1000 * 24 * 30)
+ }, {
+ text: '最近7天',
+ start: new Date(Date.now() - 3600 * 1000 * 24 * 7),
+ end: new Date()
+ }, {
+ text: '最近30天',
+ start: new Date(Date.now() - 3600 * 1000 * 24 * 30),
+ end: new Date()
+ }]
+ this.ranges.forEach((v, i) => {
+ v.text = this.translation.pickers[i]
+ })
+ } else {
+ this.ranges = []
+ }
},
displayPopup () {
const dw = document.documentElement.clientWidth