amis-saas-6892 [Feature] 编辑器fx 交互优化

Change-Id: I9436c534dabfdefa73291b39856a1a8f8879f6ce
This commit is contained in:
jiatianqi 2022-11-03 21:27:36 +08:00
parent 063c69955d
commit f61ab35882
3 changed files with 60 additions and 71 deletions

View File

@ -249,8 +249,7 @@ export class SelectControlPlugin extends BasePlugin {
getSchemaTpl('optionControlV2'),
// 模板
getSchemaTpl('optionsMenuTpl', {
that: this,
context: context,
manager: this.manager,
onChange: (value: any) => {}
}),
getSchemaTpl('creatable', {

View File

@ -176,7 +176,7 @@ export class TextareaFormulaControl extends React.Component<
let variables = [];
if (typeof rest?.variables === 'function') {
variables = rest.variables.call(this);
variables = rest.variables();
} else {
variables = rest?.variables || this.state.variables || [];
}

View File

@ -5,8 +5,7 @@ import {
isObject,
tipedLabel,
DSField,
BaseEventContext,
BasePlugin
EditorManager
} from 'amis-editor-core';
import {remarkTpl} from '../component/BaseControl';
import {SchemaObject} from 'amis/lib/Schema';
@ -493,77 +492,68 @@ setSchemaTpl('selectDateRangeType', {
]
});
setSchemaTpl(
'optionsMenuTpl',
(config: {
that: BasePlugin; // 当前组件 this 对象
context: BaseEventContext; // 事件上下文数据
}) => {
function getVariable() {
let rawVariables =
config.that.manager.dataSchema?.getDataPropsAsOptions();
// 函数调用会call(this)
// @ts-ignore
let schema = (this as any).data;
setSchemaTpl('optionsMenuTpl', (config: {manager: EditorManager}) => {
function getVariable() {
let rawVariables = config.manager.dataSchema?.getDataPropsAsOptions();
let schema = config.manager.store.valueWithoutHiddenProps;
let children = [];
let children = [];
if (schema.labelField) {
children.push({
label: '选项文本',
value: schema.labelField,
tag: typeof schema.labelField
});
}
if (schema.valueField) {
children.push({
label: '选项值',
value: schema.valueField,
tag: typeof schema.valueField
});
}
if (schema.options) {
let optionItem = _.reduce(
schema.options,
function (result, item) {
return {...result, ...item};
},
{}
);
delete optionItem?.$$id;
optionItem = _.omit(
optionItem,
_.map(children, item => item?.label)
);
let otherItem = _.map(_.keys(optionItem), item => ({
label:
item === 'label' ? '选项文本' : item === 'value' ? '选项值' : item,
value: item,
tag: typeof optionItem[item]
}));
children.push(...otherItem);
}
let variablesArr = [
{
label: '选项字段',
children
}
];
return [...variablesArr, ...rawVariables];
if (schema.labelField) {
children.push({
label: '选项文本',
value: schema.labelField,
tag: typeof schema.labelField
});
}
return {
type: 'ae-textareaFormulaControl',
mode: 'normal',
label: tipedLabel('模板', '选项渲染模板支持JSX变量使用\\${xx}'),
name: 'menuTpl',
variables: getVariable
};
if (schema.valueField) {
children.push({
label: '选项值',
value: schema.valueField,
tag: typeof schema.valueField
});
}
if (schema.options) {
let optionItem = _.reduce(
schema.options,
function (result, item) {
return {...result, ...item};
},
{}
);
delete optionItem?.$$id;
optionItem = _.omit(
optionItem,
_.map(children, item => item?.label)
);
let otherItem = _.map(_.keys(optionItem), item => ({
label:
item === 'label' ? '选项文本' : item === 'value' ? '选项值' : item,
value: item,
tag: typeof optionItem[item]
}));
children.push(...otherItem);
}
let variablesArr = [
{
label: '选项字段',
children
}
];
return [...variablesArr, ...rawVariables];
}
);
return {
type: 'ae-textareaFormulaControl',
mode: 'normal',
label: tipedLabel('模板', '选项渲染模板支持JSX变量使用\\${xx}'),
name: 'menuTpl',
variables: getVariable
};
});
setSchemaTpl('menuTpl', {
type: 'ae-formulaControl',