mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-12 03:01:16 +00:00
feat: lowcode component add error placeholder
This commit is contained in:
parent
9cec5d833c
commit
9228a2baa7
@ -39,10 +39,6 @@ export class DocumentInstance {
|
|||||||
|
|
||||||
private disposeFunctions: Array<() => void> = [];
|
private disposeFunctions: Array<() => void> = [];
|
||||||
|
|
||||||
constructor(readonly container: SimulatorRendererContainer, readonly document: DocumentModel) {
|
|
||||||
makeObservable(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@obx.ref private _components: any = {};
|
@obx.ref private _components: any = {};
|
||||||
|
|
||||||
@computed get components(): object {
|
@computed get components(): object {
|
||||||
@ -98,6 +94,10 @@ export class DocumentInstance {
|
|||||||
return this.document.id;
|
return this.document.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constructor(readonly container: SimulatorRendererContainer, readonly document: DocumentModel) {
|
||||||
|
makeObservable(this);
|
||||||
|
}
|
||||||
|
|
||||||
private unmountInstance(id: string, instance: ReactInstance) {
|
private unmountInstance(id: string, instance: ReactInstance) {
|
||||||
const instances = this.instancesMap.get(id);
|
const instances = this.instancesMap.get(id);
|
||||||
if (instances) {
|
if (instances) {
|
||||||
@ -170,8 +170,7 @@ export class DocumentInstance {
|
|||||||
host.setInstance(this.document.id, id, instances);
|
host.setInstance(this.document.id, id, instances);
|
||||||
}
|
}
|
||||||
|
|
||||||
mountContext(docId: string, id: string, ctx: object) {
|
mountContext() {
|
||||||
// this.ctxMap.set(id, ctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getNode(id: string): Node | null {
|
getNode(id: string): Node | null {
|
||||||
@ -195,6 +194,60 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
|
|||||||
return this._documentInstances;
|
return this._documentInstances;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@obx private _layout: any = null;
|
||||||
|
|
||||||
|
@computed get layout(): any {
|
||||||
|
// TODO: parse layout Component
|
||||||
|
return this._layout;
|
||||||
|
}
|
||||||
|
|
||||||
|
set layout(value: any) {
|
||||||
|
this._layout = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _libraryMap: { [key: string]: string } = {};
|
||||||
|
|
||||||
|
private _components: any = {};
|
||||||
|
|
||||||
|
get components(): object {
|
||||||
|
// 根据 device 选择不同组件,进行响应式
|
||||||
|
// 更好的做法是,根据 device 选择加载不同的组件资源,甚至是 simulatorUrl
|
||||||
|
return this._components;
|
||||||
|
}
|
||||||
|
// context from: utils、constants、history、location、match
|
||||||
|
@obx.ref private _appContext: any = {};
|
||||||
|
@computed get context(): any {
|
||||||
|
return this._appContext;
|
||||||
|
}
|
||||||
|
@obx.ref private _designMode: string = 'design';
|
||||||
|
@computed get designMode(): any {
|
||||||
|
return this._designMode;
|
||||||
|
}
|
||||||
|
@obx.ref private _device: string = 'default';
|
||||||
|
@computed get device() {
|
||||||
|
return this._device;
|
||||||
|
}
|
||||||
|
@obx.ref private _locale: string | undefined = undefined;
|
||||||
|
@computed get locale() {
|
||||||
|
return this._locale;
|
||||||
|
}
|
||||||
|
@obx.ref private _componentsMap = {};
|
||||||
|
@computed get componentsMap(): any {
|
||||||
|
return this._componentsMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否为画布自动渲染
|
||||||
|
*/
|
||||||
|
autoRender = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 画布是否自动监听事件来重绘节点
|
||||||
|
*/
|
||||||
|
autoRepaintNode = true;
|
||||||
|
|
||||||
|
private _running = false;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
makeObservable(this);
|
makeObservable(this);
|
||||||
this.autoRender = host.autoRender;
|
this.autoRender = host.autoRender;
|
||||||
@ -306,19 +359,6 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@obx private _layout: any = null;
|
|
||||||
|
|
||||||
@computed get layout(): any {
|
|
||||||
// TODO: parse layout Component
|
|
||||||
return this._layout;
|
|
||||||
}
|
|
||||||
|
|
||||||
set layout(value: any) {
|
|
||||||
this._layout = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private _libraryMap: { [key: string]: string } = {};
|
|
||||||
|
|
||||||
private buildComponents() {
|
private buildComponents() {
|
||||||
this._components = buildComponents(
|
this._components = buildComponents(
|
||||||
this._libraryMap,
|
this._libraryMap,
|
||||||
@ -330,44 +370,6 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
|
|||||||
...this._components,
|
...this._components,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
private _components: any = {};
|
|
||||||
|
|
||||||
get components(): object {
|
|
||||||
// 根据 device 选择不同组件,进行响应式
|
|
||||||
// 更好的做法是,根据 device 选择加载不同的组件资源,甚至是 simulatorUrl
|
|
||||||
return this._components;
|
|
||||||
}
|
|
||||||
// context from: utils、constants、history、location、match
|
|
||||||
@obx.ref private _appContext: any = {};
|
|
||||||
@computed get context(): any {
|
|
||||||
return this._appContext;
|
|
||||||
}
|
|
||||||
@obx.ref private _designMode: string = 'design';
|
|
||||||
@computed get designMode(): any {
|
|
||||||
return this._designMode;
|
|
||||||
}
|
|
||||||
@obx.ref private _device: string = 'default';
|
|
||||||
@computed get device() {
|
|
||||||
return this._device;
|
|
||||||
}
|
|
||||||
@obx.ref private _locale: string | undefined = undefined;
|
|
||||||
@computed get locale() {
|
|
||||||
return this._locale;
|
|
||||||
}
|
|
||||||
@obx.ref private _componentsMap = {};
|
|
||||||
@computed get componentsMap(): any {
|
|
||||||
return this._componentsMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否为画布自动渲染
|
|
||||||
*/
|
|
||||||
autoRender = true;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 画布是否自动监听事件来重绘节点
|
|
||||||
*/
|
|
||||||
autoRepaintNode = true;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 加载资源
|
* 加载资源
|
||||||
@ -457,6 +459,7 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
|
|||||||
appHelper: renderer.context,
|
appHelper: renderer.context,
|
||||||
rendererName: 'LowCodeRenderer',
|
rendererName: 'LowCodeRenderer',
|
||||||
thisRequiredInJSE: host.thisRequiredInJSE,
|
thisRequiredInJSE: host.thisRequiredInJSE,
|
||||||
|
faultComponent: host.faultComponent,
|
||||||
customCreateElement: (Comp: any, props: any, children: any) => {
|
customCreateElement: (Comp: any, props: any, children: any) => {
|
||||||
const componentMeta = host.currentDocument?.getComponentMeta(Comp.displayName);
|
const componentMeta = host.currentDocument?.getComponentMeta(Comp.displayName);
|
||||||
if (componentMeta?.isModal) {
|
if (componentMeta?.isModal) {
|
||||||
@ -479,8 +482,6 @@ export class SimulatorRendererContainer implements BuiltinSimulatorRenderer {
|
|||||||
return LowCodeComp;
|
return LowCodeComp;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _running = false;
|
|
||||||
|
|
||||||
run() {
|
run() {
|
||||||
if (this._running) {
|
if (this._running) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -86,8 +86,9 @@ export default function rendererFactory(): IRenderComponent {
|
|||||||
debug(`entry.componentWillUnmount - ${this.props?.schema?.componentName}`);
|
debug(`entry.componentWillUnmount - ${this.props?.schema?.componentName}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async componentDidCatch(e: any) {
|
componentDidCatch(error: Error) {
|
||||||
console.warn(e);
|
this.state.engineRenderError = true;
|
||||||
|
this.state.error = error;
|
||||||
}
|
}
|
||||||
|
|
||||||
shouldComponentUpdate(nextProps: IRendererProps) {
|
shouldComponentUpdate(nextProps: IRendererProps) {
|
||||||
@ -182,6 +183,13 @@ export default function rendererFactory(): IRenderComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.state && this.state.engineRenderError) {
|
||||||
|
return createElement(this.getFaultComponent(), {
|
||||||
|
...this.props,
|
||||||
|
error: this.state.error,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (Comp) {
|
if (Comp) {
|
||||||
return createElement(AppContext.Provider, { value: {
|
return createElement(AppContext.Provider, { value: {
|
||||||
appHelper,
|
appHelper,
|
||||||
|
|||||||
@ -323,10 +323,10 @@ export interface IRenderComponent {
|
|||||||
new(props: IRendererProps, context: any): IGeneralComponent<IRendererProps, IRendererState> & {
|
new(props: IRendererProps, context: any): IGeneralComponent<IRendererProps, IRendererState> & {
|
||||||
[x: string]: any;
|
[x: string]: any;
|
||||||
__getRef: (ref: any) => void;
|
__getRef: (ref: any) => void;
|
||||||
componentDidMount(): Promise<void>;
|
componentDidMount(): Promise<void> | void;
|
||||||
componentDidUpdate(): Promise<void>;
|
componentDidUpdate(): Promise<void> | void;
|
||||||
componentWillUnmount(): Promise<void>;
|
componentWillUnmount(): Promise<void> | void;
|
||||||
componentDidCatch(e: any): Promise<void>;
|
componentDidCatch(e: any): Promise<void> | void;
|
||||||
shouldComponentUpdate(nextProps: IRendererProps): boolean;
|
shouldComponentUpdate(nextProps: IRendererProps): boolean;
|
||||||
isValidComponent(SetComponent: any): any;
|
isValidComponent(SetComponent: any): any;
|
||||||
patchDidCatch(SetComponent: any): void;
|
patchDidCatch(SetComponent: any): void;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user