feat: 按视觉模板 manifest 驱动小程序运行时

This commit is contained in:
que01 committed 2026-09-23 14:26:39 +08:00
1 parent 031c81a7c1
commit ce958fc1ae
17 files changed
+149 -26

No files matched your search

@@ -1,5 +1,5 @@
Component({
properties: { hero: { type: Object, value: {} } },
properties: { hero: { type: Object, value: {} }, variant: { type: String, value: "default" } },
methods: {
explore() {
this.triggerEvent("explore");
@@ -1 +1,3 @@
Component({ properties: { brand: { type: Object, value: {} } } });
Component({
properties: { brand: { type: Object, value: {} }, variant: { type: String, value: "default" } },
});
@@ -1,5 +1,8 @@
Component({
properties: { offerings: { type: Array, value: [] } },
properties: {
offerings: { type: Array, value: [] },
variant: { type: String, value: "default" },
},
methods: {
open(e) {
this.triggerEvent("open", { id: e.currentTarget.dataset.id });
@@ -1 +1,3 @@
Component({ properties: { content: { type: Object, value: {} } } });
Component({
properties: { content: { type: Object, value: {} }, variant: { type: String, value: "default" } },
});
@@ -1 +1,3 @@
Component({ properties: { content: { type: Object, value: {} } } });
Component({
properties: { content: { type: Object, value: {} }, variant: { type: String, value: "default" } },
});
+2
View File
@@ -5,6 +5,7 @@ Page({
trustContent: [],
offerings: [],
modules: [],
moduleVariants: {},
layout: [],
theme: {},
hero: {
@@ -35,6 +36,7 @@ Page({
trustContent: workspace.trustContent || [],
offerings: activeOfferings,
modules: workspace.modules || [],
moduleVariants: workspace.moduleVariants || {},
layout,
theme: workspace.theme || {},
hero: {
+5 -5
View File
@@ -1,9 +1,9 @@
<view class="page">
<block wx:for="{{layout}}" wx:key="*this" wx:for-item="moduleKey">
<founder-card wx:if="{{moduleKey === 'founder-card'}}" brand="{{brand}}" />
<brand-hero wx:if="{{moduleKey === 'brand-hero'}}" hero="{{hero}}" bind:explore="goWorks" />
<trust-proof wx:if="{{moduleKey === 'trust-proof'}}" content="{{trustContent}}" />
<trust-manifesto wx:if="{{moduleKey === 'trust-manifesto'}}" content="{{trustContent}}" />
<offering-list wx:if="{{moduleKey === 'offering-list'}}" offerings="{{offerings}}" bind:open="selectOffering" bind:more="goWorks" />
<founder-card wx:if="{{moduleKey === 'founder-card'}}" brand="{{brand}}" variant="{{moduleVariants[moduleKey]}}" />
<brand-hero wx:if="{{moduleKey === 'brand-hero'}}" hero="{{hero}}" variant="{{moduleVariants[moduleKey]}}" bind:explore="goWorks" />
<trust-proof wx:if="{{moduleKey === 'trust-proof'}}" content="{{trustContent}}" variant="{{moduleVariants[moduleKey]}}" />
<trust-manifesto wx:if="{{moduleKey === 'trust-manifesto'}}" content="{{trustContent}}" variant="{{moduleVariants[moduleKey]}}" />
<offering-list wx:if="{{moduleKey === 'offering-list'}}" offerings="{{offerings}}" variant="{{moduleVariants[moduleKey]}}" bind:open="selectOffering" bind:more="goWorks" />
</block>
</view>
+42 -4
View File
@@ -44,19 +44,57 @@ function resolveModule(module) {
};
}
const MANIFEST_TYPE_ALIASES = {
"brand-identity": "founder-card",
hero: "brand-hero",
trust: "trust-proof",
"inquiry-form": "inquiry",
"success-summary": "success-summary",
"records-list": "records",
};
function resolveManifest(workspace) {
const manifest = workspace && workspace.visualTemplateManifest;
if (!manifest || !Array.isArray(manifest.pages)) return null;
const pages = {};
for (const page of manifest.pages) {
pages[page.key] = (page.modules || []).map((module) => ({
...module,
type: MANIFEST_TYPE_ALIASES[module.type] || module.type,
variant: module.variant || "default",
}));
}
return { ...manifest, pages };
}
function resolveRuntime(workspace) {
const modules = Array.isArray(workspace && workspace.modules) ? workspace.modules : [];
const manifest = resolveManifest(workspace);
const manifestHome = manifest && manifest.pages.home;
const manifestModules = manifestHome || [];
const resolved = modules.map(resolveModule);
const home =
workspace && workspace.layout && Array.isArray(workspace.layout.home)
const resolvedTypes = new Set(resolved.map((item) => item.type));
for (const module of manifestModules) {
if (!resolvedTypes.has(module.type)) {
resolved.push(resolveModule(module));
resolvedTypes.add(module.type);
}
}
const home = manifestHome?.length
? manifestHome.map((item) => item.type)
: workspace && workspace.layout && Array.isArray(workspace.layout.home)
? workspace.layout.home
: resolved.map((item) => item.type);
const moduleVariants = {};
for (const item of manifestHome || []) moduleVariants[item.type] = item.variant;
return {
theme: workspace && workspace.theme ? workspace.theme : FALLBACK_THEME,
theme: manifest?.tokens || (workspace && workspace.theme ? workspace.theme : FALLBACK_THEME),
modules: resolved,
layout: { home: home.filter((key) => resolved.some((item) => item.type === key)) },
moduleVariants,
visualManifest: manifest,
capabilities: workspace && Array.isArray(workspace.capabilities) ? workspace.capabilities : [],
};
}
module.exports = { CORE_MODULES, FALLBACK_THEME, resolveRuntime };
module.exports = { CORE_MODULES, FALLBACK_THEME, resolveManifest, resolveRuntime };