diff --git a/apps/api/src/main.ts b/apps/api/src/main.ts index c92bb5a..bcbfabe 100644 --- a/apps/api/src/main.ts +++ b/apps/api/src/main.ts @@ -148,31 +148,43 @@ export class PublicWorkspaceController { @Get() async get(): Promise { const brandId = process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001"; - const [brand, modules, fields, offerings, inquiryForm, installation, capabilityInstallations] = - await Promise.all([ - this.prisma.brandProfile.findUnique({ where: { id: brandId } }), - this.prisma.brandModule.findMany({ - where: { brandId, isEnabled: true }, - orderBy: { sortOrder: "asc" }, - }), - this.prisma.brandFieldDefinition.findMany({ - where: { brandId, isVisible: true }, - orderBy: { sortOrder: "asc" }, - }), - this.prisma.offering.findMany({ - where: { brandId, isEnabled: true }, - orderBy: { sortOrder: "asc" }, - }), - this.prisma.inquiryForm.findFirst({ - where: { brandId, isEnabled: true }, - orderBy: { updatedAt: "desc" }, - }), - this.prisma.brandTemplateInstallation.findFirst({ - where: { brandId }, - orderBy: { updatedAt: "desc" }, - }), - this.prisma.capabilityInstallation.findMany({ where: { brandId } }), - ]); + const [ + brand, + modules, + fields, + offerings, + inquiryForm, + installation, + capabilityInstallations, + trustContents, + ] = await Promise.all([ + this.prisma.brandProfile.findUnique({ where: { id: brandId } }), + this.prisma.brandModule.findMany({ + where: { brandId, isEnabled: true }, + orderBy: { sortOrder: "asc" }, + }), + this.prisma.brandFieldDefinition.findMany({ + where: { brandId, isVisible: true }, + orderBy: { sortOrder: "asc" }, + }), + this.prisma.offering.findMany({ + where: { brandId, isEnabled: true }, + orderBy: { sortOrder: "asc" }, + }), + this.prisma.inquiryForm.findFirst({ + where: { brandId, isEnabled: true }, + orderBy: { updatedAt: "desc" }, + }), + this.prisma.brandTemplateInstallation.findFirst({ + where: { brandId }, + orderBy: { updatedAt: "desc" }, + }), + this.prisma.capabilityInstallation.findMany({ where: { brandId } }), + this.prisma.trustContent.findMany({ + where: { brandId, isPublished: true }, + orderBy: { sortOrder: "asc" }, + }), + ]); const templateKey = installation?.templateKey ?? brand?.templateKey ?? "personal"; const template = getBrandTemplate(templateKey); const runtimeCapabilities = capabilityInstallations.length @@ -314,6 +326,7 @@ export class PublicWorkspaceController { runtimeModules, fields, offerings, + trustContent: trustContents, inquiryForm, }; } diff --git a/apps/miniapp/pages/index/index.js b/apps/miniapp/pages/index/index.js index 0938208..602c3f9 100644 --- a/apps/miniapp/pages/index/index.js +++ b/apps/miniapp/pages/index/index.js @@ -1,11 +1,67 @@ -const { brand, trustContent, offerings } = require("../../utils/linjing-data"); const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace"); Page({ - 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) => { const activeBrand = workspace.brand || brand; const layout = workspace.layout?.home || ["founder-card", "brand-hero", "trust-proof", "trust-manifesto", "offering-list"]; const firstOffering = (workspace.offerings || offerings)[0] || {}; this.setData({ brand: activeBrand, trustContent: workspace.trustContent || trustContent, offerings: workspace.offerings || offerings, modules: workspace.modules || [], layout, theme: workspace.theme || {}, hero: { ...this.data.hero, eyebrow: activeBrand.tagline || activeBrand.name, title: firstOffering.name || activeBrand.name, slogan: activeBrand.description || "以专业经验建立长期信任", cta: "了解业务与服务 →" }, loading: false }); wx.setNavigationBarTitle({ title: activeBrand.name || brand.name }); }); }, - 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.switchTab({ url: "/pages/bookings/index" }); }, + 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: "", + cta: "了解业务与服务 →", + }, + loading: false, + }, + onLoad() { + 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] || {}; + this.setData({ + brand: activeBrand, + trustContent: workspace.trustContent || [], + offerings: activeOfferings, + modules: workspace.modules || [], + layout, + theme: workspace.theme || {}, + hero: { + ...this.data.hero, + eyebrow: activeBrand.tagline || activeBrand.name, + title: firstOffering.name || activeBrand.name, + slogan: activeBrand.description || "以专业经验建立长期信任", + }, + loading: false, + }); + wx.setNavigationBarTitle({ title: activeBrand.name || "个人品牌" }); + }); + }, + 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.switchTab({ url: "/pages/bookings/index" }); + }, }); diff --git a/apps/miniapp/pages/services/index.js b/apps/miniapp/pages/services/index.js index 5389f6b..50b4708 100644 --- a/apps/miniapp/pages/services/index.js +++ b/apps/miniapp/pages/services/index.js @@ -1,8 +1,34 @@ -const { offerings } = require("../../utils/linjing-data"); const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace"); Page({ - data: { loading: false, error: "", offerings, filtered: offerings, modules: [], theme: {}, category: "全部" }, - onLoad() { loadWorkspaceWithFallback().then((workspace) => { const items = workspace.offerings || offerings; this.setData({ offerings: items, filtered: items, modules: workspace.modules || [], theme: workspace.theme || {} }); }); }, - switchCategory(e) { const category = e.currentTarget.dataset.category; const items = this.data.offerings || offerings; this.setData({ category, filtered: category === "全部" ? items : items.filter((item) => item.category === category) }); }, - open(e) { wx.navigateTo({ url: "/pages/offering/detail?id=" + e.currentTarget.dataset.id }); }, + data: { + loading: false, + error: "", + offerings: [], + filtered: [], + modules: [], + theme: {}, + category: "全部", + }, + onLoad() { + loadWorkspaceWithFallback().then((workspace) => { + const items = workspace.offerings || []; + this.setData({ + offerings: items, + filtered: items, + modules: workspace.modules || [], + theme: workspace.theme || {}, + }); + }); + }, + switchCategory(e) { + const category = e.currentTarget.dataset.category; + const items = this.data.offerings || []; + this.setData({ + category, + filtered: category === "全部" ? items : items.filter((item) => item.category === category), + }); + }, + open(e) { + wx.navigateTo({ url: "/pages/offering/detail?id=" + e.currentTarget.dataset.id }); + }, }); diff --git a/apps/miniapp/utils/runtime-workspace.js b/apps/miniapp/utils/runtime-workspace.js index 5464ff6..3c200fe 100644 --- a/apps/miniapp/utils/runtime-workspace.js +++ b/apps/miniapp/utils/runtime-workspace.js @@ -22,7 +22,18 @@ function loadWorkspace() { const offerings = Array.isArray(workspace && workspace.offerings) ? workspace.offerings.map(toOffering) : fallback.offerings; - return { ...workspace, ...resolveRuntime(workspace), brand, offerings, trustContent: fallback.trustContent, plugins: Array.isArray(workspace.plugins) ? workspace.plugins : [] }; + const trustContent = + Array.isArray(workspace && workspace.trustContent) && workspace.trustContent.length + ? workspace.trustContent + : fallback.trustContent; + return { + ...workspace, + ...resolveRuntime(workspace), + brand, + offerings, + trustContent, + plugins: Array.isArray(workspace.plugins) ? workspace.plugins : [], + }; }); }