feat: 支持多 pages 的 schema 结构

This commit is contained in:
carlos.czw 2020-08-20 11:21:02 +08:00
parent 8029905ffd
commit d9b5adbc04

View File

@ -32,27 +32,32 @@ const pages = Object.assign(project, {
if (!pages || !Array.isArray(pages) || pages.length === 0) { if (!pages || !Array.isArray(pages) || pages.length === 0) {
throw new Error('pages schema 不合法'); throw new Error('pages schema 不合法');
} }
// todo: miniapp
let componentsTree: any; const componentsTree: any = [];
if (isPageDataV1(pages[0])) { pages.forEach((item: any) => {
componentsTree = [pages[0].layout]; if (isPageDataV1(item)) {
componentsTree.push(item.layout);
} else { } else {
componentsTree = pages[0].componentsTree; componentsTree.push(item.componentsTree[0]);
if (componentsTree[0]) {
componentsTree[0].componentName = componentsTree[0].componentName || 'Page';
// FIXME
if (componentsTree[0].componentName === 'Page' ||
componentsTree[0].componentName === 'Component') {
componentsTree[0].methods = {};
} }
});
componentsTree.forEach((item: any) => {
item.componentName = item.componentName || 'Page';
if (item.componentName === 'Page' || item.componentName === 'Component') {
item.methods = {};
} }
} });
project.load({ console.log(pages, componentsTree);
project.load(
{
version: '1.0.0', version: '1.0.0',
componentsMap: [], componentsMap: [],
componentsTree, componentsTree,
config: project.config config: project.config,
}, true); },
true,
);
}, },
addPage(data: OldPageData | RootSchema) { addPage(data: OldPageData | RootSchema) {
if (isPageDataV1(data)) { if (isPageDataV1(data)) {