From 7c9d037054603ada8b0fee1437315cf0cfe4103e Mon Sep 17 00:00:00 2001 From: 2betop <2betop.cn@gmail.com> Date: Thu, 26 Dec 2019 20:21:56 +0800 Subject: [PATCH] =?UTF-8?q?Combo=20=E7=9A=84=20strictMode=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 - src/renderers/Form/Combo.tsx | 17 +++++++++-------- src/store/combo.ts | 4 +++- src/utils/helper.ts | 4 ++++ 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index d5264abe..7c85cd0b 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,6 @@ "dom-helpers": "3.3.1", "downshift": "3.1.4", "echarts": "^4.1.0", - "fast-memoize": "2.5.1", "flv.js": "1.5.0", "froala-editor": "2.9.6", "history": "4.7.2", diff --git a/src/renderers/Form/Combo.tsx b/src/renderers/Form/Combo.tsx index 331f997d..e0b14d85 100644 --- a/src/renderers/Form/Combo.tsx +++ b/src/renderers/Form/Combo.tsx @@ -21,18 +21,17 @@ import Select from '../../components/Select'; import {dataMapping} from '../../utils/tpl-builtin'; import {isEffectiveApi} from '../../utils/api'; import {Alert2} from '../../components'; -import memoize from 'fast-memoize'; +import memoize from 'lodash/memoize'; const formatValue = memoize( - (value: any, index: number, data: any) => { + (strictMode: boolean, value: any, index: number, data: any) => { return createObject( extendObject(data, {index, __index: index, ...data}), value ); }, - { - serializer: (args: Array) => JSON.stringify(args.slice(0, 2)) - } + (strictMode: boolean, ...args: Array) => + strictMode ? JSON.stringify(args.slice(0, 2)) : JSON.stringify(args) ); export interface Condition { @@ -74,6 +73,7 @@ export interface ComboProps extends FormControlProps { tabsStyle: '' | 'line' | 'card' | 'radio'; tabsLabelTpl?: string; lazyLoad?: boolean; + strictMode?: boolean; messages?: { validateFailed?: string; minLengthValidateFailed?: string; @@ -118,7 +118,8 @@ export default class ComboControl extends React.Component { 'conditions', 'tabsMode', 'tabsStyle', - 'lazyLoad' + 'lazyLoad', + 'strictMode' ]; subForms: Array = []; @@ -543,7 +544,7 @@ export default class ComboControl extends React.Component { } formatValue(value: any, index: number) { - const {flat, data, store} = this.props; + const {flat, data, strictMode} = this.props; if (flat) { value = { @@ -553,7 +554,7 @@ export default class ComboControl extends React.Component { value = value || this.defaultValue; - return formatValue(value, index, data); + return formatValue(strictMode !== false, value, index, data); } pickCondition(value: any): Condition | null { diff --git a/src/store/combo.ts b/src/store/combo.ts index 38f259ed..5f695c38 100644 --- a/src/store/combo.ts +++ b/src/store/combo.ts @@ -93,7 +93,9 @@ export const ComboStore = iRendererStore } function removeForm(form: IFormStore) { - self.forms.remove(form); + // form 可能再它自己销毁的是已经被移除了。因为调用的是 destroy,所以 self.forms 里面也被一起移除。 + // 再来尝试移除,会报错。 + self.forms.includes(form) && self.forms.remove(form); } function setActiveKey(key: number) { diff --git a/src/utils/helper.ts b/src/utils/helper.ts index 3e8eac2f..20c12b95 100644 --- a/src/utils/helper.ts +++ b/src/utils/helper.ts @@ -80,6 +80,10 @@ export function syncDataFromSuper( if (superObject || prevSuperObject) { keys.forEach(key => { + if (!key) { + return; + } + if ( ((superObject && typeof superObject[key] !== 'undefined') || (prevSuperObject && typeof prevSuperObject[key] !== 'undefined')) &&