mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-04-06 03:57:56 +08:00
fix(form): date组件初始化时不显示值
This commit is contained in:
parent
7a19b7204c
commit
0c665c6b3c
@ -107,6 +107,8 @@ export interface DatePickerProps {
|
|||||||
startPlaceholder?: string;
|
startPlaceholder?: string;
|
||||||
endPlaceholder?: string;
|
endPlaceholder?: string;
|
||||||
format?: string;
|
format?: string;
|
||||||
|
dateFormat?: string;
|
||||||
|
timeFormat?: string;
|
||||||
/** 可选,绑定值的格式。 不指定则绑定值为 Date 对象 */
|
/** 可选,绑定值的格式。 不指定则绑定值为 Date 对象 */
|
||||||
valueFormat?: string;
|
valueFormat?: string;
|
||||||
/** 在范围选择器里取消两个日期面板之间的联动 */
|
/** 在范围选择器里取消两个日期面板之间的联动 */
|
||||||
|
@ -45,7 +45,6 @@
|
|||||||
<template #label><span v-html="type === 'checkbox' ? '' : text" :title="config.labelTitle"></span></template>
|
<template #label><span v-html="type === 'checkbox' ? '' : text" :title="config.labelTitle"></span></template>
|
||||||
<TMagicTooltip v-if="tooltip">
|
<TMagicTooltip v-if="tooltip">
|
||||||
<component
|
<component
|
||||||
:data-tmagic-form-item-prop="itemProp"
|
|
||||||
:key="key(config)"
|
:key="key(config)"
|
||||||
:size="size"
|
:size="size"
|
||||||
:is="tagName"
|
:is="tagName"
|
||||||
@ -65,7 +64,6 @@
|
|||||||
|
|
||||||
<component
|
<component
|
||||||
v-else
|
v-else
|
||||||
:data-tmagic-form-item-prop="itemProp"
|
|
||||||
:key="key(config)"
|
:key="key(config)"
|
||||||
:size="size"
|
:size="size"
|
||||||
:is="tagName"
|
:is="tagName"
|
||||||
|
@ -30,7 +30,7 @@ const emit = defineEmits<{
|
|||||||
|
|
||||||
useAddField(props.prop);
|
useAddField(props.prop);
|
||||||
|
|
||||||
props.model[props.name] = datetimeFormatter(props.model[props.name], '', 'YYYY/MM/DD');
|
props.model[props.name] = datetimeFormatter(props.model[props.name], '', props.config.valueFormat || 'YYYY/MM/DD');
|
||||||
|
|
||||||
const changeHandler = (v: string) => {
|
const changeHandler = (v: string) => {
|
||||||
emit('change', v);
|
emit('change', v);
|
||||||
|
@ -22,7 +22,6 @@ import { ref, watch } from 'vue';
|
|||||||
import { TMagicDatePicker } from '@tmagic/design';
|
import { TMagicDatePicker } from '@tmagic/design';
|
||||||
|
|
||||||
import type { DaterangeConfig, FieldProps } from '../schema';
|
import type { DaterangeConfig, FieldProps } from '../schema';
|
||||||
import { datetimeFormatter } from '../utils/form';
|
|
||||||
import { useAddField } from '../utils/useAddField';
|
import { useAddField } from '../utils/useAddField';
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
@ -35,7 +34,6 @@ const emit = defineEmits(['change']);
|
|||||||
|
|
||||||
useAddField(props.prop);
|
useAddField(props.prop);
|
||||||
|
|
||||||
// eslint-disable-next-line vue/no-setup-props-destructure
|
|
||||||
const { names } = props.config;
|
const { names } = props.config;
|
||||||
const value = ref<(Date | undefined)[] | null>([]);
|
const value = ref<(Date | undefined)[] | null>([]);
|
||||||
|
|
||||||
@ -48,8 +46,8 @@ if (props.model !== undefined) {
|
|||||||
value.value = [];
|
value.value = [];
|
||||||
}
|
}
|
||||||
if (!start || !end) value.value = [];
|
if (!start || !end) value.value = [];
|
||||||
if (start !== preStart) value.value[0] = new Date(start);
|
if (start !== preStart) value.value[0] = start;
|
||||||
if (end !== preEnd) value.value[1] = new Date(end);
|
if (end !== preEnd) value.value[1] = end;
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
immediate: true,
|
immediate: true,
|
||||||
@ -58,8 +56,8 @@ if (props.model !== undefined) {
|
|||||||
} else if (props.name && props.model[props.name]) {
|
} else if (props.name && props.model[props.name]) {
|
||||||
watch(
|
watch(
|
||||||
() => props.model[props.name],
|
() => props.model[props.name],
|
||||||
(start, preStart) => {
|
(start) => {
|
||||||
if (start !== preStart) value.value = start.map((item: string) => (item ? new Date(item) : undefined));
|
value.value = start;
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
immediate: true,
|
immediate: true,
|
||||||
@ -74,11 +72,7 @@ const setValue = (v: Date[] | Date) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Array.isArray(v)) {
|
if (Array.isArray(v)) {
|
||||||
props.model[item] = datetimeFormatter(
|
props.model[item] = v[index];
|
||||||
v[index]?.toString(),
|
|
||||||
'',
|
|
||||||
props.config.valueFormat || 'YYYY/MM/DD HH:mm:ss',
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
props.model[item] = undefined;
|
props.model[item] = undefined;
|
||||||
}
|
}
|
||||||
@ -89,18 +83,12 @@ const changeHandler = (v: Date[]) => {
|
|||||||
const value = v || [];
|
const value = v || [];
|
||||||
|
|
||||||
if (props.name) {
|
if (props.name) {
|
||||||
emit(
|
emit('change', value);
|
||||||
'change',
|
|
||||||
value.map((item?: Date) => {
|
|
||||||
if (item) return datetimeFormatter(item, '', props.config.valueFormat || 'YYYY/MM/DD HH:mm:ss');
|
|
||||||
return undefined;
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
if (names?.length) {
|
if (names?.length) {
|
||||||
setValue(value);
|
setValue(value);
|
||||||
}
|
}
|
||||||
emit('change', value);
|
emit('change', props.model);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user