88 lines
2.7 KiB
JavaScript
88 lines
2.7 KiB
JavaScript
const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace");
|
|
const config = require("../../utils/config");
|
|
Page({
|
|
data: {
|
|
brand: {},
|
|
trustContent: [],
|
|
offerings: [],
|
|
modules: [],
|
|
moduleVariants: {},
|
|
pageRenderer: "",
|
|
layout: [],
|
|
theme: {},
|
|
hero: { image: "", eyebrow: "", title: "", slogan: "", cta: "" },
|
|
loading: false,
|
|
loadedBrandSlug: "",
|
|
templateKey: "",
|
|
navigation: [],
|
|
},
|
|
onLoad() {
|
|
this.loadWorkspace();
|
|
},
|
|
onShow() {
|
|
if (this.data.loadedBrandSlug && this.data.loadedBrandSlug !== config.brandSlug) {
|
|
this.loadWorkspace();
|
|
}
|
|
},
|
|
loadWorkspace() {
|
|
this.setData({ loading: true });
|
|
loadWorkspaceWithFallback()
|
|
.then((workspace) => {
|
|
const activeBrand = workspace.brand || {};
|
|
const activeOfferings = workspace.offerings || [];
|
|
const layout = workspace.layout?.home || [
|
|
"founder-card",
|
|
"brand-hero",
|
|
"trust-proof",
|
|
"trust-manifesto",
|
|
"offering-list",
|
|
];
|
|
const firstOffering = activeOfferings[0] || {};
|
|
const configuredHero =
|
|
activeBrand.homeHero && typeof activeBrand.homeHero === "object"
|
|
? activeBrand.homeHero
|
|
: {};
|
|
this.setData({
|
|
brand: activeBrand,
|
|
trustContent: workspace.trustPresentation || {},
|
|
offerings: activeOfferings,
|
|
modules: workspace.modules || [],
|
|
moduleVariants: workspace.moduleVariants || {},
|
|
pageRenderer: workspace.pageRenderers?.home || "",
|
|
layout,
|
|
theme: workspace.theme || {},
|
|
hero: {
|
|
...this.data.hero,
|
|
image: activeBrand.heroImage || this.data.hero.image,
|
|
eyebrow: activeBrand.tagline || activeBrand.name,
|
|
title: firstOffering.name || activeBrand.name,
|
|
slogan: activeBrand.description || "",
|
|
...configuredHero,
|
|
},
|
|
loading: false,
|
|
loadedBrandSlug: config.brandSlug,
|
|
templateKey: workspace.visualTemplate?.key || "",
|
|
navigation: workspace.navigation || [],
|
|
});
|
|
wx.setNavigationBarTitle({ title: activeBrand.name || "个人品牌" });
|
|
})
|
|
.catch((error) => this.setData({ error: error.message, loading: false }));
|
|
},
|
|
showModule(e) {
|
|
return this.data.layout.includes(e);
|
|
},
|
|
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" });
|
|
},
|
|
goProfile() {
|
|
wx.navigateTo({ url: "/pages/bookings/index" });
|
|
},
|
|
});
|