|
1 | 1 | <template> |
2 | | - <Form v-bind="$attrs" ref="formElRef" :model="formModel"> |
| 2 | + <Form v-bind="{ ...$attrs, ...$props }" ref="formElRef" :model="formModel"> |
3 | 3 | <Row :class="getProps.compact ? 'compact-form-row' : ''"> |
4 | 4 | <slot name="formHeader" /> |
5 | 5 | <template v-for="schema in getSchema" :key="schema.field"> |
|
54 | 54 | const formModel = reactive({}); |
55 | 55 |
|
56 | 56 | const actionState = reactive({ |
57 | | - resetAction: () => {}, |
58 | | - submitAction: () => {}, |
| 57 | + resetAction: {}, |
| 58 | + submitAction: {}, |
59 | 59 | }); |
60 | 60 |
|
61 | 61 | const advanceState = reactive<AdvanceState>({ |
|
67 | 67 |
|
68 | 68 | const defaultValueRef = ref<any>({}); |
69 | 69 | const propsRef = ref<Partial<FormProps>>({}); |
70 | | - const schemaRef = ref<FormSchema[] | null>(null); |
| 70 | + const schemaRef = ref<Nullable<FormSchema[]>>(null); |
71 | 71 | const formElRef = ref<Nullable<FormActionType>>(null); |
72 | 72 |
|
73 | 73 | const getMergePropsRef = computed( |
|
98 | 98 | for (const schema of schemas) { |
99 | 99 | const { defaultValue, component } = schema; |
100 | 100 | if (defaultValue && dateItemType.includes(component!)) { |
101 | | - schema.defaultValue = moment(defaultValue); |
| 101 | + if (!Array.isArray(defaultValue)) { |
| 102 | + schema.defaultValue = moment(defaultValue); |
| 103 | + } else { |
| 104 | + const def: moment.Moment[] = []; |
| 105 | + defaultValue.forEach((item) => { |
| 106 | + def.push(moment(item)); |
| 107 | + }); |
| 108 | + schema.defaultValue = def; |
| 109 | + } |
102 | 110 | } |
103 | 111 | } |
104 | 112 | return schemas as FormSchema[]; |
|
139 | 147 | formModel, |
140 | 148 | getSchema, |
141 | 149 | defaultValueRef, |
142 | | - formElRef: formElRef as any, |
143 | | - schemaRef: schemaRef as any, |
| 150 | + formElRef: formElRef as Ref<FormActionType>, |
| 151 | + schemaRef: schemaRef as Ref<FormSchema[]>, |
144 | 152 | handleFormValues, |
145 | 153 | actionState, |
146 | 154 | }); |
|
156 | 164 | } |
157 | 165 | ); |
158 | 166 |
|
| 167 | + watch( |
| 168 | + () => getSchema.value, |
| 169 | + () => { |
| 170 | + initDefault(); |
| 171 | + } |
| 172 | + ); |
| 173 | +
|
159 | 174 | /** |
160 | 175 | * @description:设置表单 |
161 | 176 | */ |
|
0 commit comments