mirror of
https://github.com/tenrok/vue2-datepicker.git
synced 2026-06-21 03:20:35 +03:00
feat: add panel-change event
This commit is contained in:
@@ -156,6 +156,11 @@ export default {
|
|||||||
| confirm | When click 'OK' button | the currentValue |
|
| confirm | When click 'OK' button | the currentValue |
|
||||||
| clear | When click 'clear' button | |
|
| clear | When click 'clear' button | |
|
||||||
| input-error | When user type a invalid Date| the input text |
|
| input-error | When user type a invalid Date| the input text |
|
||||||
|
| panel-change | When change the panel | panel, oldPanel |
|
||||||
|
|
||||||
|
#### panel value
|
||||||
|
`['NONE', 'DATE', 'YEAR', 'MONTH', 'TIME']`
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Slots
|
### Slots
|
||||||
|
|||||||
@@ -154,6 +154,10 @@ export default {
|
|||||||
| input | 日期改变的时候触发 | 选择的日期 |
|
| input | 日期改变的时候触发 | 选择的日期 |
|
||||||
| confirm | 点击确认按钮触发的事件 | 选择的日期 |
|
| confirm | 点击确认按钮触发的事件 | 选择的日期 |
|
||||||
| input-error | 当用户输入的值无效时候触发 | 用户输入的字符串 |
|
| input-error | 当用户输入的值无效时候触发 | 用户输入的字符串 |
|
||||||
|
| panel-change | 切换面板时触发 | 当前面板,过去的面板|
|
||||||
|
|
||||||
|
#### panel value
|
||||||
|
`['NONE', 'DATE', 'YEAR', 'MONTH', 'TIME']`
|
||||||
|
|
||||||
## 许可证
|
## 许可证
|
||||||
|
|
||||||
|
|||||||
+24
-14
@@ -146,7 +146,7 @@ export default {
|
|||||||
const calendarMonth = now.getMonth()
|
const calendarMonth = now.getMonth()
|
||||||
const firstYear = Math.floor(calendarYear / 10) * 10
|
const firstYear = Math.floor(calendarYear / 10) * 10
|
||||||
return {
|
return {
|
||||||
panel: 'DATE',
|
panel: 'NONE',
|
||||||
dates: [],
|
dates: [],
|
||||||
calendarMonth,
|
calendarMonth,
|
||||||
calendarYear,
|
calendarYear,
|
||||||
@@ -198,12 +198,12 @@ export default {
|
|||||||
handler: 'init'
|
handler: 'init'
|
||||||
},
|
},
|
||||||
panel: {
|
panel: {
|
||||||
immediate: true,
|
|
||||||
handler: 'handelPanelChange'
|
handler: 'handelPanelChange'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
handelPanelChange (panel) {
|
handelPanelChange (panel, oldPanel) {
|
||||||
|
this.$parent.$emit('panel-change', panel, oldPanel)
|
||||||
if (panel === 'YEAR') {
|
if (panel === 'YEAR') {
|
||||||
this.firstYear = Math.floor(this.calendarYear / 10) * 10
|
this.firstYear = Math.floor(this.calendarYear / 10) * 10
|
||||||
} else if (panel === 'TIME') {
|
} else if (panel === 'TIME') {
|
||||||
@@ -216,16 +216,20 @@ export default {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
init () {
|
init (val) {
|
||||||
const type = this.type
|
if (val) {
|
||||||
if (type === 'month') {
|
const type = this.type
|
||||||
this.panel = 'MONTH'
|
if (type === 'month') {
|
||||||
} else if (type === 'year') {
|
this.showPanelMonth()
|
||||||
this.panel = 'YEAR'
|
} else if (type === 'year') {
|
||||||
} else if (type === 'time') {
|
this.showPanelYear()
|
||||||
this.panel = 'TIME'
|
} else if (type === 'time') {
|
||||||
|
this.showPanelTime()
|
||||||
|
} else {
|
||||||
|
this.showPanelDate()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.panel = 'DATE'
|
this.showPanelNone()
|
||||||
}
|
}
|
||||||
this.updateNow(this.value)
|
this.updateNow(this.value)
|
||||||
},
|
},
|
||||||
@@ -303,8 +307,8 @@ export default {
|
|||||||
time = new Date(this.startAt)
|
time = new Date(this.startAt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.$emit('select-time', time)
|
this.selectTime(time)
|
||||||
this.panel = 'TIME'
|
this.showPanelTime()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.$emit('select-date', date)
|
this.$emit('select-date', date)
|
||||||
@@ -380,6 +384,12 @@ export default {
|
|||||||
changePanelYears (flag) {
|
changePanelYears (flag) {
|
||||||
this.firstYear = this.firstYear + flag * 10
|
this.firstYear = this.firstYear + flag * 10
|
||||||
},
|
},
|
||||||
|
showPanelNone () {
|
||||||
|
this.panel = 'NONE'
|
||||||
|
},
|
||||||
|
showPanelTime () {
|
||||||
|
this.panel = 'TIME'
|
||||||
|
},
|
||||||
showPanelDate () {
|
showPanelDate () {
|
||||||
this.panel = 'DATE'
|
this.panel = 'DATE'
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user