refactor: 清理小程序静态行业数据引用
This commit is contained in:
1 parent
947e6d1ac3
commit
bfa24d48d0
4 files changed
+145
-39
No files matched your search
+38
-25
@@ -148,31 +148,43 @@ export class PublicWorkspaceController {
|
||||
@Get()
|
||||
async get(): Promise<unknown> {
|
||||
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,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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" });
|
||||
},
|
||||
});
|
||||
@@ -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 });
|
||||
},
|
||||
});
|
||||
@@ -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 : [],
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user