fix: 增加必要的方法

This commit is contained in:
LeoYuan 袁力皓 2022-02-16 21:21:25 +08:00
parent b8b265866b
commit 1b38a81265
3 changed files with 14 additions and 9 deletions

View File

@ -24,7 +24,6 @@
"setup:test": "./scripts/setup-for-test.sh", "setup:test": "./scripts/setup-for-test.sh",
"setup:skip-build": "./scripts/setup-skip-build.sh", "setup:skip-build": "./scripts/setup-skip-build.sh",
"start": "./scripts/start.sh", "start": "./scripts/start.sh",
"start:demo": "./scripts/start.sh @ali/lowcode-demo",
"test": "lerna run test --stream", "test": "lerna run test --stream",
"test:snapshot": "lerna run test:snapshot", "test:snapshot": "lerna run test:snapshot",
"watchdog:build": "node ./scripts/watchdog.js", "watchdog:build": "node ./scripts/watchdog.js",

View File

@ -10,12 +10,6 @@ import { SkeletonContext } from '../../context';
// import { Icon } from '@alifd/next'; // import { Icon } from '@alifd/next';
import { intl } from '../../locale'; import { intl } from '../../locale';
function transformStringToFunction(str) {
if (typeof str !== 'string') return str;
// eslint-disable-next-line no-new-func
return new Function(`"use strict"; return ${str}`)();
}
function isStandardComponent(componentMeta: ComponentMeta | null) { function isStandardComponent(componentMeta: ComponentMeta | null) {
if (!componentMeta) return false; if (!componentMeta) return false;
const { prototype } = componentMeta; const { prototype } = componentMeta;
@ -38,8 +32,9 @@ function isInitialValueNotEmpty(initialValue: any) {
} }
type SettingFieldViewProps = { field: SettingField }; type SettingFieldViewProps = { field: SettingField };
type SettingFieldViewState = { fromOnChange: boolean; value: any };
@observer @observer
class SettingFieldView extends Component<{ field: SettingField }> { class SettingFieldView extends Component<SettingFieldViewProps, SettingFieldViewState> {
static contextType = SkeletonContext; static contextType = SkeletonContext;
stageName: string | undefined; stageName: string | undefined;
@ -150,9 +145,10 @@ class SettingFieldView extends Component<{ field: SettingField }> {
// 当前 field 没有 value 值时,将 initialValue 写入 field // 当前 field 没有 value 值时,将 initialValue 写入 field
// 之所以用 initialValue而不是 defaultValue 是为了保持跟 props.onInitial 的逻辑一致 // 之所以用 initialValue而不是 defaultValue 是为了保持跟 props.onInitial 的逻辑一致
if (value === undefined && isInitialValueNotEmpty(initialValue)) { if (!this.state?.fromOnChange && value === undefined && isInitialValueNotEmpty(initialValue)) {
const _initialValue = typeof initialValue === 'function' ? initialValue(field.internalToShellPropEntry()) : initialValue; const _initialValue = typeof initialValue === 'function' ? initialValue(field.internalToShellPropEntry()) : initialValue;
field.setValue(_initialValue); field.setValue(_initialValue);
value = _initialValue;
} }
let _onChange = extraProps?.onChange; let _onChange = extraProps?.onChange;
@ -183,8 +179,10 @@ class SettingFieldView extends Component<{ field: SettingField }> {
field: field.internalToShellPropEntry(), field: field.internalToShellPropEntry(),
// === IO // === IO
value, // reaction point value, // reaction point
initialValue,
onChange: (value: any) => { onChange: (value: any) => {
this.setState({ this.setState({
fromOnChange: true,
// eslint-disable-next-line react/no-unused-state // eslint-disable-next-line react/no-unused-state
value, value,
}); });

View File

@ -124,6 +124,14 @@ export default class SettingPropEntry {
this[settingPropEntrySymbol].setPropValue(propName, value); this[settingPropEntrySymbol].setPropValue(propName, value);
} }
/**
*
* @param propName
*/
clearPropValue(propName: string | number) {
this[settingPropEntrySymbol].clearPropValue(propName);
}
/** /**
* *
* @returns * @returns