Skip to content

Commit

Permalink
fix: shortcut date changed to function
Browse files Browse the repository at this point in the history
  • Loading branch information
mengxiong10 committed Jun 26, 2018
1 parent f282a4d commit 5cf6c72
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ export default {
shortcuts: [
{
text: 'Today',
start: new Date(),
end: new Date()
onClick: () => {
this.time3 = [ new Date(), new Date() ]
}
}
],
timePickerOptions:{
Expand Down Expand Up @@ -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}]
Expand Down
9 changes: 6 additions & 3 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:{
Expand Down Expand Up @@ -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}]
Expand Down
27 changes: 19 additions & 8 deletions src/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
},
Expand Down

0 comments on commit 5cf6c72

Please sign in to comment.