fix: 修复部分组件配置面板变更配置后,默认值选项没有更新的问题 (#8171)

Co-authored-by: wutong25 <wutong25@baidu.com>
This commit is contained in:
wutong 2023-09-20 10:46:36 +08:00 committed by GitHub
parent 7419cdc0a2
commit 7bc2c2ba85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 58 additions and 57 deletions

View File

@ -10,6 +10,7 @@ import {getSchemaTpl, defaultValue} from 'amis-editor-core';
import {getEventControlConfig} from '../../renderer/event-control/helper';
import {ValidatorTag} from '../../validator';
import {resolveOptionType} from '../../util';
import type {Schema} from 'amis';
export class ButtonGroupControlPlugin extends BasePlugin {
static id = 'ButtonGroupControlPlugin';
@ -126,7 +127,7 @@ export class ButtonGroupControlPlugin extends BasePlugin {
getSchemaTpl('label'),
getSchemaTpl('multiple'),
getSchemaTpl('valueFormula', {
rendererSchema: context?.schema,
rendererSchema: (schema: Schema) => schema,
useSelectMode: true, // 改用 Select 设置模式
visibleOn: 'this.options && this.options.length > 0'
}),

View File

@ -13,6 +13,7 @@ import {
} from 'amis-editor-core';
import {ValidatorTag} from '../../validator';
import {getEventControlConfig} from '../../renderer/event-control/helper';
import type {Schema} from 'amis';
export class ChainedSelectControlPlugin extends BasePlugin {
static id = 'ChainedSelectControlPlugin';
@ -114,7 +115,7 @@ export class ChainedSelectControlPlugin extends BasePlugin {
getSchemaTpl('label'),
getSchemaTpl('valueFormula', {
rendererSchema: context?.schema,
rendererSchema: (schema: Schema) => schema,
mode: 'vertical', // 改成上下展示模式
rendererWrapper: true,
label: tipedLabel('默认值', '请填入选项 Options 中 value 值')

View File

@ -15,6 +15,7 @@ import {
} from 'amis-editor-core';
import {ValidatorTag} from '../../validator';
import type {Schema} from 'amis';
import {RendererPluginAction, RendererPluginEvent} from 'amis-editor-core';
import {getEventControlConfig} from '../../renderer/event-control/helper';
import {resolveOptionType} from '../../util';
@ -166,7 +167,7 @@ export class CheckboxesControlPlugin extends BasePlugin {
}
],
getSchemaTpl('valueFormula', {
rendererSchema: context?.schema,
rendererSchema: (schema: Schema) => schema,
useSelectMode: true, // 改用 Select 设置模式
visibleOn: 'this.options && this.options.length > 0'
}),

View File

@ -13,6 +13,7 @@ import {
BaseEventContext
} from 'amis-editor-core';
import cloneDeep from 'lodash/cloneDeep';
import type {Schema} from 'amis';
import {formItemControl} from '../../component/BaseControl';
import {RendererPluginAction, RendererPluginEvent} from 'amis-editor-core';
@ -118,7 +119,7 @@ export class CityControlPlugin extends BasePlugin {
}),
getSchemaTpl('label'),
getSchemaTpl('valueFormula', {
rendererSchema: context?.schema,
rendererSchema: (schema: Schema) => schema,
rendererWrapper: true,
mode: 'vertical' // 改成上下展示模式
}),

View File

@ -6,6 +6,7 @@ import {ValidatorTag} from '../../validator';
import {getEventControlConfig} from '../../renderer/event-control/helper';
import {FormulaDateType} from '../../renderer/FormulaControl';
import {RendererPluginAction, RendererPluginEvent} from 'amis-editor-core';
import type {Schema} from 'amis';
const formatX = [
{
@ -347,15 +348,7 @@ export class DateControlPlugin extends BasePlugin {
pipeIn: defaultValue(true)
}),
getSchemaTpl('valueFormula', {
rendererSchema: () => {
const schema = this.manager.store.getSchema(
context.schema?.id,
'id'
);
return {
...schema
};
},
rendererSchema: (schema: Schema) => schema,
placeholder: '请选择静态值',
header: '表达式或相对值',
DateTimeType: FormulaDateType.IsDate,

View File

@ -8,6 +8,7 @@ import {FormulaDateType} from '../../renderer/FormulaControl';
import {RendererPluginAction, RendererPluginEvent} from 'amis-editor-core';
import {getRendererByName} from 'amis-core';
import omit from 'lodash/omit';
import type {Schema} from 'amis';
const formatX = [
{
@ -405,11 +406,11 @@ export class DateRangeControlPlugin extends BasePlugin {
}),
getSchemaTpl('valueFormula', {
rendererSchema: {
...context?.schema,
rendererSchema: (schema: Schema) => ({
...schema,
size: 'full',
mode: 'inline'
},
}),
mode: 'vertical',
header: '表达式或相对值',
DateTimeType: FormulaDateType.IsRange,
@ -419,11 +420,11 @@ export class DateRangeControlPlugin extends BasePlugin {
name: 'minDate',
header: '表达式或相对值',
DateTimeType: FormulaDateType.IsDate,
rendererSchema: {
...omit(context?.schema, ['shortcuts']),
value: context?.schema.minDate,
rendererSchema: (schema: Schema) => ({
...omit(schema, ['shortcuts']),
value: schema?.minDate,
type: 'input-date'
},
}),
placeholder: '请选择静态值',
needDeleteProps: ['minDate', 'ranges', 'shortcuts'], // 避免自我限制
label: tipedLabel('最小值', dateTooltip)
@ -432,11 +433,11 @@ export class DateRangeControlPlugin extends BasePlugin {
name: 'maxDate',
header: '表达式或相对值',
DateTimeType: FormulaDateType.IsDate,
rendererSchema: {
...omit(context?.schema, ['shortcuts']),
value: context?.schema.maxDate,
rendererSchema: (schema: Schema) => ({
...omit(schema, ['shortcuts']),
value: schema?.maxDate,
type: 'input-date'
},
}),
placeholder: '请选择静态值',
needDeleteProps: ['maxDate', 'ranges', 'shortcuts'], // 避免自我限制
label: tipedLabel('最大值', dateTooltip)
@ -446,11 +447,11 @@ export class DateRangeControlPlugin extends BasePlugin {
name: 'minDuration',
header: '表达式',
DateTimeType: FormulaDateType.NotDate,
rendererSchema: {
...context?.schema,
value: context?.schema.minDuration,
rendererSchema: (schema: Schema) => ({
...schema,
value: schema?.minDuration,
type: 'input-text'
},
}),
placeholder: '请输入相对值',
needDeleteProps: ['minDuration'], // 避免自我限制
label: tipedLabel('最小跨度', rangTooltip)
@ -460,11 +461,11 @@ export class DateRangeControlPlugin extends BasePlugin {
name: 'maxDuration',
header: '表达式',
DateTimeType: FormulaDateType.NotDate,
rendererSchema: {
...context?.schema,
value: context?.schema.maxDuration,
rendererSchema: (schema: Schema) => ({
...schema,
value: schema?.maxDuration,
type: 'input-text'
},
}),
placeholder: '请输入相对值',
needDeleteProps: ['maxDuration'], // 避免自我限制
label: tipedLabel('最大跨度', rangTooltip)

View File

@ -11,6 +11,7 @@ import {
import {formItemControl} from '../../component/BaseControl';
import {RendererPluginAction, RendererPluginEvent} from 'amis-editor-core';
import {resolveOptionType} from '../../util';
import type {Schema} from 'amis';
export class TagControlPlugin extends BasePlugin {
static id = 'TagControlPlugin';
@ -31,7 +32,11 @@ export class TagControlPlugin extends BasePlugin {
type: 'input-tag',
label: '标签',
name: 'tag',
options: ['红色', '绿色', '蓝色']
options: [
{label: '红色', value: 'red'},
{label: '绿色', value: 'green'},
{label: '蓝色', value: 'blue'}
]
};
previewSchema: any = {
type: 'form',
@ -40,7 +45,7 @@ export class TagControlPlugin extends BasePlugin {
wrapWithPanel: false,
body: {
...this.scaffold,
value: '红色'
value: 'red'
}
};
@ -168,7 +173,7 @@ export class TagControlPlugin extends BasePlugin {
getSchemaTpl('clearable'),
getSchemaTpl('optionsTip'),
getSchemaTpl('valueFormula', {
rendererSchema: context?.schema,
rendererSchema: (schema: Schema) => schema,
mode: 'vertical' // 改成上下展示模式
}),
getSchemaTpl('joinValues'),

View File

@ -16,6 +16,7 @@ import {
import {tipedLabel} from 'amis-editor-core';
import {ValidatorTag} from '../../validator';
import {resolveOptionType} from '../../util';
import type {Schema} from 'amis';
export class TreeControlPlugin extends BasePlugin {
static id = 'TreeControlPlugin';
@ -418,10 +419,10 @@ export class TreeControlPlugin extends BasePlugin {
hiddenOn: '!data.multiple || !data.autoCheckChildren'
}),
getSchemaTpl('valueFormula', {
rendererSchema: {
...context?.schema,
rendererSchema: (schema: Schema) => ({
...schema,
type: 'tree-select'
},
}),
visibleOn: 'this.options && this.options.length > 0'
}),

View File

@ -5,6 +5,7 @@ import {BasePlugin, BaseEventContext} from 'amis-editor-core';
import {formItemControl} from '../../component/BaseControl';
import {RendererPluginAction, RendererPluginEvent} from 'amis-editor-core';
import {resolveOptionType} from '../../util';
import type {Schema} from 'amis';
export class ListControlPlugin extends BasePlugin {
static id = 'ListControlPlugin';
@ -118,7 +119,7 @@ export class ListControlPlugin extends BasePlugin {
getSchemaTpl('multiple'),
getSchemaTpl('extractValue'),
getSchemaTpl('valueFormula', {
rendererSchema: context?.schema,
rendererSchema: (schema: Schema) => schema,
mode: 'vertical',
useSelectMode: true, // 改用 Select 设置模式
visibleOn: 'this.options && this.options.length > 0'

View File

@ -9,6 +9,7 @@ import {BasePlugin, BaseEventContext, tipedLabel} from 'amis-editor-core';
import {ValidatorTag} from '../../validator';
import {getEventControlConfig} from '../../renderer/event-control/helper';
import {resolveOptionType} from '../../util';
import type {Schema} from 'amis';
export class NestedSelectControlPlugin extends BasePlugin {
static id = 'NestedSelectControlPlugin';
@ -304,7 +305,7 @@ export class NestedSelectControlPlugin extends BasePlugin {
}
],
getSchemaTpl('valueFormula', {
rendererSchema: context?.schema
rendererSchema: (schema: Schema) => schema
}),
getSchemaTpl('hideNodePathLabel'),
getSchemaTpl('labelRemark'),

View File

@ -6,6 +6,7 @@ import {ValidatorTag} from '../../validator';
import {getEventControlConfig} from '../../renderer/event-control/helper';
import {RendererPluginAction, RendererPluginEvent} from 'amis-editor-core';
import {resolveOptionType} from '../../util';
import type {Schema} from 'amis';
export class RadiosControlPlugin extends BasePlugin {
static id = 'RadiosControlPlugin';
@ -128,7 +129,7 @@ export class RadiosControlPlugin extends BasePlugin {
}),
getSchemaTpl('label'),
getSchemaTpl('valueFormula', {
rendererSchema: context?.schema,
rendererSchema: (schema: Schema) => schema,
useSelectMode: true, // 改用 Select 设置模式
visibleOn: 'this.options && this.options.length > 0'
}),

View File

@ -14,7 +14,7 @@ import {ValidatorTag} from '../../validator';
import {getEventControlConfig} from '../../renderer/event-control/helper';
import {resolveOptionType} from '../../util';
import type {RendererProps} from 'amis';
import type {Schema} from 'amis';
import type {
EditorNodeType,
RendererPluginAction,
@ -296,15 +296,7 @@ export class SelectControlPlugin extends BasePlugin {
}),
getSchemaTpl('checkAll'),
getSchemaTpl('valueFormula', {
rendererSchema: () => {
const schema = this.manager.store.getSchema(
context.schema?.id,
'id'
);
return {
...schema
};
}
rendererSchema: (schema: Schema) => schema
}),
getSchemaTpl('labelRemark'),
getSchemaTpl('remark'),

View File

@ -7,6 +7,7 @@ import {RendererPluginAction, RendererPluginEvent} from 'amis-editor-core';
import {ValidatorTag} from '../../validator';
import {tipedLabel} from 'amis-editor-core';
import {resolveOptionType} from '../../util';
import type {Schema} from 'amis';
export class TransferPlugin extends BasePlugin {
static id = 'TransferPlugin';
@ -184,11 +185,11 @@ export class TransferPlugin extends BasePlugin {
}),
getSchemaTpl('label'),
getSchemaTpl('valueFormula', {
rendererSchema: {
...context?.schema,
rendererSchema: (schema: Schema) => ({
...schema,
type: 'select',
multiple: true
},
}),
visibleOn: 'data.options.length > 0'
}),
getSchemaTpl('labelRemark'),

View File

@ -20,7 +20,7 @@ export class PaginationPlugin extends BasePlugin {
name = '分页组件';
isBaseComponent = true;
description = '分页组件,可以对列表进行分页展示,提高页面性能';
tags = ['容器'];
tags = ['展示'];
icon = 'fa fa-window-minimize';
lastLayoutSetting = ['pager'];
layoutOptions = [

View File

@ -98,7 +98,7 @@ export interface FormulaControlProps extends FormControlProps {
* :
* 备注: 可用于设置指定组件类型编辑默认值
*/
rendererSchema?: any; // SchemaObject | Function | undefined;
rendererSchema?: any; // SchemaObject | (schema: Schema) => Schema | undefined;
/**
*
@ -240,7 +240,8 @@ export default class FormulaControl extends React.Component<
}
if (typeof rendererSchema === 'function') {
return rendererSchema();
const schema = this.props.data ? {...this.props.data} : undefined;
return rendererSchema(schema);
} else {
return rendererSchema;
}