Skip to content

Commit

Permalink
fix(form): datarange组件如果传入utc时间,显示会出错
Browse files Browse the repository at this point in the history
  • Loading branch information
roymondchen committed Sep 6, 2024
1 parent 03ba102 commit c77c0db
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions packages/form/src/fields/Daterange.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { ref, watch } from 'vue';
import { TMagicDatePicker } from '@tmagic/design';
import type { DaterangeConfig, FieldProps } from '../schema';
import { datetimeFormatter } from '../utils/form';
import { useAddField } from '../utils/useAddField';
defineOptions({
Expand All @@ -35,7 +36,7 @@ const emit = defineEmits(['change']);
useAddField(props.prop);
const { names } = props.config;
const value = ref<(Date | undefined)[] | null>([]);
const value = ref<(Date | string | undefined)[] | null>([]);
if (props.model !== undefined) {
if (names?.length) {
Expand All @@ -45,9 +46,11 @@ if (props.model !== undefined) {
if (!value.value) {
value.value = [];
}
const format = `${props.config.dateFormat || 'YYYY/MM/DD'} ${props.config.timeFormat || 'HH:mm:ss'}`;
if (!start || !end) value.value = [];
if (start !== preStart) value.value[0] = start;
if (end !== preEnd) value.value[1] = end;
if (start !== preStart) value.value[0] = datetimeFormatter(start, '', format) as string;
if (end !== preEnd) value.value[1] = datetimeFormatter(end, '', format) as string;
},
{
immediate: true,
Expand All @@ -56,8 +59,13 @@ if (props.model !== undefined) {
} else if (props.name && props.model[props.name]) {
watch(
() => props.model[props.name],
(start) => {
value.value = start;
(start, preStart) => {
const format = `${props.config.dateFormat || 'YYYY/MM/DD'} ${props.config.timeFormat || 'HH:mm:ss'}`;
if (start !== preStart)
value.value = start.map((item: string) =>
item ? (datetimeFormatter(item, '', format) as string) : undefined,
);
},
{
immediate: true,
Expand Down

0 comments on commit c77c0db

Please sign in to comment.