@@ -10,12 +10,6 @@ import { SkeletonContext } from '../../context';
1010// import { Icon } from '@alifd/next';
1111import { intl } from '../../locale' ;
1212
13- function transformStringToFunction ( str ) {
14- if ( typeof str !== 'string' ) return str ;
15- // eslint-disable-next-line no-new-func
16- return new Function ( `"use strict"; return ${ str } ` ) ( ) ;
17- }
18-
1913function isStandardComponent ( componentMeta : ComponentMeta | null ) {
2014 if ( ! componentMeta ) return false ;
2115 const { prototype } = componentMeta ;
@@ -38,8 +32,9 @@ function isInitialValueNotEmpty(initialValue: any) {
3832}
3933
4034type SettingFieldViewProps = { field : SettingField } ;
35+ type SettingFieldViewState = { fromOnChange : boolean ; value : any } ;
4136@observer
42- class SettingFieldView extends Component < { field : SettingField } > {
37+ class SettingFieldView extends Component < SettingFieldViewProps , SettingFieldViewState > {
4338 static contextType = SkeletonContext ;
4439
4540 stageName : string | undefined ;
@@ -150,9 +145,10 @@ class SettingFieldView extends Component<{ field: SettingField }> {
150145
151146 // 当前 field 没有 value 值时,将 initialValue 写入 field
152147 // 之所以用 initialValue,而不是 defaultValue 是为了保持跟 props.onInitial 的逻辑一致
153- if ( value === undefined && isInitialValueNotEmpty ( initialValue ) ) {
148+ if ( ! this . state ?. fromOnChange && value === undefined && isInitialValueNotEmpty ( initialValue ) ) {
154149 const _initialValue = typeof initialValue === 'function' ? initialValue ( field . internalToShellPropEntry ( ) ) : initialValue ;
155150 field . setValue ( _initialValue ) ;
151+ value = _initialValue ;
156152 }
157153
158154 let _onChange = extraProps ?. onChange ;
@@ -183,8 +179,10 @@ class SettingFieldView extends Component<{ field: SettingField }> {
183179 field : field . internalToShellPropEntry ( ) ,
184180 // === IO
185181 value, // reaction point
182+ initialValue,
186183 onChange : ( value : any ) => {
187184 this . setState ( {
185+ fromOnChange : true ,
188186 // eslint-disable-next-line react/no-unused-state
189187 value,
190188 } ) ;
0 commit comments