Merge pull request #7147 from hsm-lv/feat-formulaeditor

feat:表达式编辑器升级
This commit is contained in:
hsm-lv 2023-06-16 18:07:41 +08:00 committed by GitHub
commit 0ce97c81f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
81 changed files with 2773 additions and 1907 deletions

View File

@ -380,7 +380,9 @@ export type FunctionPropertyNames<T> = {
// 先只支持 JSONSchema draft07 好了
export type JSONSchema = JSONSchema7;
export type JSONSchema = JSONSchema7 & {
group?: string; // 分组
};
// export type Omit<T, K extends keyof T & any> = Pick<T, Exclude<keyof T, K>>;
// export type Override<M, N> = Omit<M, Extract<keyof M, keyof N>> & N;

View File

@ -98,18 +98,41 @@ export class DataSchema {
return this;
}
pushVariable(current: DataScope, variables: any[]) {
if (current.tag) {
variables.push({
label: current.tag,
children: current.getDataPropsAsOptions()
});
} else {
variables.push(...current.getDataPropsAsOptions());
}
}
getDataPropsAsOptions() {
const variables: Array<any> = [];
let current: DataScope | void = this.current;
while (current) {
if (current.tag) {
variables.push({
label: current.tag,
children: current.getDataPropsAsOptions()
});
if (current.group) {
const subVars: Array<any> = [];
this.pushVariable(current, subVars);
const index = variables.findIndex(
item => item.label === current?.group
);
if (~index) {
variables[index].children.push(...subVars);
} else {
variables.push({
label: current.group,
children: subVars
});
}
} else {
variables.push(...current.getDataPropsAsOptions());
this.pushVariable(current, variables);
}
current = current.parent;

View File

@ -18,6 +18,9 @@ export class DataScope {
// scope 分类
tag?: string;
// scope 分组不同scope
group?: string;
// scope 的描述信息
description?: string;
@ -200,18 +203,37 @@ export class DataScope {
protected buildOptions(
options: Array<any>,
schema: JSONSchema,
path: string = '',
key: string = ''
path: {label: string; value: string} = {label: '', value: ''},
key: string = '',
isMember?: boolean // 是否是数组成员
) {
// todo 支持 oneOf, anyOf
const option: any = {
let option: any = {
label: schema.title || key,
value: path,
value: schema.title === '成员' ? '' : path.value,
path: schema.title === '成员' ? '' : path.label,
type: schema.type,
tag: schema.description ?? schema.type
tag: schema.type,
description: schema.description,
isMember,
disabled: schema.title === '成员'
};
options.push(option);
// 处理option分组
if (schema.group) {
const index = options.findIndex(item => item.label === schema.group);
if (~index) {
options[index].children.push(option);
} else {
options.push({
label: schema.group,
value: '',
children: [option]
});
}
} else {
options.push(option);
}
if (schema.type === 'object' && schema.properties) {
option.children = [];
@ -219,15 +241,18 @@ export class DataScope {
keys.forEach(key => {
const child: any = schema.properties![key];
this.buildOptions(
option.children,
child,
path + (path ? '.' : '') + key,
key
{
label: path.label + (path.label ? '.' : '') + (child.title ?? key),
value: path.value + (path.value ? '.' : '') + key
},
key,
schema.title === '成员'
);
});
} else if (schema.type === 'array' && schema.items) {
} else if (schema.type === 'array' && (schema.items as any)?.properties) {
option.children = [];
this.buildOptions(
@ -237,13 +262,17 @@ export class DataScope {
...(schema.items as any),
disabled: true
},
path,
'items'
{
label: path.label,
value: path.value
},
'items',
schema.title === '成员'
);
option.children = mapTree(option.children, item => ({
...item,
disabled: true
...item
// disabled: true
}));
}
}

View File

@ -105,7 +105,10 @@ export function makeWrapper(
this.scopeId = `${info.id}-${info.type}`;
manager.dataSchema.addScope([], this.scopeId);
if (info.name) {
manager.dataSchema.current.tag = `${info.name}变量`;
const nodeSchema = manager.store.getNodeById(info.id)?.schema;
const tag = nodeSchema?.title ?? nodeSchema?.name;
manager.dataSchema.current.tag = `${tag ?? ''}${info.name}`;
manager.dataSchema.current.group = '组件上下文';
}
}
}

View File

@ -299,7 +299,6 @@ export class EditorManager {
this.dnd = parent?.dnd || new EditorDNDManager(this, store);
this.dataSchema =
parent?.dataSchema || new DataSchema(config.schemas || []);
this.dataSchema.current.tag = '系统变量';
/** 初始化变量管理 */
this.variableManager = new VariableManager(

View File

@ -104,10 +104,20 @@ export class VariableManager {
}
/** 初始化变量Scope */
dataSchema.addScope(schema, scopeName);
dataSchema.addScope(
{
type: 'object',
$id: scopeName,
properties: {
[scopeName]: {
...schema,
title: tagName
}
}
},
scopeName
);
dataSchema.switchTo(scopeName);
/** 这里的Tag指变量的命名空间中文名称 */
dataSchema.current.tag = tagName;
if (afterScopeInsert && typeof afterScopeInsert === 'function') {
afterScopeInsert(this);

View File

@ -55,9 +55,15 @@ export class ButtonPlugin extends BasePlugin {
{
type: 'object',
properties: {
nativeEvent: {
context: {
type: 'object',
title: '鼠标事件对象'
title: '上下文',
properties: {
nativeEvent: {
type: 'object',
title: '鼠标事件对象'
}
}
}
}
}
@ -71,9 +77,15 @@ export class ButtonPlugin extends BasePlugin {
{
type: 'object',
properties: {
nativeEvent: {
context: {
type: 'object',
title: '鼠标事件对象'
title: '上下文',
properties: {
nativeEvent: {
type: 'object',
title: '鼠标事件对象'
}
}
}
}
}
@ -87,9 +99,15 @@ export class ButtonPlugin extends BasePlugin {
{
type: 'object',
properties: {
nativeEvent: {
context: {
type: 'object',
title: '鼠标事件对象'
title: '上下文',
properties: {
nativeEvent: {
type: 'object',
title: '鼠标事件对象'
}
}
}
}
}

View File

@ -102,17 +102,23 @@ export class CRUDPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.responseData': {
data: {
type: 'object',
title: '响应数据'
},
'event.data.responseStatus': {
type: 'number',
title: '响应状态(0表示成功)'
},
'event.data.responseMsg': {
type: 'string',
title: '响应消息'
title: '数据',
properties: {
responseData: {
type: 'object',
title: '响应数据'
},
responseStatus: {
type: 'number',
title: '响应状态(0表示成功)'
},
responseMsg: {
type: 'string',
title: '响应消息'
}
}
}
}
}
@ -126,13 +132,19 @@ export class CRUDPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.selectedItems': {
type: 'array',
title: '已选择行'
},
'event.data.unSelectedItems': {
type: 'array',
title: '未选择行'
data: {
type: 'object',
title: '数据',
properties: {
selectedItems: {
type: 'array',
title: '已选择行记录'
},
unSelectedItems: {
type: 'array',
title: '未选择行记录'
}
}
}
}
}
@ -146,13 +158,19 @@ export class CRUDPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.orderBy': {
type: 'string',
title: '列排序列名'
},
'event.data.orderDir': {
type: 'string',
title: '列排序值'
data: {
type: 'object',
title: '数据',
properties: {
orderBy: {
type: 'string',
title: '列名'
},
orderDir: {
type: 'string',
title: '排序值'
}
}
}
}
}
@ -166,13 +184,19 @@ export class CRUDPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.filterName': {
type: 'string',
title: '列筛选列名'
},
'event.data.filterValue': {
type: 'string',
title: '列筛选值'
data: {
type: 'object',
title: '数据',
properties: {
filterName: {
type: 'string',
title: '列名'
},
filterValue: {
type: 'string',
title: '筛选值'
}
}
}
}
}
@ -186,13 +210,19 @@ export class CRUDPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.searchName': {
type: 'string',
title: '列搜索列名'
},
'event.data.searchValue': {
data: {
type: 'object',
title: '列搜索数据'
title: '数据',
properties: {
searchName: {
type: 'string',
title: '列名'
},
searchValue: {
type: 'object',
title: '搜索值'
}
}
}
}
}
@ -206,9 +236,15 @@ export class CRUDPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.movedItems': {
type: 'array',
title: '已排序数据'
data: {
type: 'object',
title: '数据',
properties: {
movedItems: {
type: 'array',
title: '已排序记录'
}
}
}
}
}
@ -222,9 +258,15 @@ export class CRUDPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.columns': {
type: 'array',
title: '当前显示的列配置数据'
data: {
type: 'object',
title: '数据',
properties: {
columns: {
type: 'array',
title: '当前显示的列配置'
}
}
}
}
}
@ -238,13 +280,19 @@ export class CRUDPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.item': {
data: {
type: 'object',
title: '当前行数据'
},
'event.data.index': {
type: 'number',
title: '当前行索引'
title: '数据',
properties: {
item: {
type: 'object',
title: '当前行记录'
},
index: {
type: 'number',
title: '当前行索引'
}
}
}
}
}
@ -258,13 +306,19 @@ export class CRUDPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.item': {
data: {
type: 'object',
title: '当前行数据'
},
'event.data.index': {
type: 'number',
title: '当前行索引'
title: '数据',
properties: {
item: {
type: 'object',
title: '当前行记录'
},
index: {
type: 'number',
title: '当前行索引'
}
}
}
}
}
@ -278,13 +332,19 @@ export class CRUDPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.item': {
data: {
type: 'object',
title: '当前行数据'
},
'event.data.index': {
type: 'number',
title: '当前行索引'
title: '数据',
properties: {
item: {
type: 'object',
title: '当前行记录'
},
index: {
type: 'number',
title: '当前行索引'
}
}
}
}
}
@ -1981,10 +2041,12 @@ export class CRUDPlugin extends BasePlugin {
// 兼容table的rows并自行merged异步数据
if (child.type === 'table') {
let cellProperties = {};
let cellProperties: any = {}; // 收集当前行记录中的列
let itemsSchema: any = {}; // 收集选择记录中的列
const columns: EditorNodeType = child.children.find(
item => item.isRegion && item.region === 'columns'
);
const rowsSchema = childSchame.properties.rows?.items;
if (trigger) {
const isColumnChild = someTree(
@ -1993,24 +2055,31 @@ export class CRUDPlugin extends BasePlugin {
);
// merge异步数据中的单列成员因为rendererBeforeDispatchEvent无法区分是否需要单列成员
if (isColumnChild) {
const scope = this.manager.dataSchema.getScope(
`${node.id}-${node.type}`
);
const menberProps = (
scope.getSchemaById('crudFetchInitedData')?.properties?.items as any
)?.items?.properties;
const scope = this.manager.dataSchema.getScope(
`${node.id}-${node.type}`
);
// 列表记录成员字段
const menberProps = (
scope.getSchemaById('crudFetchInitedData')?.properties?.items as any
)?.items?.properties;
// 所有字段
let tmpProperties: any = {
...menberProps,
...rowsSchema?.properties
};
cellProperties = {
...menberProps,
...omit(
childSchame.properties,
'rows',
'selectedItems',
'unSelectedItems'
)
Object.keys(tmpProperties).map(key => {
if (isColumnChild) {
// 给列补充group
cellProperties[key] = {
...cellProperties[key],
group: '当前行记录'
};
}
itemsSchema[key] = {
...tmpProperties[key]
};
}
});
}
childSchame = {
@ -2019,8 +2088,20 @@ export class CRUDPlugin extends BasePlugin {
properties: {
...cellProperties,
items: childSchame.properties.rows,
selectedItems: childSchame.properties.selectedItems,
unSelectedItems: childSchame.properties.unSelectedItems,
selectedItems: {
...childSchame.properties.selectedItems,
items: {
...childSchame.properties.selectedItems.items,
properties: itemsSchema
}
},
unSelectedItems: {
...childSchame.properties.selectedItems,
items: {
...childSchame.properties.unSelectedItems.items,
properties: itemsSchema
}
},
count: {
type: 'number',
title: '总行数'

View File

@ -1306,14 +1306,6 @@ export class CRUDPlugin extends BasePlugin {
};
}
events: RendererPluginEvent[] = [
{
eventName: 'get-data',
eventLabel: '数据加载',
description: '列表数据翻页'
}
];
actions: RendererPluginAction[] = [
{
actionType: 'search',

View File

@ -25,45 +25,51 @@ const DEFAULT_EVENT_PARAMS = [
{
type: 'object',
properties: {
'event.data.componentType': {
type: 'string',
title: 'componentType'
},
'event.data.seriesType': {
type: 'string',
title: 'seriesType'
},
'event.data.seriesIndex': {
type: 'number',
title: 'seriesIndex'
},
'event.data.seriesName': {
type: 'string',
title: 'seriesName'
},
'event.data.name': {
type: 'string',
title: 'name'
},
'event.data.dataIndex': {
type: 'number',
title: 'dataIndex'
},
'event.data.data': {
data: {
type: 'object',
title: 'data'
},
'event.data.dataType': {
type: 'string',
title: 'dataType'
},
'event.data.value': {
type: 'number',
title: 'value'
},
'event.data.color': {
type: 'string',
title: 'color'
title: '数据',
properties: {
componentType: {
type: 'string',
title: 'componentType'
},
seriesType: {
type: 'string',
title: 'seriesType'
},
seriesIndex: {
type: 'number',
title: 'seriesIndex'
},
seriesName: {
type: 'string',
title: 'seriesName'
},
name: {
type: 'string',
title: 'name'
},
dataIndex: {
type: 'number',
title: 'dataIndex'
},
data: {
type: 'object',
title: 'data'
},
dataType: {
type: 'string',
title: 'dataType'
},
value: {
type: 'number',
title: 'value'
},
color: {
type: 'string',
title: 'color'
}
}
}
}
}
@ -117,9 +123,10 @@ export class ChartPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data': {
data: {
type: 'object',
title: '当前数据域'
title: '数据',
description: '当前数据域,可以通过.字段名读取对应的值'
}
}
}
@ -145,13 +152,19 @@ export class ChartPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.name': {
type: 'string',
title: 'name'
},
'event.data.selected': {
data: {
type: 'object',
title: 'selected'
title: '数据',
properties: {
name: {
type: 'string',
title: 'name'
},
selected: {
type: 'object',
title: 'selected'
}
}
}
}
}

View File

@ -63,9 +63,10 @@ export class DialogPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data': {
data: {
type: 'object',
title: '弹窗数据'
title: '数据',
description: '当前数据域,可以通过.字段名读取对应的值'
}
}
}
@ -79,9 +80,10 @@ export class DialogPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data': {
data: {
type: 'object',
title: '弹窗数据'
title: '数据',
description: '当前数据域,可以通过.字段名读取对应的值'
}
}
}

View File

@ -63,9 +63,10 @@ export class DrawerPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data': {
data: {
type: 'object',
title: '抽屉数据'
title: '数据',
description: '当前数据域,可以通过.字段名读取对应的值'
}
}
}
@ -79,9 +80,10 @@ export class DrawerPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data': {
data: {
type: 'object',
title: '抽屉数据'
title: '数据',
description: '当前数据域,可以通过.字段名读取对应的值'
}
}
}

View File

@ -66,9 +66,15 @@ export class ButtonGroupControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '选中值'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '选中的值'
}
}
}
}
}

View File

@ -55,9 +55,15 @@ export class ChainedSelectControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '选中值'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '选中的值'
}
}
}
}
}

View File

@ -68,9 +68,15 @@ export class CheckboxControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '选中状态'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '状态值'
}
}
}
}
}

View File

@ -76,9 +76,15 @@ export class CheckboxesControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '选中值'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '选中的值'
}
}
}
}
}

View File

@ -51,9 +51,15 @@ export class CodeEditorControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '当前代码'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '当前代码内容'
}
}
}
}
}
@ -67,9 +73,15 @@ export class CodeEditorControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '当前代码'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '当前代码内容'
}
}
}
}
}
@ -83,9 +95,15 @@ export class CodeEditorControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '当前代码'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '当前代码内容'
}
}
}
}
}

View File

@ -106,9 +106,15 @@ export class ComboControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
data: {
type: 'object',
title: '当前组合项的值'
title: '数据',
properties: {
value: {
type: 'string',
title: '组合项的值'
}
}
}
}
}
@ -122,17 +128,23 @@ export class ComboControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.key': {
type: 'string',
title: '删除项的索引'
},
'event.data.value': {
type: 'string',
title: '现有组合项的值'
},
'event.data.item': {
data: {
type: 'object',
title: '被删除的项'
title: '数据',
properties: {
key: {
type: 'string',
title: '被删除的索引'
},
value: {
type: 'string',
title: '组合项的值'
},
item: {
type: 'object',
title: '被删除的项'
}
}
}
}
}
@ -146,17 +158,23 @@ export class ComboControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.key': {
type: 'string',
title: '选项卡索引'
},
'event.data.value': {
type: 'string',
title: '现有组合项的值'
},
'event.data.item': {
data: {
type: 'object',
title: '被激活的项'
title: '数据',
properties: {
key: {
type: 'string',
title: '选项卡索引'
},
value: {
type: 'string',
title: '组合项的值'
},
item: {
type: 'object',
title: '被激活的项'
}
}
}
}
}
@ -204,7 +222,6 @@ export class ComboControlPlugin extends BasePlugin {
getSchemaTpl('formulaControl', {
name: 'val',
variables: '${variables}',
variableMode: 'tabs',
inputMode: 'input-group'
})
]

View File

@ -57,9 +57,15 @@ export class DiffEditorControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '当前代码'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '当前代码内容'
}
}
}
}
}
@ -73,9 +79,15 @@ export class DiffEditorControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '当前代码'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '当前代码内容'
}
}
}
}
}
@ -89,9 +101,15 @@ export class DiffEditorControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '当前代码'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '当前代码内容'
}
}
}
}
}

View File

@ -255,17 +255,23 @@ export class FormPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.responseData': {
data: {
type: 'object',
title: '响应数据'
},
'event.data.responseStatus': {
type: 'number',
title: '响应状态(0表示成功)'
},
'event.data.responseMsg': {
type: 'string',
title: '响应消息'
title: '数据',
properties: {
responseData: {
type: 'object',
title: '响应数据'
},
responseStatus: {
type: 'number',
title: '响应状态(0表示成功)'
},
responseMsg: {
type: 'string',
title: '响应消息'
}
}
}
}
}
@ -279,9 +285,10 @@ export class FormPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data': {
data: {
type: 'object',
title: '当前表单数据'
title: '数据',
description: '当前表单数据,可以通过.字段名读取对应的值'
}
}
}
@ -295,9 +302,10 @@ export class FormPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data': {
data: {
type: 'object',
title: '当前表单数据'
title: '数据',
description: '当前表单数据,可以通过.字段名读取对应的值'
}
}
}
@ -311,9 +319,10 @@ export class FormPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data': {
data: {
type: 'object',
title: '当前表单数据'
title: '数据',
description: '当前表单数据,可以通过.字段名读取对应的值'
}
}
}
@ -327,9 +336,10 @@ export class FormPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data': {
data: {
type: 'object',
title: '当前表单数据'
title: '数据',
description: '当前表单数据,可以通过.字段名读取对应的值'
}
}
}
@ -343,9 +353,10 @@ export class FormPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data': {
data: {
type: 'object',
title: '当前表单数据'
title: '数据',
description: '当前表单数据,可以通过.字段名读取对应的值'
}
}
}
@ -360,9 +371,10 @@ export class FormPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data': {
data: {
type: 'object',
title: '当前表单数据'
title: '数据',
description: '当前表单数据,可以通过.字段名读取对应的值'
}
}
}
@ -377,9 +389,15 @@ export class FormPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.result': {
data: {
type: 'object',
title: '保存接口请求成功后返回的数据'
title: '数据',
properties: {
result: {
type: 'object',
title: '保存接口请求成功后返回的数据'
}
}
}
}
}
@ -393,9 +411,15 @@ export class FormPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.error': {
data: {
type: 'object',
title: '保存接口请求失败后返回的错误信息'
title: '数据',
properties: {
error: {
type: 'object',
title: '保存接口请求失败后返回的错误信息'
}
}
}
}
}
@ -404,7 +428,19 @@ export class FormPlugin extends BasePlugin {
{
eventName: 'asyncApiFinished',
eventLabel: '远程请求轮询结束',
description: 'asyncApi 远程请求轮询结束后触发'
description: 'asyncApi 远程请求轮询结束后触发',
dataSchema: [
{
type: 'object',
properties: {
data: {
type: 'object',
title: '数据',
description: '当前数据域,可以通过.字段名读取对应的值'
}
}
}
]
}
];

View File

@ -63,9 +63,15 @@ export class CityControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '选中值'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '当前城市'
}
}
}
}
}

View File

@ -88,35 +88,6 @@ export class ColorControlPlugin extends BasePlugin {
};
panelTitle = '颜色框';
notRenderFormZone = true;
events = [
{
eventName: 'change',
eventLabel: '值变化',
description: '输入框内容变化'
},
{
eventName: 'focus',
eventLabel: '获取焦点',
description: '输入框获取焦点'
},
{
eventName: 'blur',
eventLabel: '失去焦点',
description: '输入框失去焦点'
}
];
actions = [
{
actionType: 'clear',
actionLabel: '清空',
description: '清空输入框内容'
},
{
actionType: 'focus',
actionLabel: '获取焦点',
description: '输入框获取焦点'
}
];
panelJustify = true;
getConditionalColorPanel(format: string) {
const visibleOnNoFormat = format === 'hex' ? ' || !this.format' : '';

View File

@ -186,9 +186,15 @@ export class DateControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '时间值'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '当前日期'
}
}
}
}
}
@ -202,9 +208,15 @@ export class DateControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '时间值'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '当前日期'
}
}
}
}
}
@ -218,9 +230,15 @@ export class DateControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '时间值'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '当前日期'
}
}
}
}
}

View File

@ -228,9 +228,15 @@ export class DateRangeControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '时间值'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '当前时间范围'
}
}
}
}
}
@ -244,9 +250,15 @@ export class DateRangeControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '时间值'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '当前时间范围'
}
}
}
}
}
@ -260,9 +272,15 @@ export class DateRangeControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '时间值'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '当前时间范围'
}
}
}
}
}

View File

@ -57,9 +57,15 @@ export class ExcelControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: 'excel 解析后的数据'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: 'excel解析后的数据'
}
}
}
}
}

View File

@ -51,9 +51,15 @@ export class FileControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.file': {
data: {
type: 'object',
title: '上传的文件'
title: '数据',
properties: {
file: {
type: 'object',
title: '上传的文件'
}
}
}
}
}
@ -67,9 +73,15 @@ export class FileControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.item': {
data: {
type: 'object',
title: '被移除的文件'
title: '数据',
properties: {
item: {
type: 'object',
title: '被移除的文件'
}
}
}
}
}
@ -83,9 +95,15 @@ export class FileControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.item': {
data: {
type: 'object',
title: '远程上传请求成功后返回的结果数据'
title: '数据',
properties: {
item: {
type: 'object',
title: '远程上传请求成功后返回的结果数据'
}
}
}
}
}
@ -99,13 +117,19 @@ export class FileControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.item': {
data: {
type: 'object',
title: '上传的文件'
},
'event.data.error': {
type: 'object',
title: '远程上传请求失败后返回的错误信息'
title: '数据',
properties: {
item: {
type: 'object',
title: '上传的文件'
},
error: {
type: 'object',
title: '远程上传请求失败后返回的错误信息'
}
}
}
}
}

View File

@ -94,9 +94,15 @@ export class ImageControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.file': {
data: {
type: 'object',
title: '上传的文件'
title: '数据',
properties: {
file: {
type: 'object',
title: '上传的文件'
}
}
}
}
}
@ -110,9 +116,15 @@ export class ImageControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.item': {
data: {
type: 'object',
title: '被移除的文件'
title: '数据',
properties: {
item: {
type: 'object',
title: '被移除的文件'
}
}
}
}
}
@ -126,9 +138,15 @@ export class ImageControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.item': {
data: {
type: 'object',
title: '远程上传请求成功后返回的结果数据'
title: '数据',
properties: {
item: {
type: 'object',
title: '远程上传请求成功后返回的结果数据'
}
}
}
}
}
@ -142,13 +160,19 @@ export class ImageControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.item': {
data: {
type: 'object',
title: '上传的文件'
},
'event.data.error': {
type: 'object',
title: '远程上传请求失败后返回的错误信息'
title: '数据',
properties: {
item: {
type: 'object',
title: '上传的文件'
},
error: {
type: 'object',
title: '远程上传请求失败后返回的错误信息'
}
}
}
}
}

View File

@ -53,9 +53,15 @@ export class KVControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
data: {
type: 'object',
title: '当前组合项的值'
title: '数据',
properties: {
value: {
type: 'string',
title: '组合项的值'
}
}
}
}
}
@ -64,22 +70,28 @@ export class KVControlPlugin extends BasePlugin {
{
eventName: 'delete',
eventLabel: '删除',
description: '删除组合项时触发',
description: '删除组合项',
dataSchema: [
{
type: 'object',
properties: {
'event.data.key': {
type: 'string',
title: '删除项的索引'
},
'event.data.value': {
type: 'string',
title: '当前组合项的值'
},
'event.data.item': {
data: {
type: 'object',
title: '被移除的项'
title: '数据',
properties: {
key: {
type: 'string',
title: '被删除的索引'
},
value: {
type: 'string',
title: '组合项的值'
},
item: {
type: 'object',
title: '被删除的项'
}
}
}
}
}

View File

@ -67,9 +67,15 @@ export class NumberControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '输入值'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'number',
title: '当前数值'
}
}
}
}
}
@ -83,9 +89,15 @@ export class NumberControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '当前值'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'number',
title: '当前数值'
}
}
}
}
}
@ -99,9 +111,15 @@ export class NumberControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '当前值'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'number',
title: '当前数值'
}
}
}
}
}

View File

@ -47,9 +47,15 @@ export class RangeControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '当前值'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'number',
title: '当前滑块值'
}
}
}
}
}
@ -63,9 +69,15 @@ export class RangeControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '滑块当前值'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'number',
title: '当前数值'
}
}
}
}
}
@ -79,9 +91,15 @@ export class RangeControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '滑块当前值'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'number',
title: '当前数值'
}
}
}
}
}

View File

@ -58,9 +58,15 @@ export class RateControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '评分值'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'number',
title: '当前分值'
}
}
}
}
}

View File

@ -296,13 +296,19 @@ export class TableControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'array',
title: '列表记录'
},
'event.data.index': {
type: 'array',
title: '新增行记录索引'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'array',
title: '列表记录'
},
index: {
type: 'array',
title: '新增索引'
}
}
}
}
}
@ -317,17 +323,23 @@ export class TableControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'array',
title: '列表记录'
},
'event.data.item': {
data: {
type: 'object',
title: '新增行记录'
},
'event.data.index': {
type: 'number',
title: '新增行记录索引'
title: '数据',
properties: {
value: {
type: 'array',
title: '列表记录'
},
item: {
type: 'object',
title: '新增行记录'
},
index: {
type: 'number',
title: '新增索引'
}
}
}
}
}
@ -342,17 +354,23 @@ export class TableControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'array',
title: '列表记录'
},
'event.data.item': {
data: {
type: 'object',
title: '新增行记录'
},
'event.data.index': {
type: 'number',
title: '新增行记录索引'
title: '数据',
properties: {
value: {
type: 'array',
title: '列表记录'
},
item: {
type: 'object',
title: '新增行记录'
},
index: {
type: 'number',
title: '新增索引'
}
}
}
}
}
@ -367,21 +385,27 @@ export class TableControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'array',
title: '列表记录'
},
'event.data.item': {
data: {
type: 'object',
title: '新增行记录'
},
'event.data.index': {
type: 'number',
title: '新增行记录索引'
},
'event.data.error': {
type: 'object',
title: '请求失败后接口返回的错误信息'
title: '数据',
properties: {
value: {
type: 'array',
title: '列表记录'
},
item: {
type: 'object',
title: '新增行记录'
},
index: {
type: 'number',
title: '新增索引'
},
error: {
type: 'object',
title: '请求失败后接口返回的错误信息'
}
}
}
}
}
@ -395,17 +419,23 @@ export class TableControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'array',
title: '列表记录'
},
'event.data.item': {
data: {
type: 'object',
title: '所在行记录'
},
'event.data.index': {
type: 'number',
title: '所在行记录索引'
title: '数据',
properties: {
value: {
type: 'array',
title: '列表记录'
},
item: {
type: 'object',
title: '所在行记录'
},
index: {
type: 'number',
title: '所在行记录索引'
}
}
}
}
}
@ -420,17 +450,23 @@ export class TableControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'array',
title: '列表记录'
},
'event.data.item': {
data: {
type: 'object',
title: '所在行记录'
},
'event.data.index': {
type: 'number',
title: '所在行记录索引'
title: '数据',
properties: {
value: {
type: 'array',
title: '列表记录'
},
item: {
type: 'object',
title: '所在行记录'
},
index: {
type: 'number',
title: '所在行记录索引'
}
}
}
}
}
@ -445,17 +481,23 @@ export class TableControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'array',
title: '列表记录'
},
'event.data.item': {
data: {
type: 'object',
title: '所在行记录'
},
'event.data.index': {
type: 'number',
title: '所在行记录索引'
title: '数据',
properties: {
value: {
type: 'array',
title: '列表记录'
},
item: {
type: 'object',
title: '所在行记录'
},
index: {
type: 'number',
title: '所在行记录索引'
}
}
}
}
}
@ -470,21 +512,27 @@ export class TableControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'array',
title: '列表记录'
},
'event.data.item': {
data: {
type: 'object',
title: '所在行记录'
},
'event.data.index': {
type: 'number',
title: '所在行记录索引'
},
'event.data.error': {
type: 'object',
title: '请求错误后返回的错误信息'
title: '数据',
properties: {
value: {
type: 'array',
title: '列表记录'
},
item: {
type: 'object',
title: '所在行记录'
},
index: {
type: 'number',
title: '所在行记录索引'
},
error: {
type: 'object',
title: '请求错误后返回的错误信息'
}
}
}
}
}
@ -498,17 +546,23 @@ export class TableControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'array',
title: '列表记录'
},
'event.data.item': {
data: {
type: 'object',
title: '所在行记录'
},
'event.data.index': {
type: 'object',
title: '所在行记录索引'
title: '数据',
properties: {
value: {
type: 'array',
title: '列表记录'
},
item: {
type: 'object',
title: '所在行记录'
},
index: {
type: 'object',
title: '所在行记录索引'
}
}
}
}
}
@ -522,17 +576,23 @@ export class TableControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'array',
title: '列表记录'
},
'event.data.item': {
data: {
type: 'object',
title: '所在行记录'
},
'event.data.index': {
type: 'object',
title: '所在行记录索引'
title: '数据',
properties: {
value: {
type: 'array',
title: '列表记录'
},
item: {
type: 'object',
title: '所在行记录'
},
index: {
type: 'object',
title: '所在行记录索引'
}
}
}
}
}
@ -546,21 +606,27 @@ export class TableControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'array',
title: '列表记录'
},
'event.data.item': {
data: {
type: 'object',
title: '所在行记录'
},
'event.data.index': {
type: 'object',
title: '所在行记录索引'
},
'event.data.error': {
type: 'object',
title: '请求失败后接口返回的错误信息'
title: '数据',
properties: {
value: {
type: 'array',
title: '列表记录'
},
item: {
type: 'object',
title: '所在行记录'
},
index: {
type: 'object',
title: '所在行记录索引'
},
error: {
type: 'object',
title: '请求失败后接口返回的错误信息'
}
}
}
}
}
@ -574,9 +640,15 @@ export class TableControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'array',
title: '列表记录'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'array',
title: '列表记录'
}
}
}
}
}

View File

@ -58,9 +58,15 @@ export class TagControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '选中值'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'array',
title: '当前标签值'
}
}
}
}
}
@ -74,17 +80,23 @@ export class TagControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '选中值'
},
'event.data.selectedItems': {
type: 'array',
title: '选中的项'
},
'event.data.items': {
type: 'array',
title: '选项集合'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '当前标签值'
},
selectedItems: {
type: 'array',
title: '选中的标签'
},
items: {
type: 'array',
title: '标签列表'
}
}
}
}
}
@ -98,13 +110,23 @@ export class TagControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '选中值'
},
'event.data.items': {
type: 'array',
title: '选项集合'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '当前标签值'
},
selectedItems: {
type: 'array',
title: '选中的标签'
},
items: {
type: 'array',
title: '标签列表'
}
}
}
}
}

View File

@ -80,9 +80,15 @@ export class TextControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '输入值'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '当前文本内容'
}
}
}
}
}
@ -96,9 +102,15 @@ export class TextControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '输入值'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '当前文本内容'
}
}
}
}
}
@ -112,9 +124,15 @@ export class TextControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '输入值'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '当前文本内容'
}
}
}
}
}

View File

@ -84,9 +84,15 @@ export class TreeControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '选中节点的值'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '变化的节点值'
}
}
}
}
}
@ -100,13 +106,19 @@ export class TreeControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
data: {
type: 'object',
title: '新增的节点信息'
},
'event.data.items': {
type: 'array',
title: '选项集合'
title: '数据',
properties: {
value: {
type: 'object',
title: '新增的节点信息'
},
items: {
type: 'array',
title: '选项集合'
}
}
}
}
}
@ -120,13 +132,19 @@ export class TreeControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
data: {
type: 'object',
title: '编辑的节点信息'
},
'event.data.items': {
type: 'array',
title: '选项集合'
title: '数据',
properties: {
value: {
type: 'object',
title: '编辑的节点信息'
},
items: {
type: 'array',
title: '选项集合'
}
}
}
}
}
@ -140,13 +158,19 @@ export class TreeControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
data: {
type: 'object',
title: '删除的节点信息'
},
'event.data.items': {
type: 'array',
title: '选项集合'
title: '数据',
properties: {
value: {
type: 'object',
title: '删除的节点信息'
},
items: {
type: 'array',
title: '选项集合'
}
}
}
}
}
@ -160,9 +184,15 @@ export class TreeControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
data: {
type: 'object',
title: 'deferApi 懒加载远程请求成功后返回的数据'
title: '数据',
properties: {
value: {
type: 'object',
title: 'deferApi 懒加载远程请求成功后返回的数据'
}
}
}
}
}
@ -190,18 +220,6 @@ export class TreeControlPlugin extends BasePlugin {
);
},
schema: getArgsWrapper(
/*
{
type: 'input-formula',
variables: '${variables}',
evalMode: false,
variableMode: 'tabs',
label: '展开层级',
size: 'lg',
name: 'openLevel',
mode: 'horizontal'
},
*/
getSchemaTpl('formulaControl', {
name: 'openLevel',
label: '展开层级',

View File

@ -63,9 +63,15 @@ export class ListControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '选中值'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '选中的值'
}
}
}
}
}

View File

@ -74,9 +74,15 @@ export class MatrixControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '选中值'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '选中的值'
}
}
}
}
}

View File

@ -121,9 +121,15 @@ export class NestedSelectControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '选中值'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '选中的值'
}
}
}
}
}
@ -137,9 +143,15 @@ export class NestedSelectControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '选中值'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '选中的值'
}
}
}
}
}
@ -153,9 +165,15 @@ export class NestedSelectControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '选中值'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '选中的值'
}
}
}
}
}

View File

@ -71,13 +71,19 @@ export class PickerControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '选中值'
},
'event.data.selectedItems': {
type: 'string',
title: '选中的行数据'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '选中的值'
},
selectedItems: {
type: 'string',
title: '选中的行记录'
}
}
}
}
}
@ -91,9 +97,15 @@ export class PickerControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.item': {
data: {
type: 'object',
title: '所点击的选项'
title: '数据',
properties: {
item: {
type: 'object',
title: '所点击的选项'
}
}
}
}
}

View File

@ -64,17 +64,23 @@ export class RadiosControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '选中值'
},
'event.data.selectedItems': {
data: {
type: 'object',
title: '选中的项'
},
'event.data.items': {
type: 'array',
title: '选项集合'
title: '数据',
properties: {
value: {
type: 'string',
title: '选中的值'
},
selectedItems: {
type: 'object',
title: '选中的项'
},
items: {
type: 'array',
title: '选项列表'
}
}
}
}
}

View File

@ -64,17 +64,23 @@ export class SelectControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '选中值'
},
'event.data.selectedItems': {
type: 'object', // 也可能是array
title: '选中的项'
},
'event.data.items': {
type: 'array',
title: '选项集合'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '选中的值'
},
selectedItems: {
type: 'object',
title: '选中的项'
},
items: {
type: 'array',
title: '选项列表'
}
}
}
}
}
@ -88,13 +94,19 @@ export class SelectControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '选中值'
},
'event.data.items': {
type: 'array',
title: '选项集合'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '选中的值'
},
items: {
type: 'array',
title: '选项列表'
}
}
}
}
}
@ -108,13 +120,19 @@ export class SelectControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '选中值'
},
'event.data.items': {
type: 'array',
title: '选项集合'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '选中的值'
},
items: {
type: 'array',
title: '选项列表'
}
}
}
}
}
@ -128,13 +146,19 @@ export class SelectControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
data: {
type: 'object',
title: '新增的选项'
},
'event.data.items': {
type: 'array',
title: '选项集合'
title: '数据',
properties: {
value: {
type: 'object',
title: '新增的选项'
},
items: {
type: 'array',
title: '选项列表'
}
}
}
}
}
@ -148,13 +172,19 @@ export class SelectControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
data: {
type: 'object',
title: '编辑的选项'
},
'event.data.items': {
type: 'array',
title: '选项集合'
title: '数据',
properties: {
value: {
type: 'object',
title: '编辑的选项'
},
items: {
type: 'array',
title: '选项列表'
}
}
}
}
}
@ -168,13 +198,19 @@ export class SelectControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
data: {
type: 'object',
title: '删除的选项'
},
'event.data.items': {
type: 'array',
title: '选项集合'
title: '数据',
properties: {
value: {
type: 'object',
title: '删除的选项'
},
items: {
type: 'array',
title: '选项列表'
}
}
}
}
}

View File

@ -54,9 +54,15 @@ export class SwitchControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '开关值'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '开关值'
}
}
}
}
}

View File

@ -142,13 +142,19 @@ export class TabsTransferPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '选中值'
},
'event.data.items': {
type: 'array',
title: '选项集合'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '选中的值'
},
items: {
type: 'array',
title: '选项列表'
}
}
}
}
}
@ -162,9 +168,15 @@ export class TabsTransferPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.key': {
type: 'string',
title: '当前激活的选项卡索引'
data: {
type: 'object',
title: '数据',
properties: {
key: {
type: 'string',
title: '激活的索引'
}
}
}
}
}

View File

@ -49,9 +49,15 @@ export class TextareaControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '输入值'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '当前文本内容'
}
}
}
}
}
@ -65,9 +71,15 @@ export class TextareaControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '输入值'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '当前文本内容'
}
}
}
}
}
@ -81,9 +93,15 @@ export class TextareaControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '输入值'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '当前的文本内容'
}
}
}
}
}

View File

@ -61,13 +61,19 @@ export class TransferPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '选中值'
},
'event.data.items': {
type: 'array',
title: '选项集合'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '选中的值'
},
items: {
type: 'array',
title: '选项列表'
}
}
}
}
}
@ -81,9 +87,15 @@ export class TransferPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.items': {
type: 'array',
title: '选项集合'
data: {
type: 'object',
title: '数据',
properties: {
items: {
type: 'array',
title: '选项列表'
}
}
}
}
}

View File

@ -77,9 +77,15 @@ export class TreeSelectControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '选中节点的值'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '选中的节点值'
}
}
}
}
}
@ -93,13 +99,19 @@ export class TreeSelectControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
data: {
type: 'object',
title: '新增的选项信息'
},
'event.data.items': {
type: 'array',
title: '选项集合'
title: '数据',
properties: {
value: {
type: 'object',
title: '新增的选项'
},
items: {
type: 'array',
title: '选项列表'
}
}
}
}
}
@ -113,13 +125,19 @@ export class TreeSelectControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
data: {
type: 'object',
title: '编辑的选项信息'
},
'event.data.items': {
type: 'array',
title: '选项集合'
title: '数据',
properties: {
value: {
type: 'object',
title: '编辑的选项'
},
items: {
type: 'array',
title: '选项列表'
}
}
}
}
}
@ -133,13 +151,19 @@ export class TreeSelectControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
data: {
type: 'object',
title: '删除的选项信息'
},
'event.data.items': {
type: 'array',
title: '选项集合'
title: '数据',
properties: {
value: {
type: 'object',
title: '删除的选项'
},
items: {
type: 'array',
title: '选项列表'
}
}
}
}
}
@ -169,9 +193,15 @@ export class TreeSelectControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '选中值'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '当前选中的值'
}
}
}
}
}
@ -185,9 +215,15 @@ export class TreeSelectControlPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '选中值'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '当前选中的值'
}
}
}
}
}

View File

@ -43,9 +43,15 @@ export class IconPlugin extends BasePlugin {
{
type: 'object',
properties: {
nativeEvent: {
context: {
type: 'object',
title: '鼠标事件对象'
title: '上下文',
properties: {
nativeEvent: {
type: 'object',
title: '鼠标事件对象'
}
}
}
}
}
@ -59,9 +65,15 @@ export class IconPlugin extends BasePlugin {
{
type: 'object',
properties: {
nativeEvent: {
context: {
type: 'object',
title: '鼠标事件对象'
title: '上下文',
properties: {
nativeEvent: {
type: 'object',
title: '鼠标事件对象'
}
}
}
}
}
@ -75,9 +87,15 @@ export class IconPlugin extends BasePlugin {
{
type: 'object',
properties: {
nativeEvent: {
context: {
type: 'object',
title: '鼠标事件对象'
title: '上下文',
properties: {
nativeEvent: {
type: 'object',
title: '鼠标事件对象'
}
}
}
}
}

View File

@ -166,9 +166,10 @@ export class NavPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data': {
data: {
type: 'object',
title: '当前表单数据'
title: '数据',
description: '当前数据域,可以通过.字段名读取对应的值'
}
}
}
@ -182,9 +183,9 @@ export class NavPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data': {
data: {
type: 'object',
title: '当前表单数据'
title: '数据'
}
}
}
@ -198,9 +199,9 @@ export class NavPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data': {
data: {
type: 'object',
title: '当前表单数据'
title: '数据'
}
}
}
@ -214,9 +215,9 @@ export class NavPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data': {
data: {
type: 'object',
title: '当前表单数据'
title: '数据'
}
}
}
@ -230,9 +231,9 @@ export class NavPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data': {
data: {
type: 'object',
title: '当前表单数据'
title: '数据'
}
}
}

View File

@ -11,6 +11,7 @@ import {RendererPluginAction, RendererPluginEvent} from 'amis-editor-core';
import type {SchemaObject} from 'amis';
import {tipedLabel} from 'amis-editor-core';
import {jsonToJsonSchema, EditorNodeType} from 'amis-editor-core';
import omit from 'lodash/omit';
export class PagePlugin extends BasePlugin {
static id = 'PagePlugin';
@ -58,9 +59,10 @@ export class PagePlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data': {
data: {
type: 'object',
title: '当前数据域'
title: '数据',
description: '当前数据域,可以通过.字段名读取对应的值'
}
}
}
@ -74,17 +76,23 @@ export class PagePlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.responseData': {
data: {
type: 'object',
title: '响应数据'
},
'event.data.responseStatus': {
type: 'number',
title: '响应状态(0表示成功)'
},
'event.data.responseMsg': {
type: 'string',
title: '响应消息'
title: '数据',
properties: {
responseData: {
type: 'object',
title: '响应数据'
},
responseStatus: {
type: 'number',
title: '响应状态(0表示成功)'
},
responseMsg: {
type: 'string',
title: '响应消息'
}
}
}
}
}
@ -356,17 +364,22 @@ export class PagePlugin extends BasePlugin {
];
};
rendererBeforeDispatchEvent(node: EditorNodeType, e: any, data: any) {
if (e === 'init') {
const scope = this.manager.dataSchema.getScope(`${node.id}-${node.type}`);
const jsonschema: any = {
$id: 'pageInitData',
...jsonToJsonSchema(data)
};
async buildDataSchemas(
node: EditorNodeType,
region?: EditorNodeType,
trigger?: EditorNodeType
) {
const scope = this.manager.dataSchema.getScope(`${node.id}-${node.type}`);
let jsonschema = {
$id: 'pageStaticData',
...jsonToJsonSchema(omit(node.schema.data, '$$id'))
};
scope?.removeSchema(jsonschema.$id);
scope?.addSchema(jsonschema);
}
scope?.removeSchema(jsonschema.$id);
scope?.addSchema(jsonschema);
}
rendererBeforeDispatchEvent(node: EditorNodeType, e: any, data: any) {
if (e === 'inited') {
const scope = this.manager.dataSchema.getScope(`${node.id}-${node.type}`);
const jsonschema: any = {

View File

@ -49,14 +49,6 @@ export class PaginationPlugin extends BasePlugin {
};
panelTitle = '分页器';
// 事件定义
events: RendererPluginEvent[] = [
{
eventName: 'pageChange',
eventLabel: '分页改变',
description: '分页改变'
}
];
panelJustify = true;
panelBodyCreator = (context: BaseEventContext) => {

View File

@ -47,9 +47,15 @@ export class PlainPlugin extends BasePlugin {
{
type: 'object',
properties: {
nativeEvent: {
context: {
type: 'object',
title: '鼠标事件对象'
title: '上下文',
properties: {
nativeEvent: {
type: 'object',
title: '鼠标事件对象'
}
}
}
}
}
@ -63,9 +69,15 @@ export class PlainPlugin extends BasePlugin {
{
type: 'object',
properties: {
nativeEvent: {
context: {
type: 'object',
title: '鼠标事件对象'
title: '上下文',
properties: {
nativeEvent: {
type: 'object',
title: '鼠标事件对象'
}
}
}
}
}
@ -79,9 +91,15 @@ export class PlainPlugin extends BasePlugin {
{
type: 'object',
properties: {
nativeEvent: {
context: {
type: 'object',
title: '鼠标事件对象'
title: '上下文',
properties: {
nativeEvent: {
type: 'object',
title: '鼠标事件对象'
}
}
}
}
}

View File

@ -55,9 +55,15 @@ export class SearchBoxPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '搜索内容'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '搜索值'
}
}
}
}
}
@ -71,9 +77,15 @@ export class SearchBoxPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '搜索内容'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '搜索值'
}
}
}
}
}
@ -87,9 +99,15 @@ export class SearchBoxPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '搜索内容'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '搜索值'
}
}
}
}
}
@ -103,9 +121,15 @@ export class SearchBoxPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '搜索内容'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '搜索值'
}
}
}
}
}

View File

@ -59,9 +59,10 @@ export class ServicePlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data': {
data: {
type: 'object',
title: '当前数据域'
title: '数据',
description: '当前数据域,可以通过.字段名读取对应的值'
}
}
}
@ -75,17 +76,23 @@ export class ServicePlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.responseData': {
data: {
type: 'object',
title: '响应数据'
},
'event.data.responseStatus': {
type: 'object',
title: '响应状态'
},
'event.data.responseMsg': {
type: 'object',
title: '响应消息'
title: '数据',
properties: {
responseData: {
type: 'object',
title: '响应数据'
},
responseStatus: {
type: 'number',
title: '响应状态(0表示成功)'
},
responseMsg: {
type: 'string',
title: '响应消息'
}
}
}
}
}
@ -99,17 +106,23 @@ export class ServicePlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.responseData': {
data: {
type: 'object',
title: '响应数据'
},
'event.data.responseStatus': {
type: 'number',
title: '响应状态(0表示成功)'
},
'event.data.responseMsg': {
type: 'string',
title: '响应消息'
title: '数据',
properties: {
responseData: {
type: 'object',
title: '响应数据'
},
responseStatus: {
type: 'number',
title: '响应状态(0表示成功)'
},
responseMsg: {
type: 'string',
title: '响应消息'
}
}
}
}
}

View File

@ -22,7 +22,7 @@ import {
import {defaultValue, getSchemaTpl, tipedLabel} from 'amis-editor-core';
import {mockValue} from 'amis-editor-core';
import {EditorNodeType} from 'amis-editor-core';
import type {SchemaObject} from 'amis';
import type {DataScope, SchemaObject} from 'amis';
import {
getEventControlConfig,
getArgsWrapper
@ -180,13 +180,19 @@ export class TablePlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.selectedItems': {
type: 'array',
title: '已选择行'
},
'event.data.unSelectedItems': {
type: 'array',
title: '未选择行'
data: {
type: 'object',
title: '数据',
properties: {
selectedItems: {
type: 'array',
title: '已选行记录'
},
unSelectedItems: {
type: 'array',
title: '未选行记录'
}
}
}
}
}
@ -200,13 +206,19 @@ export class TablePlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.orderBy': {
type: 'string',
title: '列排序列名'
},
'event.data.orderDir': {
type: 'string',
title: '列排序值'
data: {
type: 'object',
title: '数据',
properties: {
orderBy: {
type: 'string',
title: '列名'
},
orderDir: {
type: 'string',
title: '排序值'
}
}
}
}
}
@ -220,13 +232,19 @@ export class TablePlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.filterName': {
type: 'string',
title: '列筛选列名'
},
'event.data.filterValue': {
type: 'string',
title: '列筛选值'
data: {
type: 'object',
title: '数据',
properties: {
filterName: {
type: 'string',
title: '列名'
},
filterValue: {
type: 'string',
title: '筛选值'
}
}
}
}
}
@ -240,13 +258,19 @@ export class TablePlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.searchName': {
type: 'string',
title: '列搜索列名'
},
'event.data.searchValue': {
data: {
type: 'object',
title: '列搜索数据'
title: '数据',
properties: {
searchName: {
type: 'string',
title: '列名'
},
searchValue: {
type: 'object',
title: '搜索值'
}
}
}
}
}
@ -260,9 +284,15 @@ export class TablePlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.movedItems': {
type: 'array',
title: '已排序数据'
data: {
type: 'object',
title: '数据',
properties: {
movedItems: {
type: 'array',
title: '已排序记录'
}
}
}
}
}
@ -276,9 +306,15 @@ export class TablePlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.columns': {
type: 'array',
title: '当前显示的列配置数据'
data: {
type: 'object',
title: '数据',
properties: {
columns: {
type: 'array',
title: '当前显示的列配置'
}
}
}
}
}
@ -292,13 +328,19 @@ export class TablePlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.item': {
data: {
type: 'object',
title: '当前行数据'
},
'event.data.index': {
type: 'number',
title: '当前行索引'
title: '数据',
properties: {
item: {
type: 'object',
title: '当前行记录'
},
index: {
type: 'number',
title: '当前行索引'
}
}
}
}
}
@ -312,13 +354,19 @@ export class TablePlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.item': {
data: {
type: 'object',
title: '当前行数据'
},
'event.data.index': {
type: 'number',
title: '当前行索引'
title: '数据',
properties: {
item: {
type: 'object',
title: '当前行记录'
},
index: {
type: 'number',
title: '当前行索引'
}
}
}
}
}
@ -332,13 +380,19 @@ export class TablePlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.item': {
data: {
type: 'object',
title: '当前行数据'
},
'event.data.index': {
type: 'number',
title: '当前行索引'
title: '数据',
properties: {
item: {
type: 'object',
title: '当前行记录'
},
index: {
type: 'number',
title: '当前行索引'
}
}
}
}
}
@ -353,18 +407,6 @@ export class TablePlugin extends BasePlugin {
description: '设置表格的选中项',
innerArgs: ['selected'],
schema: getArgsWrapper([
/*
{
type: 'input-formula',
variables: '${variables}',
evalMode: false,
variableMode: 'tabs',
label: '选中项',
size: 'lg',
name: 'selected',
mode: 'horizontal'
}
*/
getSchemaTpl('formulaControl', {
name: 'selected',
label: '选中项',
@ -720,7 +762,7 @@ export class TablePlugin extends BasePlugin {
region?: EditorNodeType,
trigger?: EditorNodeType
) {
const itemsSchema: any = {
let itemsSchema: any = {
$id: 'tableRow',
type: 'object',
properties: {}
@ -744,7 +786,7 @@ export class TablePlugin extends BasePlugin {
// }
// 一期先简单处理上面todo实现之后这里可以废弃
// table 无法根据source确定异步数据来源因此不能在table层做异步数据列的收集
// 收集table配置的列成员
for (let current of node.schema?.columns) {
if (current.name) {
itemsSchema.properties[current.name] = {
@ -754,18 +796,56 @@ export class TablePlugin extends BasePlugin {
}
}
// 收集source绑定的列表成员
if (node.schema.source) {
const sourceMatch1 = node.schema.source.match(/\$\{(.*?)\}/);
const sourceMatch2 = node.schema.source.match(/\$(\w+$)/);
const source = sourceMatch1
? sourceMatch1[1]
: sourceMatch2
? sourceMatch2[1]
: '';
let scope: any = this.manager.dataSchema.getScope(
`${node.info.id}-${node.info.type}`
);
while (scope) {
const rowMembers: any = scope.schemas.find(
(item: any) => item.properties?.[source]
);
if (rowMembers) {
itemsSchema = {
...itemsSchema,
properties: {
...itemsSchema.properties,
...(rowMembers.properties?.[source] as any)?.items?.properties
}
};
}
scope = rowMembers ? undefined : scope.parent;
}
}
if (region?.region === 'columns') {
return itemsSchema;
}
let cellProperties = {};
let cellProperties: any = {};
if (trigger) {
const isColumnChild = someTree(
columns?.children,
item => item.id === trigger.id
);
isColumnChild && (cellProperties = itemsSchema.properties);
if (isColumnChild) {
Object.keys(itemsSchema.properties).map(key => {
cellProperties[key] = {
...itemsSchema.properties[key],
group: '当前行记录'
};
});
}
}
return {
@ -780,13 +860,13 @@ export class TablePlugin extends BasePlugin {
},
selectedItems: {
type: 'array',
title: '已选中行'
// items: itemsSchema
title: '已选中行',
items: itemsSchema
},
unSelectedItems: {
type: 'array',
title: '未选中行'
// items: itemsSchema
title: '未选中行',
items: itemsSchema
}
}
};

View File

@ -167,13 +167,19 @@ export class Table2Plugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.selectedItems': {
type: 'array',
title: '已选择行'
},
'event.data.unSelectedItems': {
type: 'array',
title: '未选择行'
data: {
type: 'object',
title: '数据',
properties: {
selectedItems: {
type: 'array',
title: '已选行记录'
},
unSelectedItems: {
type: 'array',
title: '未选行记录'
}
}
}
}
}
@ -187,13 +193,19 @@ export class Table2Plugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.orderBy': {
type: 'string',
title: '列排序列名'
},
'event.data.orderDir': {
type: 'string',
title: '列排序值'
data: {
type: 'object',
title: '数据',
properties: {
orderBy: {
type: 'string',
title: '列名'
},
orderDir: {
type: 'string',
title: '排序值'
}
}
}
}
}
@ -207,13 +219,19 @@ export class Table2Plugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.filterName': {
type: 'string',
title: '列筛选列名'
},
'event.data.filterValue': {
type: 'string',
title: '列筛选值'
data: {
type: 'object',
title: '数据',
properties: {
filterName: {
type: 'string',
title: '列名'
},
filterValue: {
type: 'string',
title: '筛选值'
}
}
}
}
}
@ -227,13 +245,19 @@ export class Table2Plugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.searchName': {
type: 'string',
title: '列搜索列名'
},
'event.data.searchValue': {
data: {
type: 'object',
title: '列搜索数据'
title: '数据',
properties: {
searchName: {
type: 'string',
title: '列名'
},
searchValue: {
type: 'object',
title: '搜索值'
}
}
}
}
}
@ -247,9 +271,15 @@ export class Table2Plugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.movedItems': {
type: 'array',
title: '已排序数据'
data: {
type: 'object',
title: '数据',
properties: {
movedItems: {
type: 'array',
title: '已排序记录'
}
}
}
}
}
@ -263,9 +293,15 @@ export class Table2Plugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.columns': {
type: 'array',
title: '当前显示的列配置数据'
data: {
type: 'object',
title: '数据',
properties: {
columns: {
type: 'array',
title: '当前显示的列配置'
}
}
}
}
}
@ -279,9 +315,71 @@ export class Table2Plugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.item': {
data: {
type: 'object',
title: '行点击数据'
title: '数据',
properties: {
item: {
type: 'object',
title: '当前行记录'
},
index: {
type: 'number',
title: '当前行索引'
}
}
}
}
}
]
},
{
eventName: 'rowMouseEnter',
eventLabel: '鼠标移入行事件',
description: '移入整行时触发',
dataSchema: [
{
type: 'object',
properties: {
data: {
type: 'object',
title: '数据',
properties: {
item: {
type: 'object',
title: '当前行记录'
},
index: {
type: 'number',
title: '当前行索引'
}
}
}
}
}
]
},
{
eventName: 'rowMouseLeave',
eventLabel: '鼠标移出行事件',
description: '移出整行时触发',
dataSchema: [
{
type: 'object',
properties: {
data: {
type: 'object',
title: '数据',
properties: {
item: {
type: 'object',
title: '当前行记录'
},
index: {
type: 'number',
title: '当前行索引'
}
}
}
}
}
@ -295,18 +393,6 @@ export class Table2Plugin extends BasePlugin {
actionLabel: '设置选中项',
description: '设置表格的选中项',
schema: getArgsWrapper([
/*
{
type: 'input-formula',
variables: '${variables}',
evalMode: false,
variableMode: 'tabs',
label: '选中项',
size: 'lg',
name: 'selected',
mode: 'horizontal'
}
*/
getSchemaTpl('formulaControl', {
name: 'selected',
label: '选中项',

View File

@ -75,9 +75,15 @@ export class TabsPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.value': {
type: 'string',
title: '选项卡索引'
data: {
type: 'object',
title: '数据',
properties: {
value: {
type: 'string',
title: '选项卡索引'
}
}
}
}
}
@ -103,18 +109,6 @@ export class TabsPlugin extends BasePlugin {
);
},
schema: getArgsWrapper(
/*
{
type: 'input-formula',
variables: '${variables}',
evalMode: false,
variableMode: 'tabs',
label: '激活项',
size: 'lg',
name: 'activeKey',
mode: 'horizontal'
}
*/
getSchemaTpl('formulaControl', {
name: 'activeKey',
label: '激活项',

View File

@ -56,13 +56,25 @@ export class TagPlugin extends BasePlugin {
{
type: 'object',
properties: {
nativeEvent: {
context: {
type: 'object',
title: '鼠标事件对象'
title: '上下文',
properties: {
nativeEvent: {
type: 'object',
title: '鼠标事件对象'
}
}
},
label: {
type: 'string',
title: '标签名称'
data: {
type: 'object',
title: '数据',
properties: {
label: {
type: 'object',
title: '标签名称'
}
}
}
}
}
@ -76,13 +88,25 @@ export class TagPlugin extends BasePlugin {
{
type: 'object',
properties: {
nativeEvent: {
context: {
type: 'object',
title: '鼠标事件对象'
title: '上下文',
properties: {
nativeEvent: {
type: 'object',
title: '鼠标事件对象'
}
}
},
label: {
type: 'string',
title: '标签名称'
data: {
type: 'object',
title: '数据',
properties: {
label: {
type: 'object',
title: '标签名称'
}
}
}
}
}
@ -96,13 +120,25 @@ export class TagPlugin extends BasePlugin {
{
type: 'object',
properties: {
nativeEvent: {
context: {
type: 'object',
title: '鼠标事件对象'
title: '上下文',
properties: {
nativeEvent: {
type: 'object',
title: '鼠标事件对象'
}
}
},
label: {
type: 'string',
title: '标签名称'
data: {
type: 'object',
title: '数据',
properties: {
label: {
type: 'object',
title: '标签名称'
}
}
}
}
}
@ -116,13 +152,25 @@ export class TagPlugin extends BasePlugin {
{
type: 'object',
properties: {
nativeEvent: {
context: {
type: 'object',
title: '鼠标事件对象'
title: '上下文',
properties: {
nativeEvent: {
type: 'object',
title: '鼠标事件对象'
}
}
},
label: {
type: 'string',
title: '标签名称'
data: {
type: 'object',
title: '数据',
properties: {
label: {
type: 'object',
title: '标签名称'
}
}
}
}
}

View File

@ -30,9 +30,6 @@ export class TimelinePlugin extends BasePlugin {
...this.scaffold
};
// TODO 事件定义
// events = [];
panelTitle = '时间轴';
panelJustify = true;
panelBodyCreator = (context: BaseEventContext) =>

View File

@ -145,9 +145,15 @@ export class TplPlugin extends BasePlugin {
{
type: 'object',
properties: {
nativeEvent: {
context: {
type: 'object',
title: '鼠标事件对象'
title: '上下文',
properties: {
nativeEvent: {
type: 'object',
title: '鼠标事件对象'
}
}
}
}
}
@ -161,9 +167,15 @@ export class TplPlugin extends BasePlugin {
{
type: 'object',
properties: {
nativeEvent: {
context: {
type: 'object',
title: '鼠标事件对象'
title: '上下文',
properties: {
nativeEvent: {
type: 'object',
title: '鼠标事件对象'
}
}
}
}
}
@ -177,9 +189,15 @@ export class TplPlugin extends BasePlugin {
{
type: 'object',
properties: {
nativeEvent: {
context: {
type: 'object',
title: '鼠标事件对象'
title: '上下文',
properties: {
nativeEvent: {
type: 'object',
title: '鼠标事件对象'
}
}
}
}
}

View File

@ -97,17 +97,23 @@ export class WizardPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.responseData': {
data: {
type: 'object',
title: '响应数据'
},
'event.data.responseStatus': {
type: 'number',
title: '响应状态(0表示成功)'
},
'event.data.responseMsg': {
type: 'string',
title: '响应消息'
title: '数据',
properties: {
responseData: {
type: 'object',
title: '响应数据'
},
responseStatus: {
type: 'number',
title: '响应状态(0表示成功)'
},
responseMsg: {
type: 'string',
title: '响应消息'
}
}
}
}
}
@ -121,9 +127,10 @@ export class WizardPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data': {
data: {
type: 'object',
title: '提交的表单数据'
title: '数据',
description: '当前数据域,可以通过.字段名读取对应的值'
}
}
}
@ -137,9 +144,15 @@ export class WizardPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.step': {
type: 'string',
title: '步骤索引'
data: {
type: 'object',
title: '数据',
properties: {
step: {
type: 'string',
title: '步骤索引'
}
}
}
}
}
@ -153,9 +166,9 @@ export class WizardPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data': {
data: {
type: 'object',
title: '当前表单数据'
title: '数据'
}
}
}
@ -169,9 +182,15 @@ export class WizardPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data': {
data: {
type: 'object',
title: '提交成功后返回的数据'
title: '数据',
properties: {
result: {
type: 'object',
title: '提交成功后返回的数据'
}
}
}
}
}
@ -185,9 +204,15 @@ export class WizardPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.error': {
data: {
type: 'object',
title: '提交失败后返回的错误信息'
title: '数据',
properties: {
error: {
type: 'object',
title: '提交失败后返回的错误信息'
}
}
}
}
}
@ -206,9 +231,15 @@ export class WizardPlugin extends BasePlugin {
{
type: 'object',
properties: {
'event.data.error': {
data: {
type: 'object',
title: '单个步骤提交失败后返回的错误信息'
title: '数据',
properties: {
error: {
type: 'object',
title: '单个步骤提交失败后返回的错误信息'
}
}
}
}
}
@ -264,19 +295,6 @@ export class WizardPlugin extends BasePlugin {
);
},
schema: getArgsWrapper([
/*
{
type: 'input-formula',
variables: '${variables}',
evalMode: false,
required: true,
variableMode: 'tabs',
label: '目标步骤',
size: 'lg',
name: 'step',
mode: 'horizontal'
}
*/
getSchemaTpl('formulaControl', {
name: 'step',
label: '目标步骤',

View File

@ -24,7 +24,7 @@ class DataPickerControl extends React.Component<FormControlProps> {
...item,
selectMode: 'tree'
})),
variableMode: 'tabs'
variableMode: 'tree'
};
}

View File

@ -45,7 +45,7 @@ export default class ExpressionFormulaControl extends React.Component<
ExpressionFormulaControlState
> {
static defaultProps: Partial<ExpressionFormulaControlProps> = {
variableMode: 'tabs',
variableMode: 'tree',
requiredDataPropsVariables: false,
evalMode: true
};
@ -80,20 +80,9 @@ export default class ExpressionFormulaControl extends React.Component<
});
}
);
const variablesArr = await getVariables(this);
this.setState({
variables: variablesArr
});
}
async componentDidUpdate(prevProps: ExpressionFormulaControlProps) {
if (this.props.data !== prevProps.data) {
const variablesArr = await getVariables(this);
this.setState({
variables: variablesArr
});
}
if (prevProps.value !== this.props.value) {
this.initFormulaPickerValue(this.props.value);
}
@ -131,8 +120,21 @@ export default class ExpressionFormulaControl extends React.Component<
this.props?.onChange?.('');
}
@autobind
async handleOnClick(
e: React.MouseEvent,
onClick: (e: React.MouseEvent) => void
) {
const variablesArr = await getVariables(this);
this.setState({
variables: variablesArr
});
return onClick?.(e);
}
render() {
const {value, className, variableMode, header, ...rest} = this.props;
const {value, className, variableMode, header, size, ...rest} = this.props;
const {formulaPickerValue, variables} = this.state;
const highlightValue = FormulaEditor.highlightValue(
@ -144,7 +146,6 @@ export default class ExpressionFormulaControl extends React.Component<
// 自身字段
const selfName = this.props?.data?.name;
return (
<div className={cx('ae-ExpressionFormulaControl', className)}>
<PickerContainer
@ -171,9 +172,9 @@ export default class ExpressionFormulaControl extends React.Component<
}}
value={formulaPickerValue}
onConfirm={this.handleConfirm}
size="md"
size={size ?? 'lg'}
>
{({onClick}: {onClick: (e: React.MouseEvent) => void}) =>
{({onClick}: {onClick: (e: React.MouseEvent) => any}) =>
formulaPickerValue ? (
<Button
className="btn-configured"
@ -185,7 +186,7 @@ export default class ExpressionFormulaControl extends React.Component<
tooltipClassName: 'btn-configured-tooltip',
children: () => renderFormulaValue(highlightValue)
}}
onClick={onClick}
onClick={e => this.handleOnClick(e, onClick)}
>
{renderFormulaValue(highlightValue)}
<Icon
@ -196,7 +197,10 @@ export default class ExpressionFormulaControl extends React.Component<
</Button>
) : (
<>
<Button className="btn-set-expression" onClick={onClick}>
<Button
className="btn-set-expression"
onClick={e => this.handleOnClick(e, onClick)}
>
</Button>
</>

View File

@ -176,7 +176,7 @@ export default class FormulaControl extends React.Component<
super(props);
this.state = {
variables: [],
variableMode: 'tabs',
variableMode: 'tree',
formulaPickerOpen: false,
loading: false
};
@ -197,20 +197,6 @@ export default class FormulaControl extends React.Component<
});
}
);
const variablesArr = await getVariables(this);
this.setState({
variables: variablesArr
});
}
async componentDidUpdate(prevProps: FormulaControlProps) {
if (this.props.data !== prevProps.data) {
const variablesArr = await getVariables(this);
this.setState({
variables: variablesArr
});
}
}
componentWillUnmount() {
@ -399,6 +385,9 @@ export default class FormulaControl extends React.Component<
const variables = await getVariables(this);
this.setState({variables});
}
} else {
const variables = await getVariables(this);
this.setState({variables});
}
} catch (error) {
console.error('[amis-editor] onFormulaEditorOpen failed: ', error?.stack);

View File

@ -635,14 +635,13 @@ export default class OptionControl extends React.Component<
}
]
},
{
type: 'ae-expressionFormulaControl',
getSchemaTpl('expressionFormulaControl', {
name: 'optionHiddenOn',
label: '隐藏',
labelClassName: 'ae-OptionControlItem-EditLabel',
valueClassName: 'ae-OptionControlItem-EditValue',
onChange: (v: string) => this.handleHiddenValueChange(index, v)
},
}),
{
type: i18nEnabled ? 'input-text-i18n' : 'input-text',
placeholder: '请输入角标文本',

View File

@ -76,7 +76,7 @@ export class TplFormulaControl extends React.Component<
TplFormulaControlState
> {
static defaultProps: Partial<TplFormulaControlProps> = {
variableMode: 'tabs',
variableMode: 'tree',
requiredDataPropsVariables: false,
placeholder: '请输入'
};
@ -119,10 +119,6 @@ export class TplFormulaControl extends React.Component<
}
);
const variablesArr = await getVariables(this);
this.setState({
variables: variablesArr
});
if (this.tooltipRef.current) {
this.tooltipRef.current.addEventListener(
'mouseleave',
@ -138,15 +134,6 @@ export class TplFormulaControl extends React.Component<
}
}
async componentDidUpdate(prevProps: TplFormulaControlProps) {
if (this.props.data !== prevProps.data) {
const variablesArr = await getVariables(this);
this.setState({
variables: variablesArr
});
}
}
componentWillUnmount() {
if (this.tooltipRef.current) {
this.tooltipRef.current.removeEventListener(
@ -161,15 +148,6 @@ export class TplFormulaControl extends React.Component<
this.unReaction?.();
}
@autobind
onExpressionClick(expression: string, brace?: Array<CodeMirror.Position>) {
this.setState({
formulaPickerValue: expression,
formulaPickerOpen: true,
expressionBrace: brace
});
}
@autobind
onExpressionMouseEnter(
e: MouseEvent,
@ -332,6 +310,9 @@ export class TplFormulaControl extends React.Component<
const variables = await getVariables(this);
this.setState({variables});
}
} else {
const variables = await getVariables(this);
this.setState({variables});
}
} catch (error) {
console.error('[amis-editor] onFormulaEditorOpen failed: ', error?.stack);
@ -341,16 +322,22 @@ export class TplFormulaControl extends React.Component<
}
@autobind
async handleFormulaClick(e: React.MouseEvent, type?: string) {
async handleFormulaClick() {
try {
await this.beforeFormulaEditorOpen();
} catch (error) {}
this.setState({
formulaPickerOpen: true,
formulaPickerValue: '',
expressionBrace: undefined
formulaPickerOpen: true
});
if (type !== 'update') {
this.setState({
formulaPickerValue: '',
expressionBrace: undefined
});
}
}
@autobind
@ -366,7 +353,6 @@ export class TplFormulaControl extends React.Component<
const variables = this.props.variables || this.state.variables;
this.editorPlugin = new FormulaPlugin(editor, {
getProps: () => ({...this.props, variables}),
onExpressionClick: this.onExpressionClick,
onExpressionMouseEnter: this.onExpressionMouseEnter,
showPopover: false,
showClearIcon: true
@ -467,9 +453,7 @@ export class TplFormulaControl extends React.Component<
className="ae-TplFormulaControl-tooltip"
style={tooltipStyle}
ref={this.tooltipRef}
onClick={() => {
this.setState({formulaPickerOpen: true});
}}
onClick={e => this.handleFormulaClick(e, 'update')}
></div>
</TooltipWrapper>

View File

@ -295,22 +295,6 @@ export const ACTION_TYPE_TREE = (manager: any): RendererPluginAction[] => {
type: 'wrapper',
className: 'p-none',
body: [
/**
{
label: '页面地址',
type: 'input-formula',
variables: '${variables}',
evalMode: false,
variableMode: 'tabs',
inputMode: 'input-group',
name: 'url',
placeholder: 'http://',
mode: 'horizontal',
size: 'lg',
required: true,
visibleOn: 'data.actionType === "url"'
},
*/
getSchemaTpl('textareaFormulaControl', {
name: 'url',
label: '页面地址',
@ -334,22 +318,9 @@ export const ACTION_TYPE_TREE = (manager: any): RendererPluginAction[] => {
placeholder: '参数名',
type: 'input-text'
},
/**
{
name: 'val',
placeholder: '参数值',
type: 'input-formula',
variables: '${variables}',
evalMode: false,
variableMode: 'tabs',
inputMode: 'input-group',
size: 'xs'
},
*/
getSchemaTpl('formulaControl', {
variables: '${variables}',
name: 'val',
variableMode: 'tabs',
placeholder: '参数值'
})
]
@ -629,20 +600,6 @@ export const ACTION_TYPE_TREE = (manager: any): RendererPluginAction[] => {
level: 'default'
}))
},
/*
{
name: 'msg',
label: '消息内容',
mode: 'horizontal',
type: 'input-formula',
variables: '${variables}',
evalMode: false,
variableMode: 'tabs',
inputMode: 'input-group',
size: 'lg',
required: true
},
*/
getSchemaTpl('textareaFormulaControl', {
name: 'msg',
label: '消息内容',
@ -651,19 +608,6 @@ export const ACTION_TYPE_TREE = (manager: any): RendererPluginAction[] => {
size: 'lg',
required: true
}),
/*
{
name: 'title',
type: 'input-formula',
variables: '${variables}',
evalMode: false,
variableMode: 'tabs',
inputMode: 'input-group',
label: '标题内容',
size: 'lg',
mode: 'horizontal'
},
*/
getSchemaTpl('textareaFormulaControl', {
name: 'title',
label: '标题内容',
@ -671,19 +615,6 @@ export const ACTION_TYPE_TREE = (manager: any): RendererPluginAction[] => {
mode: 'horizontal',
size: 'lg'
}),
/*
{
name: 'timeout',
type: 'input-formula',
variables: '${variables}',
evalMode: false,
variableMode: 'tabs',
inputMode: 'input-group',
label: '持续时间(ms)',
size: 'lg',
mode: 'horizontal'
},
*/
getSchemaTpl('formulaControl', {
name: 'timeout',
label: '持续时间(ms)',
@ -834,16 +765,17 @@ export const ACTION_TYPE_TREE = (manager: any): RendererPluginAction[] => {
outputVarDataSchema: [
{
type: 'object',
title: 'responseResult',
properties: {
'event.data.${outputVar}.responseData': {
responseData: {
type: 'object',
title: '数据'
title: '响应数据'
},
'event.data.${outputVar}.responseStatus': {
responseStatus: {
type: 'number',
title: '状态标识'
},
'event.data.${outputVar}.responseMsg': {
responseMsg: {
type: 'string',
title: '提示信息'
}
@ -1242,21 +1174,6 @@ export const ACTION_TYPE_TREE = (manager: any): RendererPluginAction[] => {
form.setValueByName('__valueInput', undefined);
}
},
/*
{
name: '__valueInput',
type: 'input-formula',
variables: '${variables}',
evalMode: false,
required: true,
variableMode: 'tabs',
inputMode: 'input-group',
label: '',
size: 'lg',
mode: 'horizontal',
visibleOn: `data.__addParam && data.__customData && data.__containerType === "all" && data.actionType === "reload" && data.__isScopeContainer`
},
*/
getSchemaTpl('formulaControl', {
name: '__valueInput',
label: '',
@ -1286,17 +1203,6 @@ export const ACTION_TYPE_TREE = (manager: any): RendererPluginAction[] => {
valueField: 'value',
required: true
},
/*
{
name: 'val',
type: 'input-formula',
placeholder: '参数值',
variables: '${variables}',
evalMode: false,
variableMode: 'tabs',
inputMode: 'input-group'
}
*/
getSchemaTpl('formulaControl', {
name: 'val',
variables: '${variables}',
@ -1506,17 +1412,6 @@ export const ACTION_TYPE_TREE = (manager: any): RendererPluginAction[] => {
valueField: 'value',
required: true
},
/*
{
name: 'val',
type: 'input-formula',
placeholder: '字段值',
variables: '${variables}',
evalMode: false,
variableMode: 'tabs',
inputMode: 'input-group'
}
*/
getSchemaTpl('formulaControl', {
name: 'val',
variables: '${variables}',
@ -1562,16 +1457,6 @@ export const ACTION_TYPE_TREE = (manager: any): RendererPluginAction[] => {
required: true,
visibleOn: `data.__rendererName`
},
/*
{
name: 'val',
type: 'input-formula',
variables: '${variables}',
evalMode: false,
variableMode: 'tabs',
inputMode: 'input-group'
}
*/
getSchemaTpl('formulaControl', {
name: 'val',
variables: '${variables}'
@ -1582,21 +1467,6 @@ export const ACTION_TYPE_TREE = (manager: any): RendererPluginAction[] => {
visibleOn: `(data.__rendererName === 'combo' || data.__rendererName === 'input-table')
&& data.__comboType === 'all'`
},
/*
{
name: '__valueInput',
type: 'input-formula',
variables: '${variables}',
evalMode: false,
variableMode: 'tabs',
inputMode: 'input-group',
label: '',
size: 'lg',
mode: 'horizontal',
visibleOn: `(data.__isScopeContainer || ${SHOW_SELECT_PROP}) && data.__containerType === 'all'`,
required: true
},
*/
getSchemaTpl('formulaControl', {
name: '__valueInput',
label: '',
@ -1606,21 +1476,6 @@ export const ACTION_TYPE_TREE = (manager: any): RendererPluginAction[] => {
visibleOn: `(data.__isScopeContainer || ${SHOW_SELECT_PROP}) && data.__containerType === 'all'`,
required: true
}),
/*
{
name: '__valueInput',
type: 'input-formula',
variables: '${variables}',
evalMode: false,
variableMode: 'tabs',
inputMode: 'input-group',
label: '数据设置',
size: 'lg',
mode: 'horizontal',
visibleOn: `data.__rendererName && !data.__isScopeContainer && data.__rendererName !== 'combo'`,
required: true
}
*/
getSchemaTpl('formulaControl', {
name: '__valueInput',
label: '数据设置',
@ -1796,21 +1651,6 @@ export const ACTION_TYPE_TREE = (manager: any): RendererPluginAction[] => {
type: 'wrapper',
className: 'p-none',
body: [
/*
{
name: 'content',
type: 'input-formula',
variables: '${variables}',
evalMode: false,
variableMode: 'tabs',
inputMode: 'input-group',
label: '内容模板',
mode: 'horizontal',
size: 'lg',
visibleOn: 'data.actionType === "copy"',
required: true
},
*/
getSchemaTpl('textareaFormulaControl', {
name: 'content',
label: '内容模板',
@ -1962,28 +1802,8 @@ export const renderCmptActionSelect = (
componentLabel || '选择组件',
true,
async (value: string, oldVal: any, data: any, form: any) => {
// 获取组件上下文.
const rendererType = form.data.__rendererName;
// 获取组件上下文
if (form.data.__nodeId) {
const dataSchema: any = await form.data.getContextSchemas?.(
form.data.__nodeId,
true
);
const dataSchemaIns = new DataSchema(dataSchema || []);
const variables = dataSchemaIns?.getDataPropsAsOptions() || [];
form.setValueByName('__cmptDataSchema', dataSchema);
form.setValueByName('__cmptVariables', variables); // 组件上下文(不含父级)
form.setValueByName('__cmptVariablesWithSys', [
// 组件上下文+页面+系统
{
label: `${form.data.__rendererLabel}变量`,
children: variables
},
...form.data.rawVariables.filter((item: ContextVariables) =>
['页面变量', '系统变量'].includes(item.label)
)
]);
if (form.data.actionType === 'setValue') {
// todo:这里会闪一下需要从amis查下问题
form.setValueByName('args.value', []);
@ -1991,7 +1811,14 @@ export const renderCmptActionSelect = (
form.setValueByName('args.__valueInput', undefined);
form.setValueByName('args.__containerType', undefined);
if (SELECT_PROPS_CONTAINER.includes(rendererType)) {
if (SELECT_PROPS_CONTAINER.includes(form.data.__rendererName)) {
const contextSchema: any = await form.data.getContextSchemas?.(
form.data.__nodeId,
true
);
const dataSchema = new DataSchema(contextSchema || []);
const variables = dataSchema?.getDataPropsAsOptions() || [];
form.setValueByName(
'__setValueDs',
variables.filter(item => item.value !== '$$id')
@ -2070,17 +1897,6 @@ export const COMMON_ACTION_SCHEMA_MAP: {
valueField: 'value',
required: true
},
/*
{
name: 'val',
type: 'input-formula',
placeholder: '变量值',
variables: '${variables}',
evalMode: false,
variableMode: 'tabs',
inputMode: 'input-group'
}
*/
getSchemaTpl('formulaControl', {
name: 'val',
variables: '${variables}',
@ -2120,16 +1936,6 @@ export const COMMON_ACTION_SCHEMA_MAP: {
type: 'input-text',
required: true
},
/*
{
name: 'val',
type: 'input-formula',
variables: '${variables}',
evalMode: false,
variableMode: 'tabs',
inputMode: 'input-group'
}
*/
getSchemaTpl('formulaControl', {
name: 'val',
variables: '${variables}'
@ -2139,21 +1945,6 @@ export const COMMON_ACTION_SCHEMA_MAP: {
],
visibleOn: `data.__rendererName === 'combo' || data.__rendererName === 'input-table'`
},
/*
{
name: '__valueInput',
type: 'input-formula',
variables: '${variables}',
evalMode: false,
variableMode: 'tabs',
inputMode: 'input-group',
label: '变量赋值',
size: 'lg',
mode: 'horizontal',
visibleOn: `!data.__isScopeContainer && data.__rendererName !== 'combo'`,
required: true
}
*/
getSchemaTpl('formulaControl', {
name: '__valueInput',
label: '变量赋值',
@ -2886,13 +2677,7 @@ export const getEventControlConfig = (
);
return result;
},
actionConfigInitFormatter: async (
action: ActionConfig,
variables: {
eventVariables: ContextVariables[];
rawVariables: ContextVariables[];
}
) => {
actionConfigInitFormatter: async (action: ActionConfig) => {
let config = {...action};
if (['link', 'url'].includes(action.actionType) && action.args?.params) {
config.args = {
@ -3008,7 +2793,9 @@ export const getEventControlConfig = (
// 处理下 addItem 的初始化
if (action.actionType === 'addItem') {
if (Array.isArray(action.args?.item)) {
const comboArray = (action.args?.item || []).map((raw: any) => objectToComboArray(raw));
const comboArray = (action.args?.item || []).map((raw: any) =>
objectToComboArray(raw)
);
config.args = {
...config.args,
value: comboArray.map(combo => ({item: combo}))
@ -3049,37 +2836,11 @@ export const getEventControlConfig = (
// 获取左侧命中的动作节点
const hasSubActionNode = findSubActionNode(actionTree, action.actionType);
// 如果args配置中存在组件id则自动获取一次该组件的上下文
let datasource = [];
if (action.args?.componentId) {
const schema = manager?.store?.getSchema(
action.args?.componentId,
'id'
);
const dataSchema: any = await manager.getContextSchemas(
schema?.$$id,
true
);
const dataSchemaIns = new DataSchema(dataSchema || []);
datasource = dataSchemaIns?.getDataPropsAsOptions() || [];
}
return {
...config,
actionType: getActionType(action, hasSubActionNode),
args: {
...config.args,
__dataContainerVariables: datasource?.length
? [
...variables.eventVariables,
{
label: '数据来源变量',
children: datasource
},
...variables.rawVariables
]
: [...variables.eventVariables, ...variables.rawVariables]
}
args: config.args
};
},
actionConfigSubmitFormatter: (config: ActionConfig) => {
@ -3222,7 +2983,9 @@ export const getEventControlConfig = (
action.actionType === 'addItem' &&
action.__rendererName === 'input-table'
) {
const comboArray = (config.args?.value! || []).map((combo: any) => combo.item || {});
const comboArray = (config.args?.value! || []).map(
(combo: any) => combo.item || {}
);
action.args = {
...action.args,
item: comboArray.map((raw: any) => comboArrayToObject(raw))

View File

@ -30,6 +30,7 @@ import {
ContextVariables
} from './types';
import {
EditorManager,
PluginActions,
PluginEvents,
RendererPluginAction,
@ -40,6 +41,7 @@ export * from './helper';
import {i18n as _i18n} from 'i18n-runtime';
import type {VariableItem} from 'amis-ui/lib/components/formula/Editor';
import {reaction} from 'mobx';
import {updateComponentContext} from '../../util';
interface EventControlProps extends FormControlProps {
actions: PluginActions; // 组件的动作列表
@ -56,13 +58,7 @@ interface EventControlProps extends FormControlProps {
removeBroadcast?: (eventName: string) => void;
getComponents: (action: any) => ComponentInfo[]; // 当前页面组件树
getContextSchemas?: (id?: string, withoutSuper?: boolean) => DataSchema; // 获取上下文
actionConfigInitFormatter?: (
actionConfig: ActionConfig,
variables: {
eventVariables: ContextVariables[]; // 当前事件变量
rawVariables: ContextVariables[]; // 绑定事件的组件上下文
}
) => ActionConfig; // 动作配置初始化时格式化
actionConfigInitFormatter?: (actionConfig: ActionConfig) => ActionConfig; // 动作配置初始化时格式化
actionConfigSubmitFormatter?: (actionConfig: ActionConfig) => ActionConfig; // 动作配置提交时格式化
owner?: string; // 组件标识
}
@ -95,7 +91,6 @@ interface EventControlState {
variables?: ContextVariables[];
pluginActions: PluginActions;
getContextSchemas?: (id?: string, withoutSuper?: boolean) => DataSchema;
rawVariables: ContextVariables[];
groupType?: string;
__actionDesc?: string;
__cmptTreeSource?: ComponentInfo[];
@ -495,73 +490,194 @@ export class EventControl extends React.Component<
});
}
getEventVariables(
activeData: Pick<
EventControlState,
'showAcionDialog' | 'type' | 'actionData'
>
) {
const {events, onEvent} = this.state;
buildEventDataSchema(data: any, manager: EditorManager) {
const {actionTree, pluginActions, commonActions, allComponents} =
this.props;
// 收集当前事件已有ajax动作的请求返回结果作为事件变量
let oldActions = onEvent[activeData.actionData!.eventKey].actions;
if (activeData.type === 'update') {
// 编辑的时候只能拿到当前动作前面动作的事件变量
oldActions = oldActions.slice(0, activeData.actionData!.actionIndex);
const {events, onEvent} = this.state;
const eventConfig = events.find(
item => item.eventName === data.actionData!.eventKey
);
// 收集当前事件动作出参
let actions = onEvent[data.actionData!.eventKey].actions;
// 编辑的时候只能拿到当前动作前面动作的事件变量
if (data.type === 'update') {
actions = actions.slice(0, data.actionData!.actionIndex);
}
const withOutputVarActions = oldActions?.filter(item => item.outputVar);
const withOutputVarVariables = withOutputVarActions?.map(
(item: any, index: number) => {
let jsonSchema = {...(eventConfig?.dataSchema?.[0] ?? {})};
actions
?.filter(item => item.outputVar)
?.forEach((action: ActionConfig, index: number) => {
if (
manager.dataSchema.getScope(
`action-output-${action.actionType}_ ${index}`
)
) {
return;
}
const actionLabel = getPropOfAcion(
item,
action,
'actionLabel',
actionTree,
pluginActions,
commonActions,
allComponents
);
const dataSchemaJson = getPropOfAcion(
item,
const actionSchema = getPropOfAcion(
action,
'outputVarDataSchema',
actionTree,
pluginActions,
commonActions,
allComponents
);
const dataSchema = new DataSchema(dataSchemaJson || []);
return {
label: `${
item.outputVar
? item.outputVar + `${actionLabel}结果)`
: `${actionLabel}结果`
}`,
tag: 'object',
children: dataSchema.getDataPropsAsOptions()?.map(variable => ({
...variable,
value: variable.value.replace('${outputVar}', item.outputVar)
}))
// const schema: any = {
// type: 'object',
// $id: 'outputVar',
// properties: {
// [action.outputVar!]: {
// ...actionSchema[0],
// title: `${action.outputVar}(${actionLabel})`
// }
// }
// };
jsonSchema = {
...jsonSchema,
properties: {
...jsonSchema.properties,
data: {
type: 'object',
title: '数据',
...jsonSchema.properties?.data,
properties: {
...jsonSchema.properties?.data?.properties,
[action.outputVar!]: {
...actionSchema[0],
title: `${action.outputVar}(${actionLabel}动作出参)`
}
}
}
}
};
}
);
const eventVariables: ContextVariables[] = [
// manager.dataSchema.addScope(
// schema,
// `action-output-${action.actionType}_${index}`
// );
// manager.dataSchema.current.group = '动作出参';
});
if (manager.dataSchema.getScope('event-variable')) {
manager.dataSchema.removeScope('event-variable');
}
manager.dataSchema.addScope(
{
label: '事件变量',
children: withOutputVarVariables || []
}
];
const eventConfig = events.find(
item => item.eventName === activeData.actionData!.eventKey
type: 'object',
properties: {
event: {
...jsonSchema,
title: '事件动作'
}
}
},
'event-variable'
);
eventConfig?.dataSchema?.forEach((ds: any) => {
const dataSchema = new DataSchema(ds || []);
eventVariables[0].children = [
...eventVariables[0].children!,
...dataSchema.getDataPropsAsOptions()
];
}
// buildActionDataSchema(
// activeData: Pick<
// EventControlState,
// 'showAcionDialog' | 'type' | 'actionData'
// >,
// manager: EditorManager
// ) {
// const {actionTree, pluginActions, commonActions, allComponents} =
// this.props;
// const {onEvent} = this.state;
// // 收集当前事件已有ajax动作的请求返回结果作为事件变量
// let oldActions = onEvent[activeData.actionData!.eventKey].actions;
// // 编辑的时候只能拿到当前动作前面动作的事件变量
// if (activeData.type === 'update') {
// oldActions = oldActions.slice(0, activeData.actionData!.actionIndex);
// }
// oldActions
// ?.filter(item => item.outputVar)
// ?.forEach((action: ActionConfig, index: number) => {
// if (
// manager.dataSchema.getScope(
// `action-output-${action.actionType}_ ${index}`
// )
// ) {
// return;
// }
// const actionLabel = getPropOfAcion(
// action,
// 'actionLabel',
// actionTree,
// pluginActions,
// commonActions,
// allComponents
// );
// const actionSchema = getPropOfAcion(
// action,
// 'outputVarDataSchema',
// actionTree,
// pluginActions,
// commonActions,
// allComponents
// );
// const schema: any = {
// type: 'object',
// properties: {
// [`event.data.${action.outputVar}`]: {
// ...actionSchema[0],
// title: `${action.outputVar}(${actionLabel})`
// }
// }
// };
// manager.dataSchema.addScope(
// schema,
// `action-output-${action.actionType}_${index}`
// );
// manager.dataSchema.current.group = '动作出参';
// });
// }
async buildContextSchema(data: any) {
const {manager, node: currentNode} = this.props;
let variables = [];
// 获取上下文
await manager.getContextSchemas(currentNode.id);
// 追加事件相关
// this.buildActionDataSchema(data, manager);
this.buildEventDataSchema(data, manager);
(manager.dataSchema as DataSchema).switchTo('event-variable');
variables = (manager.dataSchema as DataSchema).getDataPropsAsOptions();
// 插入应用变量
const appVariables: VariableItem[] =
manager?.variableManager?.getVariableFormulaOptions() || [];
appVariables.forEach(item => {
if (Array.isArray(item?.children) && item.children.length) {
variables.push(item);
}
});
return eventVariables;
return updateComponentContext(variables);
}
// 唤起动作配置弹窗
@ -575,48 +691,17 @@ export class EventControl extends React.Component<
getComponents,
actionTree,
allComponents,
manager
manager,
node: currentNode
} = this.props;
let rawVariables = [];
// 获取绑定事件的组件上下文变量
if (getContextSchemas) {
const dataSchemaIns = await getContextSchemas();
rawVariables = dataSchemaIns?.getDataPropsAsOptions();
}
// 收集事件变量
const eventVariables = this.getEventVariables(data);
const appVariables: VariableItem[] =
manager?.variableManager?.getVariableFormulaOptions() || [];
const variables = [...eventVariables, ...rawVariables];
const systemVarIndex = variables.findIndex(
item => item.label === '系统变量'
);
// 插入应用变量
if (!!~systemVarIndex) {
appVariables.forEach(item => {
if (Array.isArray(item?.children) && item.children.length) {
variables.splice(systemVarIndex, 0, item);
}
});
} else {
appVariables.forEach(item => {
if (Array.isArray(item?.children) && item.children.length) {
variables.push(item);
}
});
}
variables.forEach(item => (item.selectMode = 'tree'));
// 构建上下文变量schema
const variables = await this.buildContextSchema(data);
// 编辑操作,需要格式化动作配置
if (data.type === 'update') {
const action = data.actionData!.action!;
const actionConfig = await actionConfigInitFormatter?.(action, {
eventVariables,
rawVariables
});
const actionConfig = await actionConfigInitFormatter?.(action);
const actionNode = findActionNode(actionTree, actionConfig?.actionType!);
const hasSubActionNode = findSubActionNode(actionTree, action.actionType);
const supportComponents = getComponents(actionNode!);
@ -625,17 +710,20 @@ export class EventControl extends React.Component<
item => item.value === action.componentId
);
// 获取组件数据动作所需上下文
// 获取被赋值组件的变量字段
let setValueDs: any = null;
if (
actionConfig?.actionType === 'setValue' &&
node?.id &&
SELECT_PROPS_CONTAINER.includes(node?.type || '')
) {
const targetDataSchema: any = await getContextSchemas?.(node.id, true);
const targetDataSchemaIns = new DataSchema(targetDataSchema || []);
const targetVariables =
targetDataSchemaIns?.getDataPropsAsOptions() || [];
// 获取目标组件数据域
const contextSchema: any = await manager.getContextSchemas(
node.id,
true
);
const dataSchema = new DataSchema(contextSchema || []);
const targetVariables = dataSchema?.getDataPropsAsOptions() || [];
setValueDs = targetVariables?.filter(
(item: ContextVariables) => item.value !== '$$id'
@ -648,7 +736,6 @@ export class EventControl extends React.Component<
variables,
pluginActions,
getContextSchemas,
rawVariables,
...actionConfig,
groupType: actionConfig?.__actionType || action.actionType,
__actionDesc: actionNode!.description!, // 树节点描述
@ -674,7 +761,6 @@ export class EventControl extends React.Component<
variables,
pluginActions,
getContextSchemas,
rawVariables,
__superCmptTreeSource: allComponents
};
}
@ -734,15 +820,35 @@ export class EventControl extends React.Component<
this.updateAction?.(config.eventKey, config.actionIndex, action);
}
this.removeDataSchema();
this.setState({showAcionDialog: false});
this.setState({actionData: undefined});
}
@autobind
onClose() {
this.removeDataSchema();
this.setState({showAcionDialog: false});
}
removeDataSchema() {
const {manager} = this.props;
// 删除事件
if (manager.dataSchema.getScope('event-variable')) {
manager.dataSchema.removeScope('event-variable');
}
// // 删除动作出参
// Object.keys(manager.dataSchema.idMap)
// .filter(key => /^action-output/.test(key))
// .map(key => {
// if (manager.dataSchema.getScope(key)) {
// manager.dataSchema.removeScope(key);
// }
// });
}
render() {
const {
actionTree,

View File

@ -33,4 +33,5 @@ export interface ContextVariables {
value?: any;
tag?: string | string[];
children?: any[];
path?: string;
}

View File

@ -46,7 +46,7 @@ const FormulaPicker: React.FC<FormulaPickerProps> = props => {
return (
<Modal
className={cx('FormulaPicker-Modal')}
size="md"
size="lg"
show
onHide={handleClose}
closeOnEsc

View File

@ -127,7 +127,7 @@ export class TextareaFormulaControl extends React.Component<
TextareaFormulaControlState
> {
static defaultProps: Partial<TextareaFormulaControlProps> = {
variableMode: 'tabs',
variableMode: 'tree',
requiredDataPropsVariables: false,
height: 100,
placeholder: '请输入'
@ -176,20 +176,9 @@ export class TextareaFormulaControl extends React.Component<
this.hiddenToolTip
);
}
const variablesArr = await getVariables(this);
this.setState({
variables: variablesArr
});
}
async componentDidUpdate(prevProps: TextareaFormulaControlProps) {
if (this.props.data !== prevProps.data) {
const variablesArr = await getVariables(this);
this.setState({
variables: variablesArr
});
}
if (this.state.value !== this.props.value) {
this.setState(
{
@ -212,15 +201,6 @@ export class TextareaFormulaControl extends React.Component<
this.unReaction?.();
}
@autobind
onExpressionClick(expression: string, brace?: Array<CodeMirror.Position>) {
this.setState({
formulaPickerValue: expression,
formulaPickerOpen: true,
expressionBrace: brace
});
}
@autobind
onExpressionMouseEnter(
e: any,
@ -289,7 +269,6 @@ export class TextareaFormulaControl extends React.Component<
const variables = this.state.variables || this.props.variables || [];
this.editorPlugin = new FormulaPlugin(editor, {
getProps: () => ({...this.props, variables}),
onExpressionClick: this.onExpressionClick,
onExpressionMouseEnter: this.onExpressionMouseEnter,
customMarkText: this.props.customMarkText,
onPluginInit: this.props.onPluginInit,
@ -308,15 +287,24 @@ export class TextareaFormulaControl extends React.Component<
}
@autobind
handleFormulaClick() {
async handleFormulaClick(e: React.MouseEvent, type?: string) {
if (this.props.onOverallClick) {
return;
}
const variablesArr = await getVariables(this);
this.setState({
formulaPickerOpen: true,
formulaPickerValue: '',
expressionBrace: undefined
variables: variablesArr,
formulaPickerOpen: true
});
if (type !== 'update') {
this.setState({
formulaPickerValue: '',
expressionBrace: undefined
});
}
}
@autobind
@ -469,9 +457,7 @@ export class TextareaFormulaControl extends React.Component<
className="ae-TplFormulaControl-tooltip"
style={tooltipStyle}
ref={this.tooltipRef}
onClick={() => {
this.setState({formulaPickerOpen: true});
}}
onClick={e => this.handleFormulaClick(e, 'update')}
></div>
</TooltipWrapper>

View File

@ -22,10 +22,6 @@ export function editorFactory(
interface FormulaPluginConfig {
getProps: () => TextareaFormulaControlProps;
onExpressionClick?: (
expression: string,
brace?: Array<CodeMirror.Position>
) => any;
onExpressionMouseEnter?: (
e: MouseEvent,
expression: string,
@ -67,6 +63,7 @@ export class FormulaPlugin {
autoMark() {
const editor = this.editor;
const lines = editor.lineCount();
for (let line = 0; line < lines; line++) {
const content = editor.getLine(line);
const braces = this.computedBracesPosition(content);
@ -225,13 +222,8 @@ export class FormulaPlugin {
expression = '',
className = 'cm-expression'
) {
const {
onExpressionClick,
onExpressionMouseEnter,
getProps,
showPopover,
showClearIcon
} = this.config;
const {onExpressionMouseEnter, getProps, showPopover, showClearIcon} =
this.config;
const variables = getProps()?.variables as VariableItem[];
const highlightValue = FormulaEditor.highlightValue(
@ -247,10 +239,6 @@ export class FormulaPlugin {
text.className = `${className}-text`;
text.innerHTML = highlightValue.html;
text.setAttribute('data-expression', expression);
text.onclick = () => {
const brace = this.getExpressionBrace(expression);
onExpressionClick?.(expression, brace);
};
text.onmouseenter = e => {
const brace = this.getExpressionBrace(expression);
onExpressionMouseEnter?.(e, expression, brace);

View File

@ -1,6 +1,7 @@
import {isExpression, resolveVariableAndFilter} from 'amis-core';
import {translateSchema} from 'amis-editor-core';
import type {VariableItem} from 'amis-ui/lib/components/formula/Editor';
import {updateComponentContext} from '../../util';
/**
* amis数据域中取变量数据
@ -11,40 +12,16 @@ import type {VariableItem} from 'amis-ui/lib/components/formula/Editor';
export async function resolveVariablesFromScope(node: any, manager: any) {
await manager?.getContextSchemas(node);
// 获取当前组件内相关变量,如表单、增删改查
const dataPropsAsOptions: VariableItem[] =
await manager?.dataSchema?.getDataPropsAsOptions();
const dataPropsAsOptions: VariableItem[] = updateComponentContext(
(await manager?.dataSchema?.getDataPropsAsOptions()) ?? []
);
const variables: VariableItem[] =
manager?.variableManager?.getVariableFormulaOptions() || [];
if (dataPropsAsOptions) {
// FIXME: 系统变量最好有个唯一标识符
const systemVarIndex = dataPropsAsOptions.findIndex(
item => item.label === '系统变量'
);
if (!!~systemVarIndex) {
variables.forEach(item => {
if (Array.isArray(item?.children) && item.children.length) {
dataPropsAsOptions.splice(systemVarIndex, 0, item);
}
});
} else {
variables.forEach(item => {
if (Array.isArray(item?.children) && item.children.length) {
dataPropsAsOptions.push(item);
}
});
}
return dataPropsAsOptions
.map((item: any) => ({
selectMode: 'tree',
...item
}))
.filter((item: any) => item.children?.length);
}
return [];
return [...dataPropsAsOptions, ...variables].filter(
(item: any) => item.children?.length
);
}
/**

View File

@ -114,6 +114,7 @@ setSchemaTpl(
setSchemaTpl('formulaControl', (schema: object = {}) => {
return {
type: 'ae-formulaControl',
variableMode: 'tree',
...schema
};
});
@ -121,6 +122,7 @@ setSchemaTpl('formulaControl', (schema: object = {}) => {
setSchemaTpl('expressionFormulaControl', (schema: object = {}) => {
return {
type: 'ae-expressionFormulaControl',
variableMode: 'tree',
...schema
};
});
@ -128,6 +130,7 @@ setSchemaTpl('expressionFormulaControl', (schema: object = {}) => {
setSchemaTpl('textareaFormulaControl', (schema: object = {}) => {
return {
type: 'ae-textareaFormulaControl',
variableMode: 'tree',
...schema
};
});
@ -135,6 +138,7 @@ setSchemaTpl('textareaFormulaControl', (schema: object = {}) => {
setSchemaTpl('tplFormulaControl', (schema: object = {}) => {
return {
type: 'ae-tplFormulaControl',
variableMode: 'tree',
...schema
};
});
@ -632,7 +636,7 @@ setSchemaTpl('sourceBindControl', (schema: object = {}) => ({
type: 'ae-formulaControl',
name: 'source',
label: '数据',
variableMode: 'tabs',
variableMode: 'tree',
inputMode: 'input-group',
placeholder: '请输入表达式',
requiredDataPropsVariables: true,
@ -1216,17 +1220,6 @@ setSchemaTpl('app-page-args', {
valueField: 'value',
required: true
},
/*
{
name: 'val',
type: 'input-formula',
placeholder: '参数值',
variables: '${variables}',
evalMode: false,
variableMode: 'tabs',
inputMode: 'input-group'
}
*/
getSchemaTpl('formulaControl', {
name: 'val',
variables: '${variables}',

View File

@ -1,275 +1,6 @@
import {
BaseEventContext,
EditorManager,
RendererPluginAction
} from 'amis-editor-core';
import {filterTree, mapTree, resolveVariableAndFilter} from 'amis';
import {ACTION_TYPE_TREE} from './renderer/event-control/helper';
import {ActionConfig, ComponentInfo} from './renderer/event-control/types';
import {
COMMON_ACTION_SCHEMA_MAP,
findActionNode,
findSubActionNode,
FORMITEM_CMPTS,
getActionType,
getPropOfAcion,
hasActionType
} from './renderer/event-control/helper';
import {resolveVariableAndFilter} from 'amis';
import isString from 'lodash/isString';
/**
*
*/
export const getEventControlConfig = (
manager: EditorManager,
context: BaseEventContext
) => {
// 通用动作配置
const commonActions =
manager?.config.actionOptions?.customActionGetter?.(manager);
// 动作树
const actionTree = manager?.config.actionOptions?.actionTreeGetter
? manager?.config.actionOptions?.actionTreeGetter(ACTION_TYPE_TREE(manager))
: ACTION_TYPE_TREE(manager);
const commonActionConfig = {
...COMMON_ACTION_SCHEMA_MAP,
...commonActions
};
return {
showOldEntry:
manager?.config.actionOptions?.showOldEntry !== false &&
(!!context.schema.actionType ||
['submit', 'reset'].includes(context.schema.type)),
actions: manager?.pluginActions,
events: manager?.pluginEvents,
actionTree,
commonActions,
owner: '',
addBroadcast: manager?.addBroadcast,
removeBroadcast: manager?.removeBroadcast,
getContextSchemas: async (id?: string, withoutSuper?: boolean) => {
const dataSchema = await manager.getContextSchemas(
id ?? context!.id,
withoutSuper
);
// 存在指定id时只需要当前层上下文
if (id) {
return dataSchema;
}
return manager.dataSchema;
},
getComponents: (action: RendererPluginAction) => {
const actionType = action.actionType!;
const components = filterTree(
mapTree(
manager?.store?.outline ?? [],
(item: any) => {
const schema = manager?.store?.getSchema(item.id);
return {
id: item.id,
label: item.label,
value: schema?.id ?? item.id,
type: schema?.type ?? item.type,
schema,
disabled: !!item.region,
children: item?.children
};
},
1,
true
),
node => {
const actions = manager?.pluginActions[node.type];
let isSupport = false;
if (typeof action.supportComponents === 'string') {
isSupport =
action.supportComponents === '*' ||
action.supportComponents === node.type;
} else if (Array.isArray(action.supportComponents)) {
isSupport = action.supportComponents.includes(node.type);
}
if (['reload', 'setValue'].includes(actionType)) {
isSupport = hasActionType(actionType, actions);
}
if (actionType === 'component' && !actions?.length) {
node.disabled = true;
}
if (isSupport) {
return true;
} else if (!isSupport && !!node.children?.length) {
node.disabled = true;
return true;
}
return false;
},
1,
true
);
return components;
},
actionConfigInitFormatter: (action: ActionConfig) => {
let config = {...action};
if (
['setValue', 'url', 'link'].includes(action.actionType) &&
action.args
) {
const prop = action.actionType === 'setValue' ? 'value' : 'params';
!config.args && (config.args = {});
if (Array.isArray(action.args[prop])) {
config.args[prop] = action.args[prop].reduce(
(arr: any, valueItem: any, index: number) => {
if (!arr[index]) {
arr[index] = {};
}
arr[index].item = Object.entries(valueItem).map(([key, val]) => ({
key,
val
}));
return arr;
},
[]
);
} else if (typeof action.args[prop] === 'object') {
config.args[prop] = Object.keys(action.args[prop]).map(key => ({
key,
val: action.args?.[prop][key]
}));
} else if (
action.actionType === 'setValue' &&
typeof action.args[prop] === 'string'
) {
config.args['valueInput'] = config.args['value'];
delete config.args?.value;
}
}
// 获取动作专有配置参数
const innerArgs: any = getPropOfAcion(
action,
'innerArgs',
actionTree,
manager.pluginActions,
commonActions
);
// 还原args为可视化配置结构(args + addOnArgs)
if (config.args) {
if (innerArgs) {
let tmpArgs = {};
config.addOnArgs = [];
Object.keys(config.args).forEach(key => {
// 筛选出附加配置参数
if (!innerArgs.includes(key)) {
config.addOnArgs = [
...config.addOnArgs,
{
key: key,
val: config.args?.[key]
}
];
} else {
tmpArgs = {
...tmpArgs,
[key]: config.args?.[key]
};
}
});
config.args = tmpArgs;
}
}
// 获取左侧命中的动作节点
const hasSubActionNode = findSubActionNode(actionTree, action.actionType);
return {
...config,
actionType: getActionType(action, hasSubActionNode)
};
},
actionConfigSubmitFormatter: (config: ActionConfig) => {
let action = {...config};
action.__title = findActionNode(
actionTree,
config.actionType
)?.actionLabel;
// 修正动作名称
if (config.actionType === 'component') {
// 标记一下组件特性动作
action.__isCmptAction = true;
action.actionType = config.__cmptActionType;
}
const hasSubActionNode = findSubActionNode(
actionTree,
config.__cmptActionType
);
if (hasSubActionNode) {
// 修正动作
action.actionType = config.__cmptActionType;
}
// 合并附加的动作参数
if (config.addOnArgs) {
config.addOnArgs.forEach((args: any) => {
action.args = action.args ?? {};
action.args = {
...action.args,
[args.key]: args.val
};
});
delete action.addOnArgs;
}
// 转换下格式
if (['setValue', 'url', 'link'].includes(action.actionType)) {
const propName = action.actionType === 'setValue' ? 'value' : 'params';
if (Array.isArray(config.args?.[propName])) {
action.args = action.args ?? {};
if (action.__rendererName === 'combo') {
// combo特殊处理
let tempArr: any = [];
config.args?.[propName].forEach((valueItem: any, index: number) => {
valueItem.item.forEach((item: any) => {
if (!tempArr[index]) {
tempArr[index] = {};
}
tempArr[index][item.key] = item.val;
});
});
action.args = {
...action.args,
[propName]: tempArr
};
} else {
let tmpObj: any = {};
config.args?.[propName].forEach((item: any) => {
tmpObj[item.key] = item.val;
});
action.args = {
...action.args,
[propName]: tmpObj
};
}
} else if (action.actionType === 'setValue') {
// 处理变量赋值非数组的情况
action.args = {
...action.args,
value: config.args?.['valueInput']
};
}
}
delete action.config;
return action;
}
};
};
/**
*
*/
@ -311,3 +42,26 @@ export const schemaToArray = (value: any) => {
export const schemaArrayFormat = (value: any) => {
return value && Array.isArray(value) && value.length === 1 ? value[0] : value;
};
/**
* label为带层级说明
* @param variables
* @returns
*/
export const updateComponentContext = (variables: any[]) => {
const items = [...variables];
const idx = items.findIndex(item => item.label === '组件上下文');
if (~idx) {
items.splice(idx, 1, {
...items[idx],
children: items[idx].children.map((child: any, index: number) => ({
...child,
label:
index === 0
? `当前数据域${child.label ? '(' + child.label + ')' : ''}`
: `${index}${child.label ? '(' + child.label + ')' : ''}`
}))
});
}
return items;
};

View File

@ -28,12 +28,25 @@
}
&-content {
border-radius: var(--borderRadius);
border: var(--Form-input-borderWidth) solid var(--Form-input-borderColor);
flex: 1;
height: 100%;
max-width: #{px2rem(530px)};
border-top: var(--Form-input-borderWidth) solid
var(--Form-input-borderColor);
border-bottom: var(--Form-input-borderWidth) solid
var(--Form-input-borderColor);
}
&-header {
@include panel-header();
&-toolbar {
font-size: 12px;
float: right;
> span {
margin-right: 5px;
}
}
}
&-editor {
@ -61,13 +74,9 @@
flex-flow: row nowrap;
align-items: stretch;
justify-content: space-between;
height: #{px2rem(250px)};
height: #{px2rem(450px)};
margin-top: #{px2rem(10px)};
&:not(.is-mobile) > div {
width: 0;
}
&.is-mobile {
width: 100%;
overflow-x: scroll;
@ -81,22 +90,13 @@
&-panel {
display: flex;
flex: 1;
flex-flow: column nowrap;
justify-content: space-between;
align-items: stretch;
height: 100%;
border-radius: var(--borderRadius);
width: #{px2rem(188px)};
border: var(--Form-input-borderWidth) solid var(--Form-input-borderColor);
&:not(:last-child) {
margin-right: #{px2rem(10px)};
}
&:last-child {
flex: 1;
}
&-header {
@include panel-header();
}
@ -114,8 +114,19 @@
}
}
&-panel.left {
justify-content: normal !important;
border-radius: var(--borderRadius) 0 0 var(--borderRadius);
}
&-panel.right {
width: #{px2rem(330px)};
border-radius: 0 var(--borderRadius) var(--borderRadius) 0;
}
/* 变量列表 */
&-VariableList {
height: 100%;
&-root {
max-height: 100%;
}
@ -135,7 +146,7 @@
&-base.is-scrollable {
@include scrollbar();
overflow-x: hidden;
overflow-x: auto;
overflow-y: auto;
}
@ -175,7 +186,6 @@
.#{$ns}FormulaEditor-VariableList {
&-sub {
.#{$ns}FormulaEditor-VariableList-body {
max-height: #{px2rem(220px)};
overflow-y: hidden;
}
&-FormulaEditor-VariableList-base {
@ -238,6 +248,14 @@
flex: 1;
width: 0;
display: inline-block;
min-width: #{px2rem(50px)};
}
.fa-ellipsis-h {
margin-right: #{px2rem(5px)};
&:hover {
color: var(--primary);
}
}
&-tag {
@ -251,31 +269,42 @@
line-height: #{px2rem(24px)};
height: #{px2rem(24px)};
}
&-oper {
list-style: none;
max-width: #{px2rem(235px)};
font-size: var(--fontSizeSm);
min-width: 100px;
padding: 0 5px;
margin: 5px;
text-align: center;
li {
line-height: 24px;
&:hover {
cursor: pointer;
background: var(--Form-select-menu-onHover-bg);
}
}
}
}
.#{$ns}GroupedSelection {
max-height: 100%;
&-item {
&-tag {
line-height: 17px;
}
}
&-itemLabel {
font-size: var(--fontSizeSm);
}
}
}
/* 函数列表 */
&-FuncList {
display: flex;
flex-flow: row nowrap;
justify-content: space-between;
align-items: stretch;
flex: 1;
.#{$ns}FormulaEditor-panel {
width: #{px2rem(188px)};
}
&:not(:last-child) {
margin-right: #{px2rem(10px)};
}
flex-flow: column nowrap;
height: 100%;
&-searchBox {
display: flex;
@ -341,14 +370,14 @@
&-doc {
display: flex;
flex-flow: column nowrap;
padding: #{px2rem(10px)};
max-height: #{px2rem(200px)};
padding: 0 #{px2rem(10px)};
font-size: 12px;
height: 100%;
overflow: hidden;
pre {
white-space: pre-wrap;
word-wrap: break-word;
background: var(--InputFormula-code-bgColor);
padding: #{px2rem(5px)} #{px2rem(10px)};
border-radius: var(--borderRadius);
margin-top: 0;
@ -357,6 +386,17 @@
}
}
&-example {
font-size: var(--fontSizeSm) !important;
th {
padding: #{px2rem(5px)} !important;
font-size: var(--fontSizeSm) !important;
}
td {
padding: #{px2rem(5px)} !important;
}
}
&-desc {
@include scrollbar();
color: var(--text--loud-color);
@ -367,6 +407,16 @@
}
}
&-FuncList.withDoc {
max-height: 50% !important;
}
&-FuncDoc {
height: 300px;
overflow: hidden;
background: var(--InputFormula-code-bgColor);
}
.cm-field,
.cm-func {
border-radius: 3px;
@ -376,7 +426,7 @@
}
.cm-field {
padding: 3px 5px;
padding: 2px 5px;
}
.cm-field {

View File

@ -39,10 +39,9 @@ export class TreeSelection extends BaseSelection<
componentDidUpdate(prevProps: TreeSelectionProps) {
const props = this.props;
if (
!this.state.expanded.length &&
(props.expand !== prevProps.expand || props.options !== prevProps.options)
props.expand !== prevProps.expand ||
props.options !== prevProps.options
) {
this.syncExpanded();
}
@ -51,7 +50,7 @@ export class TreeSelection extends BaseSelection<
syncExpanded() {
const options = this.props.options;
const mode = this.props.expand;
const expanded: Array<string> = [];
let expanded: Array<string> = [];
if (!Array.isArray(options)) {
return;

View File

@ -22,15 +22,18 @@ import FuncList from './FuncList';
import VariableList from './VariableList';
import CodeMirrorEditor from '../CodeMirror';
import {toast} from '../Toast';
import {isMobile} from 'amis-core';
import Switch from '../Switch';
export interface VariableItem {
label: string;
value?: string;
path?: string; // 路径label
children?: Array<VariableItem>;
type?: string;
tag?: string;
selectMode?: 'tree' | 'tabs';
isMember?: boolean; // 是否是数组成员
// chunks?: string[]; // 内容块,作为一个整体进行高亮标记
}
export interface FuncGroup {
@ -84,6 +87,11 @@ export interface FormulaEditorProps extends ThemeProps, LocaleProps {
* name: 用于避免循环绑定自身导致无限渲染
*/
selfVariableName?: string;
/**
*
*/
editorOptions?: any;
}
export interface FunctionsProps {
@ -100,6 +108,8 @@ export interface FunctionProps {
export interface FormulaState {
focused: boolean;
isCodeMode: boolean;
expandTree: boolean;
}
export class FormulaEditor extends React.Component<
@ -107,7 +117,9 @@ export class FormulaEditor extends React.Component<
FormulaState
> {
state: FormulaState = {
focused: false
focused: false,
isCodeMode: false,
expandTree: false
};
editorPlugin?: FormulaPlugin;
@ -296,11 +308,17 @@ export class FormulaEditor extends React.Component<
}
this.editorPlugin?.insertContent(
{
key: item.value,
name: item.label
},
'variable'
item.isMember
? item.value
: {
key: item.value,
name: item.label,
path: item.path
// chunks: item.chunks
},
item.isMember ? undefined : 'variable',
'cm-field',
!this.state.isCodeMode
);
}
@ -312,7 +330,24 @@ export class FormulaEditor extends React.Component<
@autobind
editorFactory(dom: HTMLElement, cm: any) {
return editorFactory(dom, cm, this.props);
const {editorOptions, ...rest} = this.props;
return editorFactory(dom, cm, rest, {
lineWrapping: true // 自动换行
});
}
@autobind
handleIsCodeModeChange(showCode: boolean) {
// 重置一下value
this.editorPlugin?.setValue(this.editorPlugin?.getValue());
// 非源码模式则mark一下
!showCode && this.editorPlugin?.autoMarkText();
this.setState({isCodeMode: showCode});
}
@autobind
handleExpandTreeChange(expand: boolean) {
this.setState({expandTree: expand});
}
render() {
@ -329,7 +364,7 @@ export class FormulaEditor extends React.Component<
classPrefix,
selfVariableName
} = this.props;
const {focused} = this.state;
const {focused, isCodeMode, expandTree} = this.state;
const customFunctions = Array.isArray(functions) ? functions : [];
const functionList = [
...FormulaEditor.buildDefaultFunctions(doc),
@ -343,29 +378,49 @@ export class FormulaEditor extends React.Component<
'is-focused': focused
})}
>
<section className={cx(`FormulaEditor-content`)}>
<header className={cx(`FormulaEditor-header`)}>
{__(header || 'FormulaEditor.title')}
</header>
<CodeMirrorEditor
className={cx('FormulaEditor-editor')}
value={value}
onChange={this.handleOnChange}
editorFactory={this.editorFactory}
editorDidMount={this.handleEditorMounted}
onFocus={this.handleFocus}
onBlur={this.handleBlur}
<section className={cx('FormulaEditor-settings')}>
<FuncList
className={functionClassName}
title={__('FormulaEditor.function')}
data={functionList}
onSelect={this.handleFunctionSelect}
/>
</section>
<section
className={cx('FormulaEditor-settings', {'is-mobile': isMobile()})}
>
<div className={cx('FormulaEditor-panel')}>
<div className={cx(`FormulaEditor-content`)}>
<header className={cx(`FormulaEditor-header`)}>
{__(header || 'FormulaEditor.title')}
<div className={cx(`FormulaEditor-header-toolbar`)}>
<span></span>
<Switch
value={isCodeMode}
onChange={this.handleIsCodeModeChange}
/>
</div>
</header>
<CodeMirrorEditor
className={cx('FormulaEditor-editor')}
value={value}
onChange={this.handleOnChange}
editorFactory={this.editorFactory}
editorDidMount={this.handleEditorMounted}
onFocus={this.handleFocus}
onBlur={this.handleBlur}
/>
</div>
<div className={cx('FormulaEditor-panel', 'right')}>
{variableMode !== 'tabs' ? (
<div className={cx('FormulaEditor-panel-header')}>
{__('FormulaEditor.variable')}
{variableMode === 'tree' ? (
<div className={cx(`FormulaEditor-header-toolbar`)}>
<span></span>
<Switch
value={expandTree}
onChange={this.handleExpandTreeChange}
/>
</div>
) : null}
</div>
) : null}
<div
@ -381,6 +436,7 @@ export class FormulaEditor extends React.Component<
'FormulaEditor-VariableList-root',
variableClassName
)}
expandTree={expandTree}
selectMode={variableMode}
data={variables!}
onSelect={this.handleVariableSelect}
@ -388,13 +444,6 @@ export class FormulaEditor extends React.Component<
/>
</div>
</div>
<FuncList
className={functionClassName}
title={__('FormulaEditor.function')}
data={functionList}
onSelect={this.handleFunctionSelect}
/>
</section>
</div>
);

View File

@ -5,6 +5,7 @@ import Collapse from '../Collapse';
import CollapseGroup from '../CollapseGroup';
import SearchBox from '../SearchBox';
import type {FuncGroup, FuncItem} from './Editor';
import TooltipWrapper from '../TooltipWrapper';
export interface FuncListProps extends ThemeProps {
title?: string;
@ -24,6 +25,7 @@ export function FuncList(props: FuncListProps) {
} = props;
const [filteredFuncs, setFiteredFuncs] = React.useState(props.data);
const [activeFunc, setActiveFunc] = React.useState<any>(null);
function onSearch(term: string) {
const filtered = props.data
.map(item => {
@ -39,8 +41,13 @@ export function FuncList(props: FuncListProps) {
}
return (
<div className={cx('FormulaEditor-FuncList', className)}>
<div className={cx('FormulaEditor-panel')}>
<div className={cx('FormulaEditor-panel', 'left', className)}>
<div
className={cx(
'FormulaEditor-FuncList',
activeFunc?.name ? 'withDoc' : ''
)}
>
<div className={cx('FormulaEditor-panel-header')}>{title}</div>
<div className={cx('FormulaEditor-panel-body')}>
<div className={cx('FormulaEditor-FuncList-searchBox')}>
@ -73,8 +80,8 @@ export function FuncList(props: FuncListProps) {
className={cx('FormulaEditor-FuncList-item', {
'is-active': item.name === activeFunc?.name
})}
onMouseEnter={() => setActiveFunc(item)}
onClick={() => props.onSelect?.(item)}
onClick={() => setActiveFunc(item)}
onDoubleClick={() => props.onSelect?.(item)}
key={item.name}
>
{item.name}
@ -86,26 +93,63 @@ export function FuncList(props: FuncListProps) {
</div>
</div>
</div>
<div className={cx('FormulaEditor-panel')}>
<div className={cx('FormulaEditor-panel-header')}>
{activeFunc?.name || ''}
</div>
<div className={cx('FormulaEditor-panel-body')}>
<div className={cx('FormulaEditor-FuncList-doc', descClassName)}>
{activeFunc ? (
<>
<pre>
<code>{activeFunc.example}</code>
</pre>
<div className={cx('FormulaEditor-FuncList-doc-desc')}>
{activeFunc.description}
</div>
</>
) : null}
{activeFunc?.name ? (
<div className={cx('FormulaEditor-FuncDoc')}>
<div className={cx('FormulaEditor-panel-header')}>
{activeFunc?.name || ''}
</div>
<div className={cx('FormulaEditor-panel-body')}>
<div className={cx('FormulaEditor-FuncList-doc', descClassName)}>
{activeFunc ? (
<>
<pre>
<TooltipWrapper
placement="top"
tooltip={{
children: () => (
<table
className={cx(
'FormulaEditor-FuncList-doc-example',
'Table-table'
)}
>
<thead>
<tr>
{['参数名称', '类型', '描述'].map(
(name, index) => (
<th key={index}>{name}</th>
)
)}
</tr>
</thead>
<tbody>
{activeFunc.params.map(
(param: any, index: number) => (
<tr key={index}>
<td>{param.name}</td>
<td>{param.type}</td>
<td>{param.description}</td>
</tr>
)
)}
</tbody>
</table>
)
}}
trigger="hover"
>
<code>{activeFunc.example}</code>
</TooltipWrapper>
</pre>
<div className={cx('FormulaEditor-FuncList-doc-desc')}>
{activeFunc.description}
</div>
</>
) : null}
</div>
</div>
</div>
</div>
) : null}
</div>
);
}

View File

@ -503,7 +503,7 @@ export class FormulaPicker extends React.Component<
</PopUp>
) : (
<Modal
size="md"
size="lg"
closeOnEsc
show={this.state.isOpened}
onHide={this.close}

View File

@ -1,6 +1,6 @@
import React from 'react';
import {themeable, ThemeProps, findTreeAll} from 'amis-core';
import {themeable, ThemeProps, filterTree} from 'amis-core';
import GroupedSelection from '../GroupedSelection';
import Tabs, {Tab} from '../Tabs';
import TreeSelection from '../TreeSelection';
@ -12,6 +12,45 @@ import type {Option} from '../Select';
import type {TabsMode} from '../Tabs';
import {Badge} from '../Badge';
import {SpinnerExtraProps} from '../Spinner';
import PopOverContainer from '../PopOverContainer';
import {matchSorter} from 'match-sorter';
import TooltipWrapper from '../TooltipWrapper';
// 数组成员读取
const memberOpers = [
{
label: '取该成员的记录',
value: 'ARRAYMAP(${arr}, item => item.${member})'
},
{
label: '取该成员的记录并过滤',
value: 'ARRAYFILTER(${arr}, item => item.${member})'
},
{
label: '取该成员列表记录中符合条件的总数',
value: 'COUNT(ARRAYFILTER(${arr}, item => item.${member} === 条件))'
},
{
label: '取该成员去重之后的总数',
value: 'COUNT(UNIQ(${arr}, item.${member}))'
},
{
label: '取该成员的总和',
value: 'SUM(ARRAYMAP(${arr}, item => item.${member}))'
},
{
label: '取该成员的平均值',
value: 'AVG(ARRAYMAP(${arr}, item => item.${member}))'
},
{
label: '取该成员的最大值',
value: 'MAX(ARRAYMAP(${arr}, item => item.${member}))'
},
{
label: '取该成员的最小值',
value: 'MIN(ARRAYMAP(${arr}, item => item.${member}))'
}
];
export interface VariableListProps extends ThemeProps, SpinnerExtraProps {
className?: string;
@ -24,9 +63,11 @@ export interface VariableListProps extends ThemeProps, SpinnerExtraProps {
placeholderRender?: (props: any) => JSX.Element | null;
onSelect?: (item: VariableItem) => void;
selfVariableName?: string;
expandTree?: boolean;
}
function VariableList(props: VariableListProps) {
const variableListRef = React.useRef<HTMLDivElement>(null);
const {
data: list,
className,
@ -37,7 +78,8 @@ function VariableList(props: VariableListProps) {
selectMode,
onSelect,
placeholderRender,
selfVariableName
selfVariableName,
expandTree
} = props;
const [filterVars, setFilterVars] = React.useState(list);
const classPrefix = `${themePrefix}FormulaEditor-VariableList`;
@ -46,36 +88,99 @@ function VariableList(props: VariableListProps) {
? props.itemRender
: (option: Option, states: ItemRenderStates): JSX.Element => {
return (
<span className={cx(`${classPrefix}-item`, itemClassName)}>
{option.label &&
selfVariableName &&
option.value === selfVariableName && (
<Badge
classnames={cx}
badge={{
mode: 'text',
text: 'self',
offset: [15, 2]
}}
<div>
<div className={cx(`${classPrefix}-item`, itemClassName)}>
{option.label &&
selfVariableName &&
option.value === selfVariableName && (
<Badge
classnames={cx}
badge={{
mode: 'text',
text: 'self',
offset: [15, 2]
}}
>
<label>{option.label}</label>
</Badge>
)}
{option.label &&
(!selfVariableName || option.value !== selfVariableName) && (
<TooltipWrapper
tooltip={option.description ?? option.label}
tooltipTheme="dark"
>
<label>{option.label}</label>
</TooltipWrapper>
)}
{option?.isMember ? (
<PopOverContainer
popOverContainer={() => document.querySelector('body')}
popOverRender={({onClose}) => (
<ul className={cx(`${classPrefix}-item-oper`)}>
{memberOpers.map((item, i) => {
return (
<li
key={i}
onClick={() =>
handleMemberClick(
{...item, isMember: true},
option,
onClose
)
}
>
<span>{item.label}</span>
</li>
);
})}
</ul>
)}
>
<label>{option.label}</label>
</Badge>
)}
{option.label &&
(!selfVariableName || option.value !== selfVariableName) && (
<label>{option.label}</label>
)}
{option?.tag ? (
<span className={cx(`${classPrefix}-item-tag`)}>
{option.tag}
</span>
) : null}
</span>
{({onClick, ref, isOpened}) => (
<i className="fa fa-ellipsis-h" onClick={onClick} />
)}
</PopOverContainer>
) : null}
{option?.tag ? (
<span className={cx(`${classPrefix}-item-tag`)}>
{option.tag}
</span>
) : null}
</div>
</div>
);
};
function handleMemberClick(item: any, option: any, onClose?: any) {
const pathArr = option.value.split('.');
const value = item.value
.replace('${arr}', pathArr[0])
.replace('${member}', pathArr[1]);
onClose?.();
onSelect?.({
...item,
label: value,
value: value
});
}
function onSearch(term: string) {
const tree = findTreeAll(list, i => ~i.label.indexOf(term));
const tree = filterTree(
list,
(i: any, key: number, level: number, paths: any[]) => {
return !!(
(Array.isArray(i.children) && i.children.length) ||
!!matchSorter([i].concat(paths), term, {
keys: ['label', 'value']
}).length
);
},
1,
true
);
setFilterVars(!term ? list : tree);
}
@ -87,6 +192,13 @@ function VariableList(props: VariableListProps) {
);
}
function handleChange(item: any) {
if (item.isMember) {
return;
}
onSelect?.(item);
}
return (
<div
className={cx(
@ -94,6 +206,7 @@ function VariableList(props: VariableListProps) {
'FormulaEditor-VariableList',
selectMode && `FormulaEditor-VariableList-${selectMode}`
)}
ref={variableListRef}
>
{selectMode === 'tabs' ? (
<Tabs
@ -115,7 +228,7 @@ function VariableList(props: VariableListProps) {
placeholderRender={placeholderRender}
selectMode={item.selectMode}
data={item.children!}
onSelect={onSelect}
onSelect={handleChange}
selfVariableName={selfVariableName}
/>
</Tab>
@ -129,8 +242,9 @@ function VariableList(props: VariableListProps) {
placeholderRender={placeholderRender}
className={cx(`${classPrefix}-base`, 'is-scrollable')}
multiple={false}
expand={expandTree ? 'all' : 'none'}
options={filterVars}
onChange={(item: any) => onSelect?.(item)}
onChange={(item: any) => handleChange(item)}
/>
</div>
) : (
@ -142,7 +256,7 @@ function VariableList(props: VariableListProps) {
className={cx(`${classPrefix}-base`, 'is-scrollable')}
multiple={false}
options={filterVars}
onChange={(item: any) => onSelect?.(item)}
onChange={(item: any) => handleChange(item)}
/>
</div>
)}

View File

@ -9,14 +9,16 @@ import {FormulaEditorProps, VariableItem, FormulaEditor} from './Editor';
export function editorFactory(
dom: HTMLElement,
cm: typeof CodeMirror,
props: any
props: any,
options?: any
) {
registerLaunguageMode(cm);
return cm(dom, {
value: props.value || '',
autofocus: true,
mode: props.evalMode ? 'text/formula' : 'text/formula-template'
mode: props.evalMode ? 'text/formula' : 'text/formula-template',
...options
});
}
@ -32,6 +34,7 @@ export class FormulaPlugin {
autoMarkText() {
const {functions, variables, value} = this.getProps();
if (value) {
// todo functions 也需要自动替换
this.autoMark(variables!);
@ -105,29 +108,49 @@ export class FormulaPlugin {
}
}
insertContent(value: any, type?: 'variable' | 'func') {
const from = this.editor.getCursor();
insertContent(
value: any,
type?: 'variable' | 'func',
className: string = 'cm-field',
toMark: boolean = true
) {
let from = this.editor.getCursor();
const {evalMode} = this.getProps();
if (type === 'variable') {
this.editor.replaceSelection(value.key);
const to = this.editor.getCursor();
this.markText(from, to, value.name, 'cm-field');
if (toMark) {
// 路径中每个变量分别进行标记
let markFrom = from.ch;
value.path.split('.').forEach((label: string, index: number) => {
const val = value.key.split('.')[index];
this.markText(
{line: from.line, ch: markFrom},
{line: to.line, ch: markFrom + val.length},
label,
className
);
markFrom += 1 + val.length;
});
}
!evalMode && this.insertBraces(from, to);
} else if (type === 'func') {
this.editor.replaceSelection(`${value}()`);
const to = this.editor.getCursor();
this.markText(
from,
{
line: to.line,
ch: to.ch - 2
},
value,
'cm-func'
);
toMark &&
this.markText(
from,
{
line: to.line,
ch: to.ch - 2
},
value,
'cm-func'
);
this.editor.setCursor({
line: to.line,
@ -143,11 +166,21 @@ export class FormulaPlugin {
}
} else if (typeof value === 'string') {
this.editor.replaceSelection(value);
// 非变量、非函数,可能是组合模式,也需要标记
toMark && setTimeout(() => this.autoMarkText(), 0);
}
this.editor.focus();
}
setValue(value: string) {
this.editor.setValue(value);
}
getValue() {
return this.editor.getValue();
}
markText(
from: CodeMirror.Position,
to: CodeMirror.Position,
@ -167,15 +200,17 @@ export class FormulaPlugin {
if (!Array.isArray(variables) || !variables.length) {
return;
}
const varMap: {
[propname: string]: string;
} = {};
eachTree(variables, item => {
if (item.value) {
varMap[item.value] = item.label;
varMap[item.value] = item.path ?? '';
}
});
const vars = Object.keys(varMap).sort((a, b) => b.length - a.length);
const editor = this.editor;
const lines = editor.lineCount();
@ -205,6 +240,7 @@ export class FormulaPlugin {
vars.forEach(v => {
let from = 0;
let idx = -1;
while (~(idx = content.indexOf(v, from))) {
const encode = FormulaEditor.replaceStrByIndex(
content,
@ -215,18 +251,22 @@ export class FormulaPlugin {
const reg = FormulaEditor.getRegExpByMode(evalMode, REPLACE_KEY);
if (reg.test(encode)) {
this.markText(
{
line: line,
ch: idx
},
{
line: line,
ch: idx + v.length
},
varMap[v],
'cm-field'
);
let markFrom = idx;
v.split('.').forEach((val: string, index: number) => {
this.markText(
{
line: line,
ch: markFrom
},
{
line: line,
ch: markFrom + val.length
},
varMap[v].split('.')[index],
'cm-field'
);
markFrom += 1 + val.length;
});
}
from = idx + v.length;