mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-13 01:21:58 +00:00
Merge branch 'v/0.8.0' of gitlab.alibaba-inc.com:ali-lowcode/ali-lowcode-engine into v/0.8.0
This commit is contained in:
commit
efd6cc4ea6
@ -1,20 +1,20 @@
|
||||
import { contribution, run } from '@ali/lowcode-runtime';
|
||||
import { app } from '@ali/lowcode-runtime';
|
||||
import Renderer from '@ali/lowcode-react-renderer';
|
||||
import FusionLoading from './plugins/loading/fusion';
|
||||
import BasicLayout from './layouts/BasicLayout';
|
||||
import Preview from './plugins/provider';
|
||||
|
||||
// 注册渲染模块
|
||||
contribution.registerRenderer(Renderer);
|
||||
app.registerRenderer(Renderer);
|
||||
|
||||
// 注册布局组件,可注册多个
|
||||
contribution.registerLayout('BasicLayout', BasicLayout);
|
||||
app.registerLayout('BasicLayout', BasicLayout);
|
||||
|
||||
// 注册页面 Loading
|
||||
contribution.registerLoading(FusionLoading);
|
||||
app.registerLoading(FusionLoading);
|
||||
|
||||
// appKey:应用唯一标识
|
||||
contribution.registerProvider(new Preview({ appKey: 'lowcode_demo' }));
|
||||
app.registerProvider(Preview);
|
||||
|
||||
// 启动应用
|
||||
run();
|
||||
app.run();
|
||||
|
||||
@ -8,7 +8,7 @@ import utils from '../config/utils';
|
||||
// 定制加载应用配置的逻辑
|
||||
export default class Preview extends ReactProvider {
|
||||
// 定制获取、处理应用配置(组件、插件、路由模式、布局等)的逻辑
|
||||
async getAppData(appkey: string): Promise<any> {
|
||||
async getAppData(): Promise<any> {
|
||||
const { history, layout, containerId } = appConfig;
|
||||
const appSchemaStr: any = localStorage.getItem('lce-dev-store');
|
||||
if (!appSchemaStr) {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ali/lowcode-runtime",
|
||||
"version": "0.8.5",
|
||||
"version": "0.8.6",
|
||||
"description": "Runtime for Ali lowCode engine",
|
||||
"files": [
|
||||
"es",
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { ReactType } from 'react';
|
||||
import { IProvider } from './provider/base';
|
||||
import Provider from './provider';
|
||||
|
||||
class Contribution {
|
||||
export default class Container {
|
||||
private renderer: ReactType | null = null;
|
||||
private layouts: { [key: string]: ReactType } = {};
|
||||
private loading: ReactType | null = null;
|
||||
@ -25,8 +25,13 @@ class Contribution {
|
||||
this.loading = component;
|
||||
}
|
||||
|
||||
registerProvider(provider: IProvider) {
|
||||
this.provider = provider;
|
||||
registerProvider(CustomProvider: any) {
|
||||
if (Provider.isPrototypeOf(CustomProvider)) {
|
||||
this.provider = new CustomProvider();
|
||||
} else {
|
||||
const identifier = (CustomProvider && CustomProvider.name) || 'registered Provider';
|
||||
throw new Error(`${identifier} is not a child class of Provider`);
|
||||
}
|
||||
}
|
||||
|
||||
getLayout(componentName: string) {
|
||||
@ -48,5 +53,3 @@ class Contribution {
|
||||
return this.provider;
|
||||
}
|
||||
}
|
||||
|
||||
export default new Contribution();
|
||||
49
packages/runtime/src/core/index.ts
Normal file
49
packages/runtime/src/core/index.ts
Normal file
@ -0,0 +1,49 @@
|
||||
import { ReactType } from 'react';
|
||||
import Container from './container';
|
||||
import run from './run';
|
||||
|
||||
class App {
|
||||
private container: Container;
|
||||
|
||||
constructor() {
|
||||
this.container = new Container();
|
||||
}
|
||||
|
||||
run() {
|
||||
run();
|
||||
}
|
||||
|
||||
registerRenderer(renderer: ReactType): any {
|
||||
this.container.registerRenderer(renderer);
|
||||
}
|
||||
|
||||
registerLayout(componentName: string, Layout: ReactType): any {
|
||||
this.container.registerLayout(componentName, Layout);
|
||||
}
|
||||
|
||||
registerLoading(component: ReactType) {
|
||||
this.container.registerLoading(component);
|
||||
}
|
||||
|
||||
registerProvider(CustomProvider: any) {
|
||||
this.container.registerProvider(CustomProvider);
|
||||
}
|
||||
|
||||
getLayout(componentName: string) {
|
||||
return this.container.getLayout(componentName);
|
||||
}
|
||||
|
||||
getRenderer(): ReactType | null {
|
||||
return this.container.getRenderer();
|
||||
}
|
||||
|
||||
getLoading(): ReactType | null {
|
||||
return this.container.getLoading();
|
||||
}
|
||||
|
||||
getProvider() {
|
||||
return this.container.getProvider();
|
||||
}
|
||||
}
|
||||
|
||||
export default new App();
|
||||
@ -38,10 +38,6 @@ interface IAppData {
|
||||
constants?: IConstants;
|
||||
}
|
||||
|
||||
interface IOptions {
|
||||
appKey: string;
|
||||
}
|
||||
|
||||
export interface ComponentProps {
|
||||
[key: string]: any;
|
||||
}
|
||||
@ -90,22 +86,21 @@ export interface ComponentModel {
|
||||
dataSource?: DataSource;
|
||||
lifeCycles?: LifeCycles;
|
||||
methods?: Methods;
|
||||
children?: ComponentModel[];
|
||||
children?: ComponentModel[] | string[];
|
||||
condition?: JSExpression | boolean;
|
||||
loop?: string[];
|
||||
loopArgs?: string[];
|
||||
}
|
||||
|
||||
export interface IProvider {
|
||||
init?(): void;
|
||||
getAppData?(appkey: string): Promise<IAppData | undefined>;
|
||||
getPageData?(pageId: string): Promise<ComponentModel | undefined>;
|
||||
getLazyComponent?(pageId: string, props: any): any;
|
||||
createApp?(): void;
|
||||
}
|
||||
// export interface IProvider {
|
||||
// init?(): void;
|
||||
// getAppData?(appkey: string): Promise<IAppData | undefined>;
|
||||
// getPageData?(pageId: string): Promise<ComponentModel | undefined>;
|
||||
// getLazyComponent?(pageId: string, props: any): any;
|
||||
// createApp?(): void;
|
||||
// }
|
||||
|
||||
export default class Provider implements IProvider {
|
||||
private appKey = '';
|
||||
export default class Provider {
|
||||
private components: IComponents = {};
|
||||
private utils: IUtils = {};
|
||||
private constants: IConstants = {};
|
||||
@ -116,16 +111,14 @@ export default class Provider implements IProvider {
|
||||
private containerId = '';
|
||||
private lazyElementsMap: { [key: string]: any } = {};
|
||||
|
||||
constructor(options: IOptions) {
|
||||
const { appKey } = options;
|
||||
this.appKey = appKey;
|
||||
constructor() {
|
||||
this.init();
|
||||
}
|
||||
|
||||
async(): Promise<IAppConfig> {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const appData = await this.getAppData(this.appKey || '');
|
||||
const appData = await this.getAppData();
|
||||
if (!appData) {
|
||||
return;
|
||||
}
|
||||
@ -154,11 +147,11 @@ export default class Provider implements IProvider {
|
||||
console.log('init');
|
||||
}
|
||||
|
||||
async getAppData(appkey: string): Promise<IAppData | undefined> {
|
||||
getAppData(): any {
|
||||
throw new Error('Method called "getPageData" not implemented.');
|
||||
}
|
||||
|
||||
async getPageData(pageId: string): Promise<ComponentModel | undefined> {
|
||||
getPageData(pageId?: string): any {
|
||||
throw new Error('Method called "getPageData" not implemented.');
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { createElement, ReactElement } from 'react';
|
||||
import { Router } from '@ali/recore';
|
||||
import contribution from '../../contribution';
|
||||
import Provider from '../base';
|
||||
import app from '../../index';
|
||||
import Provider from '..';
|
||||
import LazyComponent from './lazy-component';
|
||||
|
||||
export default class ReactProvider extends Provider {
|
||||
@ -52,7 +52,7 @@ export default class ReactProvider extends Provider {
|
||||
return App;
|
||||
}
|
||||
const { componentName: layoutName, props: layoutProps } = layoutConfig;
|
||||
const Layout = contribution.getLayout(layoutName);
|
||||
const Layout = app.getLayout(layoutName);
|
||||
if (Layout) {
|
||||
App = (props: any) => createElement(Layout, layoutProps, RouterView({ props }));
|
||||
} else {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { Component, createElement } from 'react';
|
||||
import contribution from '../../contribution';
|
||||
import app from '../../index';
|
||||
|
||||
interface IProps {
|
||||
getPageData: () => any;
|
||||
@ -29,8 +29,8 @@ export default class LazyComponent extends Component<IProps, IState> {
|
||||
render() {
|
||||
const { getPageData, ...restProps } = this.props;
|
||||
const { schema } = this.state;
|
||||
const Renderer = contribution.getRenderer();
|
||||
const Loading = contribution.getLoading();
|
||||
const Renderer = app.getRenderer();
|
||||
const Loading = app.getLoading();
|
||||
if (!Renderer || !schema) {
|
||||
if (!Loading) {
|
||||
return null;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { ReactType } from 'react';
|
||||
import { runApp } from '@ali/recore';
|
||||
import { HashHistoryBuildOptions, BrowserHistoryBuildOptions, MemoryHistoryBuildOptions } from '@recore/history';
|
||||
import contribution from './contribution';
|
||||
import app from './index';
|
||||
|
||||
export type HistoryOptions = {
|
||||
mode?: HistoryMode;
|
||||
@ -47,7 +47,7 @@ function transformConfig(config: IAppConfig | (() => IAppConfig)): IRecoreAppCon
|
||||
}
|
||||
|
||||
export default function run(config?: IAppConfig | (() => IAppConfig)) {
|
||||
const provider = contribution.getProvider();
|
||||
const provider = app.getProvider();
|
||||
if (config) {
|
||||
config = transformConfig(config);
|
||||
const App = provider.createApp();
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
import { navigator, Router } from '@ali/recore';
|
||||
import run from './core/run';
|
||||
import contribution from './core/contribution';
|
||||
import Provider from './core/provider/base';
|
||||
import Provider from './core/provider';
|
||||
import ReactProvider from './core/provider/react';
|
||||
import app from './core';
|
||||
import * as Utils from './utils';
|
||||
|
||||
export { run, Router, contribution, Provider, ReactProvider, navigator, Utils };
|
||||
export { app, Router, Provider, ReactProvider, navigator, Utils };
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user