forked from p96170835/amis
还原代码
This commit is contained in:
parent
10af464a6e
commit
96c3b73434
|
@ -106,9 +106,10 @@ export const detectProps = itemDetectProps.concat([
|
||||||
'extractValue'
|
'extractValue'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
export function asOptionsControl(config: OptionsConfig) {
|
export function registerOptionsControl(config: OptionsConfig) {
|
||||||
return function (Control: React.ComponentType<OptionsControlProps>) {
|
const Control = config.component;
|
||||||
return class FormOptionsItem extends React.Component<OptionsProps, any> {
|
|
||||||
|
class FormOptionsItem extends React.Component<OptionsProps, any> {
|
||||||
static displayName = `OptionsControl(${config.type})`;
|
static displayName = `OptionsControl(${config.type})`;
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
delimiter: ',',
|
delimiter: ',',
|
||||||
|
@ -343,10 +344,7 @@ export function asOptionsControl(config: OptionsConfig) {
|
||||||
let valueArray = formItem.getSelectedOptions(value).concat();
|
let valueArray = formItem.getSelectedOptions(value).concat();
|
||||||
const idx = findIndex(
|
const idx = findIndex(
|
||||||
valueArray,
|
valueArray,
|
||||||
optionValueCompare(
|
optionValueCompare(option[valueField || 'value'], valueField || 'value')
|
||||||
option[valueField || 'value'],
|
|
||||||
valueField || 'value'
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
let newValue: string | Array<Option> | Option = '';
|
let newValue: string | Array<Option> | Option = '';
|
||||||
|
|
||||||
|
@ -659,10 +657,7 @@ export function asOptionsControl(config: OptionsConfig) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (!skipForm && (!Array.isArray(editControls) || !editControls.length)) {
|
||||||
!skipForm &&
|
|
||||||
(!Array.isArray(editControls) || !editControls.length)
|
|
||||||
) {
|
|
||||||
editControls = [
|
editControls = [
|
||||||
{
|
{
|
||||||
type: 'text',
|
type: 'text',
|
||||||
|
@ -778,8 +773,7 @@ export function asOptionsControl(config: OptionsConfig) {
|
||||||
const options = model.options.concat();
|
const options = model.options.concat();
|
||||||
const idx = findIndex(
|
const idx = findIndex(
|
||||||
options,
|
options,
|
||||||
item =>
|
item => item[valueField || 'value'] == value[valueField || 'value']
|
||||||
item[valueField || 'value'] == value[valueField || 'value']
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (~idx) {
|
if (~idx) {
|
||||||
|
@ -822,9 +816,7 @@ export function asOptionsControl(config: OptionsConfig) {
|
||||||
creatable={
|
creatable={
|
||||||
creatable || (creatable !== false && isEffectiveApi(addApi))
|
creatable || (creatable !== false && isEffectiveApi(addApi))
|
||||||
}
|
}
|
||||||
editable={
|
editable={editable || (editable !== false && isEffectiveApi(editApi))}
|
||||||
editable || (editable !== false && isEffectiveApi(editApi))
|
|
||||||
}
|
|
||||||
removable={
|
removable={
|
||||||
removable || (removable !== false && isEffectiveApi(deleteApi))
|
removable || (removable !== false && isEffectiveApi(deleteApi))
|
||||||
}
|
}
|
||||||
|
@ -834,17 +826,12 @@ export function asOptionsControl(config: OptionsConfig) {
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function registerOptionsControl(config: OptionsConfig) {
|
|
||||||
const Control = config.component;
|
|
||||||
|
|
||||||
return registerFormItem({
|
return registerFormItem({
|
||||||
...(config as FormItemBasicConfig),
|
...(config as FormItemBasicConfig),
|
||||||
strictMode: false,
|
strictMode: false,
|
||||||
component: asOptionsControl(config)(Control)
|
component: FormOptionsItem
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,6 @@ import {LazyComponent} from '../../components';
|
||||||
import {isAlive} from 'mobx-state-tree';
|
import {isAlive} from 'mobx-state-tree';
|
||||||
import {asFormItem} from './Item';
|
import {asFormItem} from './Item';
|
||||||
import {SimpleMap} from '../../utils/SimpleMap';
|
import {SimpleMap} from '../../utils/SimpleMap';
|
||||||
import {asOptionsControl} from './Options';
|
|
||||||
export type FormGroup = FormSchema & {
|
export type FormGroup = FormSchema & {
|
||||||
title?: string;
|
title?: string;
|
||||||
className?: string;
|
className?: string;
|
||||||
|
@ -1027,11 +1026,7 @@ export default class Form extends React.Component<FormProps, object> {
|
||||||
control.options || {
|
control.options || {
|
||||||
strictMode: false
|
strictMode: false
|
||||||
}
|
}
|
||||||
)(
|
)(control.component);
|
||||||
control.options || control.source
|
|
||||||
? asOptionsControl(control.component)
|
|
||||||
: control.component
|
|
||||||
);
|
|
||||||
this.componentCache.set(control.component, cache);
|
this.componentCache.set(control.component, cache);
|
||||||
control.component = cache;
|
control.component = cache;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue