mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-30 19:17:54 +08:00
merge master分支
Change-Id: I0d948d8c1f1b9bc638b68cf06e953057bf31e011
This commit is contained in:
parent
530766f87a
commit
cafd51915a
@ -392,7 +392,7 @@ export class CRUDPlugin extends BasePlugin {
|
||||
|
||||
valueSchema.bulkActions = [];
|
||||
/** 统一api格式 */
|
||||
valueSchema.api = normalizeApi(valueSchema.api);
|
||||
valueSchema.api = typeof valueSchema.api === 'string' ? valueSchema.api : normalizeApi(valueSchema.api);
|
||||
hasFeatures &&
|
||||
features.forEach((item: string) => {
|
||||
if (itemBtns.includes(item)) {
|
||||
|
@ -15,7 +15,7 @@ import type {FormSchema} from 'amis/lib/schema';
|
||||
|
||||
export interface StatusControlProps extends FormControlProps {
|
||||
name: string;
|
||||
expressioName: string;
|
||||
expressionName: string;
|
||||
trueValue?: boolean;
|
||||
falseValue?: boolean;
|
||||
options?: Option[];
|
||||
@ -23,8 +23,15 @@ export interface StatusControlProps extends FormControlProps {
|
||||
messages?: Pick<FormSchema, 'messages'>;
|
||||
}
|
||||
|
||||
|
||||
type StatusFormData = {
|
||||
statusType: number;
|
||||
expression: string;
|
||||
};
|
||||
|
||||
interface StatusControlState {
|
||||
checked: boolean;
|
||||
formData: StatusFormData;
|
||||
}
|
||||
|
||||
export class StatusControl extends React.Component<
|
||||
@ -42,9 +49,19 @@ export class StatusControl extends React.Component<
|
||||
}
|
||||
|
||||
initState() {
|
||||
const {data: ctx = {}, expressioName, name, trueValue} = this.props;
|
||||
const {data: ctx = {}, expressionName, name, trueValue} = this.props;
|
||||
const formData: StatusFormData = {
|
||||
statusType: 1,
|
||||
expression: '',
|
||||
};
|
||||
if (ctx[expressionName] || ctx[expressionName]=== "") {
|
||||
formData.statusType = 2;
|
||||
formData.expression = ctx[expressionName];
|
||||
}
|
||||
return {
|
||||
checked: ctx[name] == trueValue || typeof ctx[expressioName] === 'string'
|
||||
checked:
|
||||
ctx[name] == trueValue || typeof ctx[expressionName] === 'string',
|
||||
formData
|
||||
};
|
||||
}
|
||||
|
||||
@ -59,34 +76,40 @@ export class StatusControl extends React.Component<
|
||||
handleSwitch(value: boolean) {
|
||||
const {trueValue, falseValue} = this.props;
|
||||
this.setState({checked: value == trueValue ? true : false}, () => {
|
||||
const {onBulkChange, expressioName, name} = this.props;
|
||||
onBulkChange &&
|
||||
onBulkChange({
|
||||
[name]: value == trueValue ? trueValue : falseValue,
|
||||
[expressioName]: undefined
|
||||
});
|
||||
|
||||
const {onBulkChange, expressionName, name} = this.props;
|
||||
onBulkChange &&
|
||||
onBulkChange({
|
||||
[name]: value == trueValue ? trueValue : falseValue,
|
||||
[expressionName]: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@autobind
|
||||
handleSubmit(values: any) {
|
||||
const {onBulkChange, name, expressioName} = this.props;
|
||||
values[name] = !values[name] ? undefined : values[name];
|
||||
values[expressioName] = !values[expressioName]
|
||||
? undefined
|
||||
: values[expressioName];
|
||||
onBulkChange && onBulkChange(values);
|
||||
handleFormSubmit(
|
||||
values: StatusFormData
|
||||
) {
|
||||
const {onBulkChange, name, expressionName} = this.props;
|
||||
const data: Record<string, any> = {
|
||||
[name]: undefined,
|
||||
[expressionName]: undefined
|
||||
};
|
||||
|
||||
this.setState({formData: values});
|
||||
|
||||
switch (values.statusType) {
|
||||
case 1:
|
||||
data[name] = true;
|
||||
break;
|
||||
case 2:
|
||||
data[expressionName] = values.expression;
|
||||
break;
|
||||
}
|
||||
onBulkChange && onBulkChange(data);
|
||||
}
|
||||
|
||||
@autobind
|
||||
handleSelect(value: true | '') {
|
||||
const {onBulkChange, name, expressioName} = this.props;
|
||||
onBulkChange &&
|
||||
onBulkChange({
|
||||
[value ? expressioName : name]: undefined,
|
||||
[(!value && expressioName) || '']: ''
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
const {className, data: ctx = {}, trueValue, falseValue, env} = this.props;
|
||||
@ -117,11 +140,12 @@ export class StatusControl extends React.Component<
|
||||
label,
|
||||
data: ctx = {},
|
||||
name,
|
||||
expressioName,
|
||||
expressionName,
|
||||
options,
|
||||
children,
|
||||
messages
|
||||
} = this.props;
|
||||
const {formData} = this.state;
|
||||
|
||||
return (
|
||||
<div className="ae-StatusControl-content">
|
||||
@ -149,8 +173,7 @@ export class StatusControl extends React.Component<
|
||||
{
|
||||
type: 'select',
|
||||
label: '条件',
|
||||
name: name,
|
||||
valueOn: `typeof this.${expressioName} === "string" ? 2 : 1`,
|
||||
name: 'statusType',
|
||||
options: options || [
|
||||
{
|
||||
label: '静态',
|
||||
@ -160,26 +183,20 @@ export class StatusControl extends React.Component<
|
||||
label: '表达式',
|
||||
value: 2
|
||||
}
|
||||
],
|
||||
pipeIn: (value: any) => (typeof value === 'boolean' ? 1 : 2),
|
||||
pipeOut: (value: any) => (value === 1 ? true : ''),
|
||||
onChange: this.handleSelect
|
||||
]
|
||||
},
|
||||
{
|
||||
type: 'ae-formulaControl',
|
||||
name: 'expression',
|
||||
label: '表达式',
|
||||
placeholder: `请输入${label}条件`,
|
||||
visibleOn: 'this.statusType === 2'
|
||||
},
|
||||
...(Array.isArray(children)
|
||||
? children
|
||||
: [
|
||||
children || {
|
||||
type: 'ae-formulaControl',
|
||||
name: expressioName,
|
||||
label: '表达式',
|
||||
placeholder: `请输入${label}条件`,
|
||||
visibleOn: `typeof this.${name} !== "boolean"`
|
||||
}
|
||||
])
|
||||
]
|
||||
},
|
||||
{
|
||||
onSubmit: this.handleSubmit
|
||||
data: formData,
|
||||
onSubmit: this.handleFormSubmit
|
||||
}
|
||||
)}
|
||||
</div>
|
||||
|
@ -574,6 +574,7 @@ setSchemaTpl(
|
||||
return {
|
||||
title: '状态',
|
||||
body: [
|
||||
getSchemaTpl('newVisible'),
|
||||
getSchemaTpl('hidden'),
|
||||
config?.readonly ? getSchemaTpl('readonly') : null,
|
||||
config?.disabled || config?.isFormItem
|
||||
@ -622,7 +623,7 @@ setSchemaTpl('disabled', {
|
||||
label: '禁用',
|
||||
mode: 'normal',
|
||||
name: 'disabled',
|
||||
expressioName: 'disabledOn'
|
||||
expressionName: 'disabledOn'
|
||||
});
|
||||
|
||||
setSchemaTpl('readonly', {
|
||||
@ -630,7 +631,7 @@ setSchemaTpl('readonly', {
|
||||
label: '只读',
|
||||
mode: 'normal',
|
||||
name: 'readOnly',
|
||||
expressioName: 'readOnlyOn'
|
||||
expressionName: 'readOnlyOn'
|
||||
});
|
||||
|
||||
setSchemaTpl('visible', {
|
||||
@ -638,7 +639,18 @@ setSchemaTpl('visible', {
|
||||
label: '可见',
|
||||
mode: 'normal',
|
||||
name: 'visible',
|
||||
expressioName: 'visibleOn'
|
||||
expressionName: 'visibleOn'
|
||||
});
|
||||
|
||||
|
||||
// 新版配置面板兼容 [可见] 状态
|
||||
setSchemaTpl('newVisible', {
|
||||
type: 'ae-StatusControl',
|
||||
label: '可见',
|
||||
mode: 'normal',
|
||||
name: 'visible',
|
||||
expressionName: 'visibleOn',
|
||||
visibleOn:"data.visible || data.visible === false || data.visibleOn !== undefined"
|
||||
});
|
||||
|
||||
setSchemaTpl('hidden', {
|
||||
@ -646,7 +658,7 @@ setSchemaTpl('hidden', {
|
||||
label: '隐藏',
|
||||
mode: 'normal',
|
||||
name: 'hidden',
|
||||
expressioName: 'hiddenOn'
|
||||
expressionName: 'hiddenOn'
|
||||
});
|
||||
|
||||
setSchemaTpl('maximum', {
|
||||
|
Loading…
Reference in New Issue
Block a user