2
0
mirror of https://github.com/tenrok/vue2-datepicker.git synced 2026-06-08 09:02:28 +03:00

fix: shortcut date changed to function

This commit is contained in:
mxie
2018-06-26 19:42:21 +08:00
parent f282a4d948
commit 5cf6c72720
3 changed files with 30 additions and 13 deletions
+5 -2
View File
@@ -41,8 +41,9 @@ export default {
shortcuts: [
{
text: 'Today',
start: new Date(),
end: new Date()
onClick: () => {
this.time3 = [ new Date(), new Date() ]
}
}
],
timePickerOptions:{
@@ -124,12 +125,14 @@ export default {
* true - show the default shortcuts
* false - hide the shortcuts
* Object[] - custom shortcuts, [{text, start, end}]
* Object[] - custom shortcuts, [{text, onClick}]
| Prop | Type | Description |
|-----------------|---------------|------------------------|
| text | String | Text |
| start | Date | Start Date |
| end | Date | End Date |
| onClick | Function | click handler |
#### time-picker-options
* Object[] - custom time-picker, [{start, step, end}]
+6 -3
View File
@@ -40,9 +40,10 @@ export default {
time3: '',
shortcuts: [
{
text: 'Today',
start: new Date(),
end: new Date()
text: '今天',
onClick: () => {
this.time3 = [ new Date(), new Date() ]
}
}
],
timePickerOptions:{
@@ -123,12 +124,14 @@ export default {
* true - 显示默认快捷选择
* false - 隐藏快捷选择
* Object[] - 自定义快捷选择, 格式:[{text, start, end}]
* Object[] - 自定义快捷选择, 格式:[{text, onClick}]
| 名称 | 类型 | 说明 |
|-----------------|---------------|----------------|
| text | String | 显示文字 |
| start | Date | 开始日期 |
| end | Date | 结束日期 |
| onClick | Function | 点击时候触发的函数 |
#### time-picker-options
* Object[] - 自定义时间选择, 格式:[{start, step, end}]
+19 -8
View File
@@ -236,23 +236,31 @@ export default {
const arr = [
{
text: pickers[0],
start: new Date(),
end: new Date(Date.now() + 3600 * 1000 * 24 * 7)
onClick (self) {
self.currentValue = [ new Date(), new Date(Date.now() + 3600 * 1000 * 24 * 7) ]
self.updateDate(true)
}
},
{
text: pickers[1],
start: new Date(),
end: new Date(Date.now() + 3600 * 1000 * 24 * 30)
onClick (self) {
self.currentValue = [ new Date(), new Date(Date.now() + 3600 * 1000 * 24 * 30) ]
self.updateDate(true)
}
},
{
text: pickers[2],
start: new Date(Date.now() - 3600 * 1000 * 24 * 7),
end: new Date()
onClick (self) {
self.currentValue = [ new Date(Date.now() - 3600 * 1000 * 24 * 7), new Date() ]
self.updateDate(true)
}
},
{
text: pickers[3],
start: new Date(Date.now() - 3600 * 1000 * 24 * 30),
end: new Date()
onClick (self) {
self.currentValue = [ new Date(Date.now() - 3600 * 1000 * 24 * 30), new Date() ]
self.updateDate(true)
}
}
]
return arr
@@ -282,6 +290,9 @@ export default {
return Array.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((item, index) => this.dateEqual(item, b[index]))
},
selectRange (range) {
if (typeof range.onClick === 'function') {
return range.onClick(this)
}
this.currentValue = [ new Date(range.start), new Date(range.end) ]
this.updateDate(true)
},