From 947e6d1ac3a60512f78a4a203d174c509b69bac3 Mon Sep 17 00:00:00 2001 From: que01 Date: Wed, 23 Sep 2026 01:54:06 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=BB=9F=E4=B8=80=E5=B0=8F?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=93=81=E7=89=8C=E8=BF=90=E8=A1=8C=E6=97=B6?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=85=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/miniapp/pages/bookings/index.js | 10 ++--- apps/miniapp/pages/inquiry/index.js | 4 +- apps/miniapp/pages/offering/detail.js | 4 +- docs/brand-runtime-multitenancy-plan.md | 49 +++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 docs/brand-runtime-multitenancy-plan.md diff --git a/apps/miniapp/pages/bookings/index.js b/apps/miniapp/pages/bookings/index.js index f0c6bb1..133e19f 100644 --- a/apps/miniapp/pages/bookings/index.js +++ b/apps/miniapp/pages/bookings/index.js @@ -1,18 +1,18 @@ -const { brand, trustContent } = require("../../utils/linjing-data"); +const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace"); Page({ data: { - brand, trustContent, records: [], + brand: {}, trustContent: [], records: [], }, onLoad() { - this.setData({ records: wx.getStorageSync("linjingInquiryRecords") || [] }); + loadWorkspaceWithFallback().then((workspace) => this.setData({ brand: workspace.brand || {}, trustContent: workspace.trustContent || [], records: wx.getStorageSync("linjingInquiryRecords") || [] })); }, onShow() { this.setData({ records: wx.getStorageSync("linjingInquiryRecords") || [] }); }, call() { - wx.makePhoneCall({ phoneNumber: brand.phone.replace(/[^0-9-]/g, "") }); + wx.makePhoneCall({ phoneNumber: (this.data.brand.contactPhone || "").replace(/[^0-9-]/g, "") }); }, - copyWechat() { wx.setClipboardData({ data: brand.wechat, success: () => wx.showToast({ title: "微信号已复制", icon: "none" }) }); }, + copyWechat() { wx.setClipboardData({ data: this.data.brand.contactWechat || "", success: () => wx.showToast({ title: "微信号已复制", icon: "none" }) }); }, recordsPage() { wx.navigateTo({ url: "/pages/records/index" }); }, inquire() { wx.navigateTo({ url: "/pages/inquiry/index" }); diff --git a/apps/miniapp/pages/inquiry/index.js b/apps/miniapp/pages/inquiry/index.js index 3e6889e..ebf9061 100644 --- a/apps/miniapp/pages/inquiry/index.js +++ b/apps/miniapp/pages/inquiry/index.js @@ -1,7 +1,7 @@ -const { offerings } = require("../../utils/linjing-data"); +const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace"); Page({ data: { offering: null, submitting: false, values: { name: "", phone: "", city: "", doorType: "", note: "" }, fields: [{ key: "name", label: "联系人", placeholder: "请输入称呼" }, { key: "phone", label: "手机号码", placeholder: "请输入手机号" }, { key: "city", label: "项目所在城市", placeholder: "例如:上海 · 佘山" }, { key: "doorType", label: "希望定制的门类型", placeholder: "入户门 / 庭院门 / 室内门" }, { key: "note", label: "补充说明", placeholder: "告诉我们你的空间和需求" }] }, - onLoad(options) { this.setData({ offering: offerings.find((item) => item.id === options.offeringId) || null }); }, + onLoad(options) { loadWorkspaceWithFallback().then((workspace) => { const offering = (workspace.offerings || []).find((item) => item.id === options.offeringId) || null; this.setData({ offering, fields: workspace.fields?.length ? workspace.fields : this.data.fields }); }); }, onInput(e) { this.setData({ ["values." + e.currentTarget.dataset.key]: e.detail.value }); }, onComponentInput(e) { this.setData({ ["values." + e.detail.key]: e.detail.value }); }, submit() { const values = this.data.values; if (!values.name || !values.phone) return wx.showToast({ title: "请填写联系人和手机号", icon: "none" }); this.setData({ submitting: true }); setTimeout(() => { const id = "LJ" + Date.now().toString().slice(-8); const record = { id, offeringName: this.data.offering ? this.data.offering.name : "门系统定制咨询", type: values.doorType || "门系统定制", project: values.city || "待确认项目", status: "待主理人复核图纸", createdAt: new Date().toLocaleDateString("zh-CN"), values }; const records = wx.getStorageSync("linjingInquiryRecords") || []; wx.setStorageSync("linjingInquiryRecords", [record].concat(records)); this.setData({ submitting: false }); wx.redirectTo({ url: "/pages/inquiry-success/index?id=" + id }); }, 500); }, diff --git a/apps/miniapp/pages/offering/detail.js b/apps/miniapp/pages/offering/detail.js index 56d2af6..794b9b6 100644 --- a/apps/miniapp/pages/offering/detail.js +++ b/apps/miniapp/pages/offering/detail.js @@ -1,6 +1,6 @@ -const { offerings } = require("../../utils/linjing-data"); +const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace"); Page({ data: { item: null, loading: true }, - onLoad(options) { const item = offerings.find((entry) => entry.id === options.id) || offerings[0]; this.setData({ item, loading: false }); wx.setNavigationBarTitle({ title: item.category }); }, + onLoad(options) { loadWorkspaceWithFallback().then((workspace) => { const offerings = workspace.offerings || []; const item = offerings.find((entry) => entry.id === options.id) || offerings[0]; if (!item) return this.setData({ loading: false }); this.setData({ item, loading: false }); wx.setNavigationBarTitle({ title: item.category || item.name }); }); }, inquire() { wx.navigateTo({ url: "/pages/inquiry/index?offeringId=" + this.data.item.id }); }, }); diff --git a/docs/brand-runtime-multitenancy-plan.md b/docs/brand-runtime-multitenancy-plan.md new file mode 100644 index 0000000..f70dfa5 --- /dev/null +++ b/docs/brand-runtime-multitenancy-plan.md @@ -0,0 +1,49 @@ +# 品牌运行时与多品牌隔离推进计划 + +## 目标 + +个人品牌是产品主线,行业模板、视觉模板和能力插件都必须在品牌隔离的运行时上下文中工作。Admin 与小程序不得维护第二套实时品牌数据。 + +## 当前结论 + +- 数据模型已经普遍包含 `brandId`,但 Admin 运行时仍依赖 `DEFAULT_BRAND_ID`,当前属于单品牌运行模式。 +- `BrandProfile` 及其品牌业务表应是实时品牌内容的唯一来源。 +- `BrandTemplateInstallation.configSnapshot` 仅用于模板版本、升级和回滚,不得覆盖实时品牌内容。 +- `RuntimeWorkspace` 是 Admin 和小程序统一消费的读取契约。 +- 小程序静态数据只能作为按模板选择的离线 fallback,不能覆盖成功的 API 返回。 + +## 阶段 + +### Phase 1:统一品牌运行时数据 + +- Admin 页面统一通过 `/admin/workspace` 获取运行时数据。 +- 小程序页面移除直接读取行业静态数据的路径。 +- fallback 按 `personal`、`food`、`doors` 模板拆分。 +- API 成功时不允许 fallback 覆盖 API 数据。 +- 增加三模板数据一致性和 API 失败 fallback 测试。 + +### Phase 2:品牌上下文与权限隔离 + +- 增加 `AdminUser`、`BrandMembership` 和角色模型。 +- 从 token 与 membership 解析可信当前品牌,不再依赖 `DEFAULT_BRAND_ID`。 +- 所有 Admin 查询、写入、删除强制使用服务端品牌上下文。 +- 增加跨品牌越权集成测试。 + +### Phase 3:公开品牌解析与缓存隔离 + +- 生产环境支持 `brandSlug` 或 `appId -> brandId` 解析。 +- Runtime Workspace 缓存按品牌和版本隔离。 +- 公开接口只返回当前品牌已发布内容。 + +### Phase 4:行业能力扩展 + +- 在前 3 个阶段通过验收前,不新增行业专属页面。 +- 后续行业差异继续通过模板、模块、能力插件和声明式字段表达。 + +## 交付门槛 + +- API integration tests 通过。 +- Admin production build 通过。 +- 小程序结构和视觉 fixture 通过。 +- personal、food、doors 不得出现跨行业文案、字段或业务数据污染。 +- 每个完成阶段使用一个完整、可审查的提交收口。