refactor: 清理小程序静态行业数据引用
This commit is contained in:
1 parent
947e6d1ac3
commit
bfa24d48d0
4 files changed
+122
-16
No files matched your search
+15
-2
@@ -148,8 +148,16 @@ export class PublicWorkspaceController {
|
|||||||
@Get()
|
@Get()
|
||||||
async get(): Promise<unknown> {
|
async get(): Promise<unknown> {
|
||||||
const brandId = process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001";
|
const brandId = process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001";
|
||||||
const [brand, modules, fields, offerings, inquiryForm, installation, capabilityInstallations] =
|
const [
|
||||||
await Promise.all([
|
brand,
|
||||||
|
modules,
|
||||||
|
fields,
|
||||||
|
offerings,
|
||||||
|
inquiryForm,
|
||||||
|
installation,
|
||||||
|
capabilityInstallations,
|
||||||
|
trustContents,
|
||||||
|
] = await Promise.all([
|
||||||
this.prisma.brandProfile.findUnique({ where: { id: brandId } }),
|
this.prisma.brandProfile.findUnique({ where: { id: brandId } }),
|
||||||
this.prisma.brandModule.findMany({
|
this.prisma.brandModule.findMany({
|
||||||
where: { brandId, isEnabled: true },
|
where: { brandId, isEnabled: true },
|
||||||
@@ -172,6 +180,10 @@ export class PublicWorkspaceController {
|
|||||||
orderBy: { updatedAt: "desc" },
|
orderBy: { updatedAt: "desc" },
|
||||||
}),
|
}),
|
||||||
this.prisma.capabilityInstallation.findMany({ where: { brandId } }),
|
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 templateKey = installation?.templateKey ?? brand?.templateKey ?? "personal";
|
||||||
const template = getBrandTemplate(templateKey);
|
const template = getBrandTemplate(templateKey);
|
||||||
@@ -314,6 +326,7 @@ export class PublicWorkspaceController {
|
|||||||
runtimeModules,
|
runtimeModules,
|
||||||
fields,
|
fields,
|
||||||
offerings,
|
offerings,
|
||||||
|
trustContent: trustContents,
|
||||||
inquiryForm,
|
inquiryForm,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,67 @@
|
|||||||
const { brand, trustContent, offerings } = require("../../utils/linjing-data");
|
|
||||||
const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace");
|
const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace");
|
||||||
Page({
|
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 },
|
data: {
|
||||||
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 }); }); },
|
brand: {},
|
||||||
showModule(e) { return this.data.layout.includes(e); },
|
trustContent: [],
|
||||||
selectOffering(e) { const id = e.detail ? e.detail.id : e.currentTarget.dataset.id; wx.navigateTo({ url: "/pages/offering/detail?id=" + id }); },
|
offerings: [],
|
||||||
goWorks() { wx.switchTab({ url: "/pages/services/index" }); },
|
modules: [],
|
||||||
goInquiry() { wx.navigateTo({ url: "/pages/inquiry/index" }); },
|
layout: [],
|
||||||
goProfile() { wx.switchTab({ url: "/pages/bookings/index" }); },
|
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");
|
const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace");
|
||||||
Page({
|
Page({
|
||||||
data: { loading: false, error: "", offerings, filtered: offerings, modules: [], theme: {}, category: "全部" },
|
data: {
|
||||||
onLoad() { loadWorkspaceWithFallback().then((workspace) => { const items = workspace.offerings || offerings; this.setData({ offerings: items, filtered: items, modules: workspace.modules || [], theme: workspace.theme || {} }); }); },
|
loading: false,
|
||||||
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) }); },
|
error: "",
|
||||||
open(e) { wx.navigateTo({ url: "/pages/offering/detail?id=" + e.currentTarget.dataset.id }); },
|
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)
|
const offerings = Array.isArray(workspace && workspace.offerings)
|
||||||
? workspace.offerings.map(toOffering)
|
? workspace.offerings.map(toOffering)
|
||||||
: fallback.offerings;
|
: 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