2
0
mirror of https://github.com/tenrok/vue2-datepicker.git synced 2026-06-23 04:30:35 +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: [ shortcuts: [
{ {
text: 'Today', text: 'Today',
start: new Date(), onClick: () => {
end: new Date() this.time3 = [ new Date(), new Date() ]
}
} }
], ],
timePickerOptions:{ timePickerOptions:{
@@ -124,12 +125,14 @@ export default {
* true - show the default shortcuts * true - show the default shortcuts
* false - hide the shortcuts * false - hide the shortcuts
* Object[] - custom shortcuts, [{text, start, end}] * Object[] - custom shortcuts, [{text, start, end}]
* Object[] - custom shortcuts, [{text, onClick}]
| Prop | Type | Description | | Prop | Type | Description |
|-----------------|---------------|------------------------| |-----------------|---------------|------------------------|
| text | String | Text | | text | String | Text |
| start | Date | Start Date | | start | Date | Start Date |
| end | Date | End Date | | end | Date | End Date |
| onClick | Function | click handler |
#### time-picker-options #### time-picker-options
* Object[] - custom time-picker, [{start, step, end}] * Object[] - custom time-picker, [{start, step, end}]
+6 -3
View File
@@ -40,9 +40,10 @@ export default {
time3: '', time3: '',
shortcuts: [ shortcuts: [
{ {
text: 'Today', text: '今天',
start: new Date(), onClick: () => {
end: new Date() this.time3 = [ new Date(), new Date() ]
}
} }
], ],
timePickerOptions:{ timePickerOptions:{
@@ -123,12 +124,14 @@ export default {
* true - 显示默认快捷选择 * true - 显示默认快捷选择
* false - 隐藏快捷选择 * false - 隐藏快捷选择
* Object[] - 自定义快捷选择, 格式:[{text, start, end}] * Object[] - 自定义快捷选择, 格式:[{text, start, end}]
* Object[] - 自定义快捷选择, 格式:[{text, onClick}]
| 名称 | 类型 | 说明 | | 名称 | 类型 | 说明 |
|-----------------|---------------|----------------| |-----------------|---------------|----------------|
| text | String | 显示文字 | | text | String | 显示文字 |
| start | Date | 开始日期 | | start | Date | 开始日期 |
| end | Date | 结束日期 | | end | Date | 结束日期 |
| onClick | Function | 点击时候触发的函数 |
#### time-picker-options #### time-picker-options
* Object[] - 自定义时间选择, 格式:[{start, step, end}] * Object[] - 自定义时间选择, 格式:[{start, step, end}]
+19 -8
View File
@@ -236,23 +236,31 @@ export default {
const arr = [ const arr = [
{ {
text: pickers[0], text: pickers[0],
start: new Date(), onClick (self) {
end: new Date(Date.now() + 3600 * 1000 * 24 * 7) self.currentValue = [ new Date(), new Date(Date.now() + 3600 * 1000 * 24 * 7) ]
self.updateDate(true)
}
}, },
{ {
text: pickers[1], text: pickers[1],
start: new Date(), onClick (self) {
end: new Date(Date.now() + 3600 * 1000 * 24 * 30) self.currentValue = [ new Date(), new Date(Date.now() + 3600 * 1000 * 24 * 30) ]
self.updateDate(true)
}
}, },
{ {
text: pickers[2], text: pickers[2],
start: new Date(Date.now() - 3600 * 1000 * 24 * 7), onClick (self) {
end: new Date() self.currentValue = [ new Date(Date.now() - 3600 * 1000 * 24 * 7), new Date() ]
self.updateDate(true)
}
}, },
{ {
text: pickers[3], text: pickers[3],
start: new Date(Date.now() - 3600 * 1000 * 24 * 30), onClick (self) {
end: new Date() self.currentValue = [ new Date(Date.now() - 3600 * 1000 * 24 * 30), new Date() ]
self.updateDate(true)
}
} }
] ]
return arr 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])) return Array.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((item, index) => this.dateEqual(item, b[index]))
}, },
selectRange (range) { selectRange (range) {
if (typeof range.onClick === 'function') {
return range.onClick(this)
}
this.currentValue = [ new Date(range.start), new Date(range.end) ] this.currentValue = [ new Date(range.start), new Date(range.end) ]
this.updateDate(true) this.updateDate(true)
}, },