mirror of
https://github.com/tenrok/vue2-datepicker.git
synced 2026-06-20 07:10:36 +03:00
feat: add calendar-change event
This commit is contained in:
+9
-6
@@ -73,6 +73,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import { isValidDate, isDateObejct, formatDate } from '@/utils/index'
|
import { isValidDate, isDateObejct, formatDate } from '@/utils/index'
|
||||||
import locale from '@/mixins/locale'
|
import locale from '@/mixins/locale'
|
||||||
|
import emitter from '@/mixins/emitter'
|
||||||
import scrollIntoView from '@/utils/scroll-into-view'
|
import scrollIntoView from '@/utils/scroll-into-view'
|
||||||
import PanelDate from '@/panel/date'
|
import PanelDate from '@/panel/date'
|
||||||
import PanelYear from '@/panel/year'
|
import PanelYear from '@/panel/year'
|
||||||
@@ -82,7 +83,7 @@ import PanelTime from '@/panel/time'
|
|||||||
export default {
|
export default {
|
||||||
name: 'CalendarPanel',
|
name: 'CalendarPanel',
|
||||||
components: { PanelDate, PanelYear, PanelMonth, PanelTime },
|
components: { PanelDate, PanelYear, PanelMonth, PanelTime },
|
||||||
mixins: [locale],
|
mixins: [locale, emitter],
|
||||||
props: {
|
props: {
|
||||||
value: {
|
value: {
|
||||||
default: null,
|
default: null,
|
||||||
@@ -203,7 +204,7 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
handelPanelChange (panel, oldPanel) {
|
handelPanelChange (panel, oldPanel) {
|
||||||
this.$parent.$emit('panel-change', panel, oldPanel)
|
this.dispatch('DatePicker', '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') {
|
||||||
@@ -231,11 +232,13 @@ export default {
|
|||||||
} else {
|
} else {
|
||||||
this.showPanelNone()
|
this.showPanelNone()
|
||||||
}
|
}
|
||||||
this.updateNow(this.value)
|
|
||||||
},
|
},
|
||||||
// 根据value更新日历
|
// 根据value更新日历
|
||||||
updateNow (value) {
|
updateNow (value) {
|
||||||
this.now = value ? new Date(value) : new Date()
|
const now = value ? new Date(value) : new Date()
|
||||||
|
const oldNow = new Date(this.now)
|
||||||
|
this.dispatch('DatePicker', 'calendar-change', [now, oldNow])
|
||||||
|
this.now = now
|
||||||
},
|
},
|
||||||
getCriticalTime (value) {
|
getCriticalTime (value) {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
@@ -334,10 +337,10 @@ export default {
|
|||||||
this.$emit('select-time', time, true)
|
this.$emit('select-time', time, true)
|
||||||
},
|
},
|
||||||
changeCalendarYear (year) {
|
changeCalendarYear (year) {
|
||||||
this.now = new Date(year, this.calendarMonth)
|
this.updateNow(new Date(year, this.calendarMonth))
|
||||||
},
|
},
|
||||||
changeCalendarMonth (month) {
|
changeCalendarMonth (month) {
|
||||||
this.now = new Date(this.calendarYear, month)
|
this.updateNow(new Date(this.calendarYear, month))
|
||||||
},
|
},
|
||||||
getSibling () {
|
getSibling () {
|
||||||
const calendars = this.$parent.$children.filter(v => v.$options.name === this.$options.name)
|
const calendars = this.$parent.$children.filter(v => v.$options.name === this.$options.name)
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
|
||||||
|
export default {
|
||||||
|
methods: {
|
||||||
|
dispatch (componentName, eventName, params) {
|
||||||
|
let parent = this.$parent || this.$root
|
||||||
|
let name = parent.$options.name
|
||||||
|
|
||||||
|
while (parent && (!name || name !== componentName)) {
|
||||||
|
parent = parent.$parent
|
||||||
|
|
||||||
|
if (parent) {
|
||||||
|
name = parent.$options.name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (name && name === componentName) {
|
||||||
|
parent = parent || this
|
||||||
|
parent.$emit.apply(parent, [eventName].concat(params))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user