chore: 修改接口registerLayout

This commit is contained in:
wuyue.xht 2020-04-01 13:16:44 +08:00
parent 768e71444e
commit de4e0be01d
5 changed files with 42 additions and 9 deletions

View File

@ -8,7 +8,7 @@ import Preview from './plugins/provider';
app.registerRenderer(Renderer);
// 注册布局组件,可注册多个
app.registerLayout('BasicLayout', BasicLayout);
app.registerLayout(BasicLayout, { componentName: 'BasicLayout' });
// 注册页面 Loading
app.registerLoading(FusionLoading);

View File

@ -1,6 +1,6 @@
{
"name": "@ali/lowcode-runtime",
"version": "0.8.6",
"version": "0.8.7",
"description": "Runtime for Ali lowCode engine",
"files": [
"es",

View File

@ -1,6 +1,11 @@
import { ReactType } from 'react';
import Provider from './provider';
export interface ILayoutOptions {
componentName?: string;
props?: any;
}
export default class Container {
private renderer: ReactType | null = null;
private layouts: { [key: string]: ReactType } = {};
@ -11,7 +16,11 @@ export default class Container {
this.renderer = renderer;
}
registerLayout(componentName: string, Layout: ReactType): any {
registerLayout(Layout: ReactType, options: ILayoutOptions): any {
if (!options) {
return;
}
const { componentName } = options;
if (!componentName || !Layout) {
return;
}

View File

@ -1,5 +1,5 @@
import { ReactType } from 'react';
import Container from './container';
import Container, { ILayoutOptions } from './container';
import run from './run';
class App {
@ -17,8 +17,8 @@ class App {
this.container.registerRenderer(renderer);
}
registerLayout(componentName: string, Layout: ReactType): any {
this.container.registerLayout(componentName, Layout);
registerLayout(Layout: ReactType, options: ILayoutOptions): any {
this.container.registerLayout(Layout, options);
}
registerLoading(component: ReactType) {

View File

@ -27,7 +27,7 @@ interface IHistoryConfig {
basement?: string;
}
interface IAppData {
export interface IAppData {
history?: HistoryMode;
layout?: ILayoutConfig;
routes?: IRouterConfig;
@ -36,6 +36,7 @@ interface IAppData {
componentsMap?: IComponentMap[];
utils?: IUtils;
constants?: IConstants;
i18n?: I18n;
}
export interface ComponentProps {
@ -92,6 +93,13 @@ export interface ComponentModel {
loopArgs?: string[];
}
export interface I18n {
'zh-CN': { [key: string]: string };
'en-US': { [key: string]: string };
}
type Locale = 'zh-CN' | 'en-US';
// export interface IProvider {
// init?(): void;
// getAppData?(appkey: string): Promise<IAppData | undefined>;
@ -109,6 +117,7 @@ export default class Provider {
private componentsMap: IComponentMap[] = [];
private history: HistoryMode = 'hash';
private containerId = '';
private i18n: I18n | null = null;
private lazyElementsMap: { [key: string]: any } = {};
constructor() {
@ -118,15 +127,16 @@ export default class Provider {
async(): Promise<IAppConfig> {
return new Promise(async (resolve, reject) => {
try {
const appData = await this.getAppData();
const appData: IAppData = await this.getAppData();
if (!appData) {
return;
}
const { history, layout, routes, containerId, components, componentsMap, utils, constants } = appData;
const { history, layout, routes, containerId, components, componentsMap, utils, constants, i18n } = appData;
this.setHistory(history);
this.setLayoutConfig(layout);
this.setRouterConfig(routes);
this.setContainerId(containerId);
this.setI18n(i18n);
this.registerComponents(components);
this.registerComponentsMap(componentsMap);
this.registerUtils(utils);
@ -220,6 +230,13 @@ export default class Provider {
this.containerId = id;
}
setI18n(i18n: I18n) {
if (!i18n) {
return;
}
this.i18n = i18n;
}
setlazyElement(pageId: string, cache: any) {
if (!pageId || !cache) {
return;
@ -281,6 +298,13 @@ export default class Provider {
return this.containerId;
}
getI18n(locale?: Locale) {
if (!this.i18n) {
return;
}
return locale ? this.i18n[locale] : this.i18n;
}
getlazyElement(pageId: string) {
if (!pageId) {
return;