mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-30 11:07:52 +08:00
amis-saas-6892 [Feature] 编辑器fx 交互优化
Change-Id: I9436c534dabfdefa73291b39856a1a8f8879f6ce
This commit is contained in:
parent
063c69955d
commit
f61ab35882
@ -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', {
|
||||
|
@ -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 || [];
|
||||
}
|
||||
|
@ -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',
|
||||
|
Loading…
Reference in New Issue
Block a user