forked from p96170835/amis
Combo 的 strictMode 优化
This commit is contained in:
parent
baf68d6b71
commit
7c9d037054
|
@ -35,7 +35,6 @@
|
||||||
"dom-helpers": "3.3.1",
|
"dom-helpers": "3.3.1",
|
||||||
"downshift": "3.1.4",
|
"downshift": "3.1.4",
|
||||||
"echarts": "^4.1.0",
|
"echarts": "^4.1.0",
|
||||||
"fast-memoize": "2.5.1",
|
|
||||||
"flv.js": "1.5.0",
|
"flv.js": "1.5.0",
|
||||||
"froala-editor": "2.9.6",
|
"froala-editor": "2.9.6",
|
||||||
"history": "4.7.2",
|
"history": "4.7.2",
|
||||||
|
|
|
@ -21,18 +21,17 @@ import Select from '../../components/Select';
|
||||||
import {dataMapping} from '../../utils/tpl-builtin';
|
import {dataMapping} from '../../utils/tpl-builtin';
|
||||||
import {isEffectiveApi} from '../../utils/api';
|
import {isEffectiveApi} from '../../utils/api';
|
||||||
import {Alert2} from '../../components';
|
import {Alert2} from '../../components';
|
||||||
import memoize from 'fast-memoize';
|
import memoize from 'lodash/memoize';
|
||||||
|
|
||||||
const formatValue = memoize(
|
const formatValue = memoize(
|
||||||
(value: any, index: number, data: any) => {
|
(strictMode: boolean, value: any, index: number, data: any) => {
|
||||||
return createObject(
|
return createObject(
|
||||||
extendObject(data, {index, __index: index, ...data}),
|
extendObject(data, {index, __index: index, ...data}),
|
||||||
value
|
value
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
{
|
(strictMode: boolean, ...args: Array<any>) =>
|
||||||
serializer: (args: Array<any>) => JSON.stringify(args.slice(0, 2))
|
strictMode ? JSON.stringify(args.slice(0, 2)) : JSON.stringify(args)
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
export interface Condition {
|
export interface Condition {
|
||||||
|
@ -74,6 +73,7 @@ export interface ComboProps extends FormControlProps {
|
||||||
tabsStyle: '' | 'line' | 'card' | 'radio';
|
tabsStyle: '' | 'line' | 'card' | 'radio';
|
||||||
tabsLabelTpl?: string;
|
tabsLabelTpl?: string;
|
||||||
lazyLoad?: boolean;
|
lazyLoad?: boolean;
|
||||||
|
strictMode?: boolean;
|
||||||
messages?: {
|
messages?: {
|
||||||
validateFailed?: string;
|
validateFailed?: string;
|
||||||
minLengthValidateFailed?: string;
|
minLengthValidateFailed?: string;
|
||||||
|
@ -118,7 +118,8 @@ export default class ComboControl extends React.Component<ComboProps> {
|
||||||
'conditions',
|
'conditions',
|
||||||
'tabsMode',
|
'tabsMode',
|
||||||
'tabsStyle',
|
'tabsStyle',
|
||||||
'lazyLoad'
|
'lazyLoad',
|
||||||
|
'strictMode'
|
||||||
];
|
];
|
||||||
|
|
||||||
subForms: Array<any> = [];
|
subForms: Array<any> = [];
|
||||||
|
@ -543,7 +544,7 @@ export default class ComboControl extends React.Component<ComboProps> {
|
||||||
}
|
}
|
||||||
|
|
||||||
formatValue(value: any, index: number) {
|
formatValue(value: any, index: number) {
|
||||||
const {flat, data, store} = this.props;
|
const {flat, data, strictMode} = this.props;
|
||||||
|
|
||||||
if (flat) {
|
if (flat) {
|
||||||
value = {
|
value = {
|
||||||
|
@ -553,7 +554,7 @@ export default class ComboControl extends React.Component<ComboProps> {
|
||||||
|
|
||||||
value = value || this.defaultValue;
|
value = value || this.defaultValue;
|
||||||
|
|
||||||
return formatValue(value, index, data);
|
return formatValue(strictMode !== false, value, index, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
pickCondition(value: any): Condition | null {
|
pickCondition(value: any): Condition | null {
|
||||||
|
|
|
@ -93,7 +93,9 @@ export const ComboStore = iRendererStore
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeForm(form: IFormStore) {
|
function removeForm(form: IFormStore) {
|
||||||
self.forms.remove(form);
|
// form 可能再它自己销毁的是已经被移除了。因为调用的是 destroy,所以 self.forms 里面也被一起移除。
|
||||||
|
// 再来尝试移除,会报错。
|
||||||
|
self.forms.includes(form) && self.forms.remove(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setActiveKey(key: number) {
|
function setActiveKey(key: number) {
|
||||||
|
|
|
@ -80,6 +80,10 @@ export function syncDataFromSuper(
|
||||||
|
|
||||||
if (superObject || prevSuperObject) {
|
if (superObject || prevSuperObject) {
|
||||||
keys.forEach(key => {
|
keys.forEach(key => {
|
||||||
|
if (!key) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
((superObject && typeof superObject[key] !== 'undefined') ||
|
((superObject && typeof superObject[key] !== 'undefined') ||
|
||||||
(prevSuperObject && typeof prevSuperObject[key] !== 'undefined')) &&
|
(prevSuperObject && typeof prevSuperObject[key] !== 'undefined')) &&
|
||||||
|
|
Loading…
Reference in New Issue