From d3f52c4a7aa506c0b7c992f6777e0fcbd65c44ed Mon Sep 17 00:00:00 2001 From: xuliangzhan Date: Sun, 5 Jun 2022 11:47:23 +0800 Subject: [PATCH] fix input --- packages/input/src/input.ts | 35 +++++++++++++++++--------------- packages/v-x-e-table/src/conf.ts | 4 ++-- types/input.d.ts | 4 ++++ 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/packages/input/src/input.ts b/packages/input/src/input.ts index cb732fedc..d9377c4d0 100644 --- a/packages/input/src/input.ts +++ b/packages/input/src/input.ts @@ -88,8 +88,10 @@ export default defineComponent({ digits: { type: [String, Number] as PropType, default: () => GlobalConfig.input.digits }, // date、week、month、quarter、year - minDate: { type: [String, Number, Date] as PropType, default: () => GlobalConfig.input.minDate }, - maxDate: { type: [String, Number, Date] as PropType, default: () => GlobalConfig.input.maxDate }, + startDate: { type: [String, Number, Date] as PropType, default: () => GlobalConfig.input.startDate }, + endDate: { type: [String, Number, Date] as PropType, default: () => GlobalConfig.input.endDate }, + minDate: [String, Number, Date] as PropType, + maxDate: [String, Number, Date] as PropType, // 已废弃 startWeek,被 startDay 替换 startWeek: Number as PropType, startDay: { type: [String, Number] as PropType, default: () => GlobalConfig.input.startDay }, @@ -229,12 +231,12 @@ export default defineComponent({ return props.clearable && (isPawdType || isNumType || isDatePickerType || type === 'text' || type === 'search') }) - const computeDateMinTime = computed(() => { - return props.minDate ? XEUtils.toStringDate(props.minDate) : null + const computeDateStartTime = computed(() => { + return props.startDate ? XEUtils.toStringDate(props.startDate) : null }) - const computeDateMaxTime = computed(() => { - return props.maxDate ? XEUtils.toStringDate(props.maxDate) : null + const computeDateEndTime = computed(() => { + return props.endDate ? XEUtils.toStringDate(props.endDate) : null }) const computeSupportMultiples = computed(() => { @@ -289,19 +291,19 @@ export default defineComponent({ }) const computeIsDisabledPrevDateBtn = computed(() => { - const dateMinTime = computeDateMinTime.value + const dateStartTime = computeDateStartTime.value const { selectMonth } = reactData - if (selectMonth && dateMinTime) { - return selectMonth <= dateMinTime + if (selectMonth && dateStartTime) { + return selectMonth <= dateStartTime } return false }) const computeIsDisabledNextDateBtn = computed(() => { - const dateMaxTime = computeDateMaxTime.value + const dateEndTime = computeDateEndTime.value const { selectMonth } = reactData - if (selectMonth && dateMaxTime) { - return selectMonth >= dateMaxTime + if (selectMonth && dateEndTime) { + return selectMonth >= dateEndTime } return false }) @@ -499,9 +501,9 @@ export default defineComponent({ const selMonth = selectMonth.getMonth() const selDay = selectMonth.getDay() const prevOffsetDate = -weekDatas.indexOf(selDay) - const startDate = new Date(XEUtils.getWhatDay(selectMonth, prevOffsetDate).getTime() + dateHMSTime) + const startDayDate = new Date(XEUtils.getWhatDay(selectMonth, prevOffsetDate).getTime() + dateHMSTime) for (let index = 0; index < 42; index++) { - const date = XEUtils.getWhatDay(startDate, index) + const date = XEUtils.getWhatDay(startDayDate, index) const itemFullYear = date.getFullYear() const itemMonth = date.getMonth() const itemDate = date.getDate() @@ -1322,9 +1324,10 @@ export default defineComponent({ } const dateConfirmEvent = () => { - const { type } = props + const { multiple } = props const dateValue = computeDateValue.value - if (type === 'time' || type === 'datetime') { + const isDateTimeType = computeIsDateTimeType.value + if (isDateTimeType || multiple) { dateChange(dateValue || reactData.currentDate) } hidePanel() diff --git a/packages/v-x-e-table/src/conf.ts b/packages/v-x-e-table/src/conf.ts index 1315c935c..49097f5b4 100644 --- a/packages/v-x-e-table/src/conf.ts +++ b/packages/v-x-e-table/src/conf.ts @@ -266,8 +266,8 @@ const GlobalConfig: VXETableGlobalConfig = { // parseFormat: 'yyyy-MM-dd HH:mm:ss.SSS', // labelFormat: '', // valueFormat: '', - minDate: new Date(1900, 0, 1), - maxDate: new Date(2100, 0, 1), + startDate: new Date(1900, 0, 1), + endDate: new Date(2100, 0, 1), startDay: 1, selectDay: 1, digits: 2, diff --git a/types/input.d.ts b/types/input.d.ts index 9b790151e..05e521163 100644 --- a/types/input.d.ts +++ b/types/input.d.ts @@ -65,6 +65,8 @@ export namespace VxeInputPropTypes { export type Exponential = boolean export type Controls = boolean export type Digits = string | number + export type StartDate = string | number | Date + export type EndDate = string | number | Date export type MinDate = string | number | Date export type MaxDate = string | number | Date export type StartDay = 0 | 1 | 2 | 3 | 4 | 5 | 6 @@ -110,6 +112,8 @@ export type VxeInputProps = { digits?: VxeInputPropTypes.Digits // date、week、month、quarter、year + startDate?: VxeInputPropTypes.StartDate + endDate?: VxeInputPropTypes.EndDate minDate?: VxeInputPropTypes.MinDate maxDate?: VxeInputPropTypes.MaxDate /**