import {defineComponent, h} from "vue"; import {defaultProps} from "./common/props"; import dayjs from 'dayjs' import customParseFormat from 'dayjs/plugin/customParseFormat' import advancedFormat from 'dayjs/plugin/advancedFormat' import localeData from 'dayjs/plugin/localeData' import weekOfYear from 'dayjs/plugin/weekOfYear' import weekYear from 'dayjs/plugin/weekYear' import dayOfYear from 'dayjs/plugin/dayOfYear' import isSameOrAfter from 'dayjs/plugin/isSameOrAfter' import isSameOrBefore from 'dayjs/plugin/isSameOrBefore' import {DEFAULT_FORMATS_DATE, DEFAULT_FORMATS_DATEPICKER} from "./common/constant"; import CommonPicker from './common/picker.vue' import DateRangePickPanel from './date-picker-cont/scope-date-range.vue' import MonthRangePickPanel from './date-picker-cont/scope-month-range.vue' import DatePickPanel from './date-picker-cont/scope-date-pick.vue' dayjs.extend(localeData) dayjs.extend(advancedFormat) dayjs.extend(customParseFormat) dayjs.extend(weekOfYear) dayjs.extend(weekYear) dayjs.extend(dayOfYear) dayjs.extend(isSameOrAfter) dayjs.extend(isSameOrBefore) const getPanel = function (type) { if (type === 'daterange' || type === 'datetimerange') { return DateRangePickPanel } else if (type === 'monthrange') { return MonthRangePickPanel } return DatePickPanel } export default defineComponent({ name: 'RoDatePicker', install: null, props: { type: { type: String, default: 'date' }, ...defaultProps }, emits: ['update:modelValue'], setup(props, ctx) { let format = DEFAULT_FORMATS_DATEPICKER[props.type] || DEFAULT_FORMATS_DATE return () => h(CommonPicker, { format, ...props, type: props.type, 'onUpdate:modelValue': val => ctx.emit('update:modelValue', val) }, {default: scopedProps => h(getPanel(props.type), scopedProps)} ) } })