@@ -95,15 +95,14 @@ class ModalForm extends Component<
9595 const innerRef = this . getInnerRef ( ) ;
9696 innerRef . current . formType = formType ;
9797
98- if ( initialData ) {
99- this . setState ( { visible : true , formType, formData : initialData } ) ;
100- return ;
101- }
98+ // 合并初始值. openModal 所携带的初始值优先级更大.
99+ const propsInitialValues = this . props . formProps ?. initialValues || { } ;
100+ const initialValues = { ...propsInitialValues , ...initialData } ;
102101
103102 this . setState ( {
104103 visible : true ,
105104 formType,
106- formData : this . props . formProps ?. initialValues || { } ,
105+ formData : initialValues ,
107106 } ) ;
108107 } ;
109108
@@ -204,13 +203,26 @@ class ModalForm extends Component<
204203 } ;
205204
206205 getColumns = ( ) : any => {
206+ const { formData } = this . state ;
207+ const { open } = this . props ;
208+
207209 const $cols = normalizeTree (
208210 this . props . columns ,
209211 ( item ) => {
210212 /** 去掉 width 属性, 因为在表单中不需要 width */
211- const { width, ...rest } = item ;
212-
213- return rest ;
213+ const { width, initialValue, ...rest } = item ;
214+
215+ // columns 上和 SchemaForm 组件的 initialValues 上不能有相同的字段, 否则会有告警.
216+ // Form already set 'initialValues' with path 'name'. Field can not overwrite it
217+ if (
218+ ! open &&
219+ typeof item . dataIndex === 'string' &&
220+ formData . hasOwnProperty ( item . dataIndex )
221+ ) {
222+ return rest ;
223+ } else {
224+ return { initialValue, ...rest } ;
225+ }
214226 } ,
215227 { replace : true } ,
216228 ) ;
0 commit comments