feat: 让首页读取运行时布局

This commit is contained in:
que01 committed 2026-09-23 00:00:57 +08:00
1 parent 8ecd94c26a
commit 0f35cab436
2 files changed
+5 -3

No files matched your search

+2 -2
View File
@@ -1,8 +1,8 @@
const { brand, trustContent, offerings } = require("../../utils/linjing-data");
const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace");
Page({
data: { brand, trustContent, offerings, modules: [], theme: {}, hero: { image: "https://images.unsplash.com/photo-1600585154340-be6161a56a0c?auto=format&fit=crop&w=900&q=80", eyebrow: "年度落成实景 · 莫干山庄园", title: "万籁系列 · 铸铜冷锻双轴入户门", slogan: "门高 3.4m · 德国静音地轴", cta: "探索全系作品 →" }, loading: false },
onLoad() { this.setData({ loading: true }); loadWorkspaceWithFallback().then((workspace) => { this.setData({ brand: workspace.brand, trustContent: workspace.trustContent || trustContent, offerings: workspace.offerings || offerings, modules: workspace.modules || [], theme: workspace.theme || {}, loading: false }); wx.setNavigationBarTitle({ title: workspace.brand.name || brand.name }); }); },
data: { brand, trustContent, offerings, modules: [], layout: [], theme: {}, hero: { image: "https://images.unsplash.com/photo-1600585154340-be6161a56a0c?auto=format&fit=crop&w=900&q=80", eyebrow: "年度落成实景 · 莫干山庄园", title: "万籁系列 · 铸铜冷锻双轴入户门", slogan: "门高 3.4m · 德国静音地轴", cta: "探索全系作品 →" }, loading: false },
onLoad() { this.setData({ loading: true }); loadWorkspaceWithFallback().then((workspace) => { this.setData({ brand: workspace.brand, trustContent: workspace.trustContent || trustContent, offerings: workspace.offerings || offerings, modules: workspace.modules || [], layout: workspace.layout?.home || [], theme: workspace.theme || {}, loading: false }); wx.setNavigationBarTitle({ title: workspace.brand.name || brand.name }); }); },
selectOffering(e) { const id = e.detail ? e.detail.id : e.currentTarget.dataset.id; wx.navigateTo({ url: "/pages/offering/detail?id=" + id }); },
goWorks() { wx.switchTab({ url: "/pages/services/index" }); },
goInquiry() { wx.navigateTo({ url: "/pages/inquiry/index" }); },
+3 -1
View File
@@ -24,7 +24,9 @@ function resolveModule(module) {
function resolveRuntime(workspace) {
const modules = Array.isArray(workspace && workspace.modules) ? workspace.modules : [];
return { theme: workspace && workspace.theme ? workspace.theme : FALLBACK_THEME, modules: modules.map(resolveModule), capabilities: workspace && Array.isArray(workspace.capabilities) ? workspace.capabilities : [] };
const resolved = modules.map(resolveModule);
const home = workspace && workspace.layout && Array.isArray(workspace.layout.home) ? workspace.layout.home : resolved.map((item) => item.type);
return { theme: workspace && workspace.theme ? workspace.theme : FALLBACK_THEME, modules: resolved, layout: { home: home.filter((key) => resolved.some((item) => item.type === key)) }, capabilities: workspace && Array.isArray(workspace.capabilities) ? workspace.capabilities : [] };
}
module.exports = { CORE_MODULES, FALLBACK_THEME, resolveRuntime };