From 22e67a7a2985b3bc702235172667ece5225bfa9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?w=C5=AB=20y=C4=81ng?= Date: Mon, 1 Apr 2024 16:34:58 +0800 Subject: [PATCH 1/2] fix(date-picker): over parse when valueType is Date --- src/date-picker/DatePicker.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/date-picker/DatePicker.tsx b/src/date-picker/DatePicker.tsx index e09be55c5..4676957aa 100644 --- a/src/date-picker/DatePicker.tsx +++ b/src/date-picker/DatePicker.tsx @@ -51,8 +51,12 @@ export default defineComponent({ const isDisabled = computed(() => formDisabled.value || props.disabled); watch(popupVisible, (visible) => { - const dateValue = value.value ? covertToDate(value.value as string, formatRef.value?.valueType) : value.value; - + const dateValue = + // Date 属性不再 parse,避免 dayjs 处理成 Invalid + value.value && !isDate(value.value) + ? covertToDate(value.value as string, formatRef.value?.valueType) + : value.value; + cacheValue.value = formatDate(dateValue, { format: formatRef.value.format, }); From 5f25d9fcae4d1dc7cb8c9709ac5613451264607f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?w=C5=AB=20y=C4=81ng?= Date: Mon, 1 Apr 2024 16:42:10 +0800 Subject: [PATCH 2/2] chore: fix lint --- src/date-picker/DatePicker.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/date-picker/DatePicker.tsx b/src/date-picker/DatePicker.tsx index 4676957aa..eee1e5199 100644 --- a/src/date-picker/DatePicker.tsx +++ b/src/date-picker/DatePicker.tsx @@ -1,6 +1,7 @@ import { defineComponent, watch, computed } from '@vue/composition-api'; import dayjs from 'dayjs'; import { CalendarIcon as TdCalendarIcon } from 'tdesign-icons-vue'; +import isDate from 'lodash/isDate'; import { usePrefixClass } from '../hooks/useConfig'; import { useGlobalIcon } from '../hooks/useGlobalIcon'; @@ -51,12 +52,11 @@ export default defineComponent({ const isDisabled = computed(() => formDisabled.value || props.disabled); watch(popupVisible, (visible) => { - const dateValue = - // Date 属性不再 parse,避免 dayjs 处理成 Invalid - value.value && !isDate(value.value) - ? covertToDate(value.value as string, formatRef.value?.valueType) - : value.value; - + // Date valueType add empty string don't need to be parsed + const dateValue = value.value && !isDate(value.value) + ? covertToDate(value.value as string, formatRef.value?.valueType) + : value.value; + cacheValue.value = formatDate(dateValue, { format: formatRef.value.format, });