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.registerRenderer(Renderer);
// 注册布局组件,可注册多个 // 注册布局组件,可注册多个
app.registerLayout('BasicLayout', BasicLayout); app.registerLayout(BasicLayout, { componentName: 'BasicLayout' });
// 注册页面 Loading // 注册页面 Loading
app.registerLoading(FusionLoading); app.registerLoading(FusionLoading);

View File

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

View File

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

View File

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

View File

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