diff --git a/README.md b/README.md index 282f60c..41bd4d7 100644 --- a/README.md +++ b/README.md @@ -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}] diff --git a/README.zh-CN.md b/README.zh-CN.md index 1497a23..3ac6ae8 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -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}] diff --git a/src/index.vue b/src/index.vue index 6cab3eb..e9ccc8c 100644 --- a/src/index.vue +++ b/src/index.vue @@ -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) },