feat: 让小程序消费运行时工作空间

This commit is contained in:
que01 committed 2026-09-22 17:32:59 +08:00
1 parent 53ee034db8
commit c3df77e227
4 files changed
+45 -2

No files matched your search

+2 -1
View File
@@ -1,7 +1,8 @@
const { brand, trustContent, offerings } = require("../../utils/linjing-data");
const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace");
Page({
data: { brand, trustContent, offerings, loading: false },
onLoad() { wx.setNavigationBarTitle({ title: brand.name }); },
onLoad() { this.setData({ loading: true }); loadWorkspaceWithFallback().then((workspace) => { this.setData({ brand: workspace.brand, trustContent: workspace.trustContent || trustContent, offerings: workspace.offerings || offerings, loading: false }); wx.setNavigationBarTitle({ title: workspace.brand.name || brand.name }); }); },
selectOffering(e) { wx.navigateTo({ url: "/pages/offering/detail?id=" + e.currentTarget.dataset.id }); },
goWorks() { wx.switchTab({ url: "/pages/services/index" }); },
goInquiry() { wx.navigateTo({ url: "/pages/inquiry/index" }); },
+3 -1
View File
@@ -1,6 +1,8 @@
const { offerings } = require("../../utils/linjing-data");
const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace");
Page({
data: { loading: false, error: "", offerings, filtered: offerings, category: "全部" },
switchCategory(e) { const category = e.currentTarget.dataset.category; this.setData({ category, filtered: category === "全部" ? offerings : offerings.filter((item) => item.category === category) }); },
onLoad() { loadWorkspaceWithFallback().then((workspace) => { const items = workspace.offerings || offerings; this.setData({ offerings: items, filtered: items }); }); },
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 }); },
});
+39
View File
@@ -0,0 +1,39 @@
const { request } = require("./request");
const fallback = require("./linjing-data");
function toOffering(item) {
const config = item && item.config && typeof item.config === "object" ? item.config : {};
return {
...item,
id: item.id,
category: item.category || item.kind || "业务提供项",
name: item.name,
desc: item.summary || item.description || "",
image: item.coverUrl || item.image || "",
priceRange: item.priceText || "沟通报价",
keywords: Array.isArray(config.keywords) ? config.keywords : [],
};
}
function loadWorkspace() {
return request("/public/workspace").then((workspace) => {
const brand = workspace && workspace.brand ? workspace.brand : fallback.brand;
const offerings = Array.isArray(workspace && workspace.offerings)
? workspace.offerings.map(toOffering)
: fallback.offerings;
return { ...workspace, brand, offerings, trustContent: fallback.trustContent };
});
}
function loadWorkspaceWithFallback() {
return loadWorkspace().catch(() => ({
schemaVersion: "static-fallback",
brand: fallback.brand,
offerings: fallback.offerings,
trustContent: fallback.trustContent,
modules: [],
capabilities: [],
}));
}
module.exports = { loadWorkspaceWithFallback };
+1
View File
@@ -25,6 +25,7 @@
- [x] 集成测试覆盖运行时 schemaVersion、导航、模块、Offering、表单、能力和主题。
- [ ] 增加 API 授权、品牌隔离和 schema 版本测试。
- [ ] 让 Admin 与小程序读取同一运行时契约。
- [x] 小程序首页和案例列表优先消费 `/public/workspace`,保留静态降级基线。
### 后续阶段