mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-15 05:36:39 +00:00
feat: 增加loading扩展点
This commit is contained in:
parent
e48307dc6d
commit
3a1e900149
44
packages/runtime-framework/src/boot.ts
Normal file
44
packages/runtime-framework/src/boot.ts
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import { ComponentClass, FunctionComponent } from 'react';
|
||||||
|
|
||||||
|
type TComponent = ComponentClass | FunctionComponent;
|
||||||
|
|
||||||
|
class Trunk {
|
||||||
|
private renderer: TComponent | null = null;
|
||||||
|
private layouts: { [key: string]: TComponent } = {};
|
||||||
|
private loading: TComponent | null = null;
|
||||||
|
|
||||||
|
public registerRenderer(renderer: TComponent): any {
|
||||||
|
this.renderer = renderer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public registerLayout(componentName: string, Layout: TComponent): any {
|
||||||
|
if (!componentName || !Layout) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.layouts[componentName] = Layout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public registerLoading(component: TComponent) {
|
||||||
|
if (!component) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.loading = component;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getLayout(componentName: string) {
|
||||||
|
if (!componentName) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return this.layouts[componentName];
|
||||||
|
}
|
||||||
|
|
||||||
|
public getRenderer(): TComponent | null {
|
||||||
|
return this.renderer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getLoading(): TComponent | null {
|
||||||
|
return this.loading;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new Trunk();
|
||||||
@ -1,5 +1,5 @@
|
|||||||
import { Component, createElement } from 'react';
|
import { Component, createElement } from 'react';
|
||||||
import Trunk from './trunk';
|
import Boot from './boot';
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
getPageData: () => any;
|
getPageData: () => any;
|
||||||
@ -11,6 +11,8 @@ interface IState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default class LazyComponent extends Component<IProps, IState> {
|
export default class LazyComponent extends Component<IProps, IState> {
|
||||||
|
private schema: object | null = null;
|
||||||
|
|
||||||
constructor(props: IProps) {
|
constructor(props: IProps) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
@ -20,19 +22,25 @@ export default class LazyComponent extends Component<IProps, IState> {
|
|||||||
|
|
||||||
public async componentDidMount() {
|
public async componentDidMount() {
|
||||||
const { getPageData } = this.props;
|
const { getPageData } = this.props;
|
||||||
if (getPageData) {
|
if (getPageData && !this.schema) {
|
||||||
const schema = await getPageData();
|
const schema = await getPageData();
|
||||||
|
this.schema = schema;
|
||||||
this.setState({ schema });
|
this.setState({ schema });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public render() {
|
public render() {
|
||||||
const Renderer = Trunk.getRenderer();
|
|
||||||
if (!Renderer) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
const { getPageData, ...restProps } = this.props;
|
const { getPageData, ...restProps } = this.props;
|
||||||
const { schema } = this.state;
|
const { schema } = this.state;
|
||||||
|
const Renderer = Boot.getRenderer();
|
||||||
|
const Loading = Boot.getLoading();
|
||||||
|
if (!Renderer || !schema) {
|
||||||
|
if (!Loading) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// loading扩展点
|
||||||
|
return createElement(Loading);
|
||||||
|
}
|
||||||
return createElement(Renderer as any, { schema, ...restProps });
|
return createElement(Renderer as any, { schema, ...restProps });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,30 +0,0 @@
|
|||||||
import { ComponentClass } from 'react';
|
|
||||||
|
|
||||||
class Trunk {
|
|
||||||
private renderer: ComponentClass | null = null;
|
|
||||||
private layouts: { [key: string]: ComponentClass } = {};
|
|
||||||
|
|
||||||
public registerRenderer(renderer: ComponentClass): any {
|
|
||||||
this.renderer = renderer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public registerLayout(componentName: string, Layout: ComponentClass): any {
|
|
||||||
if (!componentName || !Layout) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.layouts[componentName] = Layout;
|
|
||||||
}
|
|
||||||
|
|
||||||
public getLayout(componentName: string) {
|
|
||||||
if (!componentName) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return this.layouts[componentName];
|
|
||||||
}
|
|
||||||
|
|
||||||
public getRenderer(): ComponentClass | null {
|
|
||||||
return this.renderer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default new Trunk();
|
|
||||||
Loading…
x
Reference in New Issue
Block a user