mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-15 17:31:18 +08:00
feat:补充page/service/wizard的异步变量&优化事件面板上下文获取
Change-Id: I4bd19ec28df657ba2991564b9b154b79f8991e5b
This commit is contained in:
parent
9749db22a0
commit
da1aa2e1e0
@ -889,8 +889,8 @@ export class FormPlugin extends BasePlugin {
|
|||||||
...jsonToJsonSchema(data)
|
...jsonToJsonSchema(data)
|
||||||
};
|
};
|
||||||
|
|
||||||
scope.removeSchema(jsonschema.$id);
|
scope?.removeSchema(jsonschema.$id);
|
||||||
scope.addSchema(jsonschema);
|
scope?.addSchema(jsonschema);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import {getSchemaTpl} from 'amis-editor-core';
|
|||||||
import {getEventControlConfig} from '../renderer/event-control/helper';
|
import {getEventControlConfig} from '../renderer/event-control/helper';
|
||||||
import {RendererPluginAction, RendererPluginEvent} from 'amis-editor-core';
|
import {RendererPluginAction, RendererPluginEvent} from 'amis-editor-core';
|
||||||
import type {SchemaObject} from 'amis/lib/Schema';
|
import type {SchemaObject} from 'amis/lib/Schema';
|
||||||
|
import {jsonToJsonSchema, EditorNodeType} from 'amis-editor-core';
|
||||||
|
|
||||||
export class PagePlugin extends BasePlugin {
|
export class PagePlugin extends BasePlugin {
|
||||||
// 关联渲染器名字
|
// 关联渲染器名字
|
||||||
@ -388,6 +389,19 @@ export class PagePlugin extends BasePlugin {
|
|||||||
])
|
])
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
rendererBeforeDispatchEvent(node: EditorNodeType, e: any, data: any) {
|
||||||
|
if (e === 'inited') {
|
||||||
|
const scope = this.manager.dataSchema.getScope(`${node.id}-${node.type}`);
|
||||||
|
const jsonschema: any = {
|
||||||
|
$id: 'pageInitedData',
|
||||||
|
...jsonToJsonSchema(data)
|
||||||
|
};
|
||||||
|
|
||||||
|
scope?.removeSchema(jsonschema.$id);
|
||||||
|
scope?.addSchema(jsonschema);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
registerEditorPlugin(PagePlugin);
|
registerEditorPlugin(PagePlugin);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import {Button} from 'amis';
|
import {Button} from 'amis';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import {registerEditorPlugin} from 'amis-editor-core';
|
import {EditorNodeType, jsonToJsonSchema, registerEditorPlugin} from 'amis-editor-core';
|
||||||
import {BaseEventContext, BasePlugin, RegionConfig} from 'amis-editor-core';
|
import {BaseEventContext, BasePlugin, RegionConfig} from 'amis-editor-core';
|
||||||
import {getSchemaTpl} from 'amis-editor-core';
|
import {getSchemaTpl} from 'amis-editor-core';
|
||||||
import {getEventControlConfig} from '../renderer/event-control/helper';
|
import {getEventControlConfig} from '../renderer/event-control/helper';
|
||||||
@ -222,6 +222,19 @@ export class ServicePlugin extends BasePlugin {
|
|||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
rendererBeforeDispatchEvent(node: EditorNodeType, e: any, data: any) {
|
||||||
|
if (e === 'fetchInited') {
|
||||||
|
const scope = this.manager.dataSchema.getScope(`${node.id}-${node.type}`);
|
||||||
|
const jsonschema: any = {
|
||||||
|
$id: 'serviceFetchInitedData',
|
||||||
|
...jsonToJsonSchema(data)
|
||||||
|
};
|
||||||
|
|
||||||
|
scope?.removeSchema(jsonschema.$id);
|
||||||
|
scope?.addSchema(jsonschema);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
registerEditorPlugin(ServicePlugin);
|
registerEditorPlugin(ServicePlugin);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import {registerEditorPlugin} from 'amis-editor-core';
|
import {EditorNodeType, jsonToJsonSchema, registerEditorPlugin} from 'amis-editor-core';
|
||||||
import {
|
import {
|
||||||
BaseEventContext,
|
BaseEventContext,
|
||||||
BasePlugin,
|
BasePlugin,
|
||||||
@ -939,6 +939,19 @@ export class WizardPlugin extends BasePlugin {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
rendererBeforeDispatchEvent(node: EditorNodeType, e: any, data: any) {
|
||||||
|
if (e === 'inited') {
|
||||||
|
const scope = this.manager.dataSchema.getScope(`${node.id}-${node.type}`);
|
||||||
|
const jsonschema: any = {
|
||||||
|
$id: 'wizardInitedData',
|
||||||
|
...jsonToJsonSchema(data)
|
||||||
|
};
|
||||||
|
|
||||||
|
scope?.removeSchema(jsonschema.$id);
|
||||||
|
scope?.addSchema(jsonschema);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
registerEditorPlugin(WizardPlugin);
|
registerEditorPlugin(WizardPlugin);
|
||||||
|
@ -1149,7 +1149,7 @@ export const getEventControlConfig = (
|
|||||||
'id'
|
'id'
|
||||||
);
|
);
|
||||||
const dataSchema: any = await manager.getContextSchemas(
|
const dataSchema: any = await manager.getContextSchemas(
|
||||||
schema.$$id,
|
schema?.$$id,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
const dataSchemaIns = new DataSchema(dataSchema || []);
|
const dataSchemaIns = new DataSchema(dataSchema || []);
|
||||||
|
@ -83,7 +83,6 @@ interface EventControlState {
|
|||||||
}
|
}
|
||||||
| undefined;
|
| undefined;
|
||||||
type: 'update' | 'add';
|
type: 'update' | 'add';
|
||||||
rawVariables: ContextVariables[]; // 外部获取的上下文变量
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class EventControl extends React.Component<
|
export class EventControl extends React.Component<
|
||||||
@ -95,7 +94,6 @@ export class EventControl extends React.Component<
|
|||||||
[prop: string]: Sortable;
|
[prop: string]: Sortable;
|
||||||
} = {};
|
} = {};
|
||||||
drag?: HTMLElement | null;
|
drag?: HTMLElement | null;
|
||||||
isUnmount: boolean;
|
|
||||||
|
|
||||||
constructor(props: EventControlProps) {
|
constructor(props: EventControlProps) {
|
||||||
super(props);
|
super(props);
|
||||||
@ -110,23 +108,16 @@ export class EventControl extends React.Component<
|
|||||||
eventPanelActive[event.eventName] = true;
|
eventPanelActive[event.eventName] = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
this.isUnmount = false;
|
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
onEvent: value ?? this.generateEmptyDefault(pluginEvents),
|
onEvent: value ?? this.generateEmptyDefault(pluginEvents),
|
||||||
events: pluginEvents,
|
events: pluginEvents,
|
||||||
eventPanelActive,
|
eventPanelActive,
|
||||||
showAcionDialog: false,
|
showAcionDialog: false,
|
||||||
actionData: undefined,
|
actionData: undefined,
|
||||||
rawVariables: [],
|
|
||||||
type: 'add'
|
type: 'add'
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
|
||||||
this.loadContextVariables();
|
|
||||||
}
|
|
||||||
|
|
||||||
componentDidUpdate(
|
componentDidUpdate(
|
||||||
prevProps: EventControlProps,
|
prevProps: EventControlProps,
|
||||||
prevState: EventControlState
|
prevState: EventControlState
|
||||||
@ -142,26 +133,6 @@ export class EventControl extends React.Component<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
|
||||||
this.isUnmount = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取上下文变量
|
|
||||||
*/
|
|
||||||
async loadContextVariables() {
|
|
||||||
const {getContextSchemas} = this.props;
|
|
||||||
|
|
||||||
// 获取上下文变量
|
|
||||||
if (getContextSchemas) {
|
|
||||||
const dataSchemaIns = await getContextSchemas();
|
|
||||||
const variables = dataSchemaIns?.getDataPropsAsOptions();
|
|
||||||
if (!this.isUnmount) {
|
|
||||||
this.setState({rawVariables: variables});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
generateEmptyDefault(events: RendererPluginEvent[]) {
|
generateEmptyDefault(events: RendererPluginEvent[]) {
|
||||||
const onEvent: ActionEventConfig = {};
|
const onEvent: ActionEventConfig = {};
|
||||||
events.forEach((event: RendererPluginEvent) => {
|
events.forEach((event: RendererPluginEvent) => {
|
||||||
@ -510,7 +481,14 @@ export class EventControl extends React.Component<
|
|||||||
actionTree,
|
actionTree,
|
||||||
allComponents
|
allComponents
|
||||||
} = this.props;
|
} = this.props;
|
||||||
const {rawVariables} = this.state;
|
|
||||||
|
let rawVariables = [];
|
||||||
|
// 获取绑定事件的组件上下文变量
|
||||||
|
if (getContextSchemas) {
|
||||||
|
const dataSchemaIns = await getContextSchemas();
|
||||||
|
rawVariables = dataSchemaIns?.getDataPropsAsOptions();
|
||||||
|
}
|
||||||
|
|
||||||
// 收集事件变量
|
// 收集事件变量
|
||||||
const eventVariables = this.getEventVariables(data);
|
const eventVariables = this.getEventVariables(data);
|
||||||
const variables = [...eventVariables, ...rawVariables];
|
const variables = [...eventVariables, ...rawVariables];
|
||||||
@ -533,7 +511,7 @@ export class EventControl extends React.Component<
|
|||||||
item => item.label === `${rendererName}变量`
|
item => item.label === `${rendererName}变量`
|
||||||
);
|
);
|
||||||
setValueDs = curVariable?.children?.filter(
|
setValueDs = curVariable?.children?.filter(
|
||||||
item => item.value !== '$$id'
|
(item: ContextVariables) => item.value !== '$$id'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -148,7 +148,7 @@ setSchemaTpl('labelHide', () =>
|
|||||||
pipeIn: (value: any) => value === false,
|
pipeIn: (value: any) => value === false,
|
||||||
pipeOut: (value: any) => (value === true ? false : ''),
|
pipeOut: (value: any) => (value === true ? false : ''),
|
||||||
visibleOn:
|
visibleOn:
|
||||||
'__props__.formMode === "horizontal" || data.mode === "horizontal" || data.label === false'
|
'this.__props__ && this.__props__.formMode === "horizontal" || data.mode === "horizontal" || data.label === false'
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user