diff --git a/apps/api/src/http.ts b/apps/api/src/http.ts
index 38de765..fa34741 100644
--- a/apps/api/src/http.ts
+++ b/apps/api/src/http.ts
@@ -23,6 +23,15 @@ export class RequestIdMiddleware {
}
}
+/** HttpException.getResponse() 可能是字符串,或 { message: string | string[] }(含 ValidationPipe 错误)。 */
+function readMessage(detail: unknown): string {
+ if (typeof detail === "string") return detail;
+ const message = (detail as { message?: unknown } | null)?.message;
+ if (typeof message === "string" && message) return message;
+ if (Array.isArray(message) && message.length) return message.map(String).join(";");
+ return "请求失败";
+}
+
@Catch()
export class ApiExceptionFilter implements ExceptionFilter {
catch(exception: unknown, host: ArgumentsHost): void {
@@ -41,7 +50,7 @@ export class ApiExceptionFilter implements ExceptionFilter {
data: null,
error: {
code: `HTTP_${status}`,
- message: typeof detail === "string" ? detail : "请求失败",
+ message: readMessage(detail),
},
requestId:
(request as FastifyRequest & { requestId?: string }).requestId ??
diff --git a/apps/api/test/http.integration.test.js b/apps/api/test/http.integration.test.js
index a90570c..4513c75 100644
--- a/apps/api/test/http.integration.test.js
+++ b/apps/api/test/http.integration.test.js
@@ -1062,6 +1062,16 @@ test("admin can create and version an inquiry form", async () => {
payload: { formId: id, values: {} },
});
assert.equal(missingRequired.statusCode, 400);
+ // 业务校验错误必须透传具体原因,不能被统一改写为"请求失败"。
+ assert.equal(JSON.parse(missingRequired.body).error.code, "HTTP_400");
+ assert.match(JSON.parse(missingRequired.body).error.message, /不能为空$/);
+ const invalidBody = await request("/customer/inquiry-submissions", {
+ method: "POST",
+ headers: { authorization: `Bearer ${customerToken}` },
+ payload: { formId: id },
+ });
+ assert.equal(invalidBody.statusCode, 400);
+ assert.notEqual(JSON.parse(invalidBody.body).error.message, "请求失败");
const capability = await prisma.capabilityInstallation.create({
data: {
brandId,
diff --git a/apps/miniapp/pages/inquiry-success/index.js b/apps/miniapp/pages/inquiry-success/index.js
index d055a3e..0fa62ff 100644
--- a/apps/miniapp/pages/inquiry-success/index.js
+++ b/apps/miniapp/pages/inquiry-success/index.js
@@ -1,5 +1,6 @@
const { customerRequest, customerTokenKey } = require("../../utils/request");
const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace");
+const { openPage } = require("../../utils/navigation");
Page({
data: { record: {}, presentation: {} },
@@ -28,9 +29,9 @@ Page({
}
},
viewRecords() {
- wx.redirectTo({ url: "/pages/records/index" });
+ openPage("/pages/records/index");
},
home() {
- wx.navigateTo({ url: "/pages/index/index" });
+ openPage("/pages/index/index");
},
});
diff --git a/apps/miniapp/pages/offering/detail.js b/apps/miniapp/pages/offering/detail.js
index 895fd57..c7e93cd 100644
--- a/apps/miniapp/pages/offering/detail.js
+++ b/apps/miniapp/pages/offering/detail.js
@@ -1,4 +1,5 @@
const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace");
+const { openPage } = require("../../utils/navigation");
Page({
data: { item: null, loading: true, error: "", presentation: {} },
onLoad(options) {
@@ -17,6 +18,6 @@ Page({
.catch((error) => this.setData({ loading: false, error: error.message }));
},
inquire() {
- wx.navigateTo({ url: "/pages/inquiry/index?offeringId=" + this.data.item.id });
+ openPage("/pages/inquiry/index?offeringId=" + this.data.item.id);
},
});
diff --git a/apps/miniapp/pages/records/index.js b/apps/miniapp/pages/records/index.js
index 240a1ac..6b3f978 100644
--- a/apps/miniapp/pages/records/index.js
+++ b/apps/miniapp/pages/records/index.js
@@ -1,5 +1,6 @@
const { customerRequest, customerTokenKey } = require("../../utils/request");
const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace");
+const { openPage } = require("../../utils/navigation");
const statusLabels = {
new: "待处理",
@@ -46,6 +47,6 @@ Page({
});
},
inquire() {
- wx.navigateTo({ url: "/pages/inquiry/index" });
+ openPage("/pages/inquiry/index");
},
});
diff --git a/apps/miniapp/runtime-config.js b/apps/miniapp/runtime-config.js
index 86e8d07..975a8f0 100644
--- a/apps/miniapp/runtime-config.js
+++ b/apps/miniapp/runtime-config.js
@@ -6,4 +6,5 @@ module.exports = {
templateKey: "",
templateVersion: "",
runtimeContract: "1.0",
+ tabPages: [],
};
diff --git a/apps/miniapp/utils/navigation.js b/apps/miniapp/utils/navigation.js
new file mode 100644
index 0000000..f187950
--- /dev/null
+++ b/apps/miniapp/utils/navigation.js
@@ -0,0 +1,39 @@
+const runtimeConfig = require("../runtime-config");
+
+// tabBar 页面由 template-compiler 按模板 navigation 写入 runtime-config.js。
+const tabPages = new Set(runtimeConfig.tabPages || []);
+
+function parseQuery(query) {
+ const result = {};
+ for (const pair of (query || "").split("&")) {
+ if (!pair) continue;
+ const [key, value = ""] = pair.split("=");
+ result[decodeURIComponent(key)] = decodeURIComponent(value);
+ }
+ return result;
+}
+
+/**
+ * 打开页面。目标是 tabBar 页时使用 switchTab(微信不允许 navigateTo 到 tabBar 页,
+ * 且 switchTab 不能带参数),参数暂存到 globalData,由目标页 takePageQuery 读取。
+ */
+function openPage(url) {
+ const [rawPath, query = ""] = String(url).replace(/^\//, "").split("?");
+ const fail = (error) => console.error("openPage failed", { url, error });
+ if (tabPages.has(rawPath)) {
+ getApp().globalData.pendingPageQuery = { path: rawPath, query: parseQuery(query) };
+ return wx.switchTab({ url: "/" + rawPath, fail });
+ }
+ return wx.navigateTo({ url: "/" + rawPath + (query ? "?" + query : ""), fail });
+}
+
+/** 读取并清除 openPage 为当前 tabBar 页暂存的参数;非 tabBar 页直接使用 onLoad 的 options。 */
+function takePageQuery(path) {
+ const app = getApp();
+ const pending = app.globalData.pendingPageQuery;
+ if (!pending || pending.path !== String(path).replace(/^\//, "")) return {};
+ app.globalData.pendingPageQuery = null;
+ return pending.query;
+}
+
+module.exports = { openPage, takePageQuery };
diff --git a/docs/adr/0015-template-build-time-composition.md b/docs/adr/0015-template-build-time-composition.md
index bcb6621..c97efd5 100644
--- a/docs/adr/0015-template-build-time-composition.md
+++ b/docs/adr/0015-template-build-time-composition.md
@@ -36,4 +36,4 @@
## 迁移计划
-阿成、林境两个模板和 `booking` capability 已迁移。`packages/template-compiler/test/fixtures/template-drill-consultant` 是第二行业演练模板,只用模板包自有页面和运行时通用组件,作为"新增行业不改 compiler/runtime"的回归门禁。每个新增模板必须通过 `pnpm template:check`(契约校验、compiler 产物校验、全部模板自动发现编译)后才能进入目录 registry。
+阿成、林境两个模板已迁移。`booking` 下单页曾作为第一个能力包迁入 `packages/capability-booking`,但小程序中没有入口、依赖已删除的 `/public/brand` 接口,且需求已由咨询表单覆盖,因此已移除;能力包层机制保留,后端 Booking 的去留另行决策。`packages/template-compiler/test/fixtures/template-drill-consultant` 是第二行业演练模板,只用模板包自有页面和运行时通用组件,作为"新增行业不改 compiler/runtime"的回归门禁。每个新增模板必须通过 `pnpm template:check`(契约校验、compiler 产物校验、全部模板自动发现编译)后才能进入目录 registry。
diff --git a/docs/template-runtime-progress.md b/docs/template-runtime-progress.md
index ef51812..5903b3a 100644
--- a/docs/template-runtime-progress.md
+++ b/docs/template-runtime-progress.md
@@ -10,7 +10,7 @@
- [x] Runtime、Capability、Template 三层编译结构已落地,详见 `docs/adr/0015-template-build-time-composition.md`。
- [x] 阿成、林境页面与 tab 资源已迁入独立模板包,Runtime 不再携带行业页面和模板组件。
-- [x] `booking` 下单页面已迁入 `packages/capability-booking`。
+- [x] `booking` 下单页面曾迁入 `packages/capability-booking`,因无入口且与咨询表单重复已移除;阿成统一走咨询。
- [x] 编译产物校验覆盖页面文件、组件引用、`require`、tab 图标、品牌参数和能力依赖错误。
- [x] 增加第二行业最小演练模板(`packages/template-compiler/test/fixtures/template-drill-consultant`),并由 `pnpm template:check` 门禁。
- [ ] 接入视觉截图回归。
diff --git a/packages/capability-booking/miniapp/pages/booking/index.js b/packages/capability-booking/miniapp/pages/booking/index.js
index 2f6192c..1bf4fab 100644
--- a/packages/capability-booking/miniapp/pages/booking/index.js
+++ b/packages/capability-booking/miniapp/pages/booking/index.js
@@ -1,5 +1,6 @@
const { request, customerRequest, customerTokenKey } = require("../../utils/request");
const { getTemplate } = require("../../utils/booking-templates");
+const { openPage } = require("../../utils/navigation");
Page({
data: {
service: {},
@@ -64,7 +65,7 @@ Page({
.then(() => {
this.setData({ submitting: false });
wx.showToast({ title: "预约已提交" });
- setTimeout(() => wx.navigateTo({ url: "/pages/bookings/index" }), 500);
+ setTimeout(() => openPage("/pages/bookings/index"), 500);
})
.catch((error) => {
this.setData({ submitting: false });
diff --git a/packages/config/src/generated-template-packages.js b/packages/config/src/generated-template-packages.js
index 84d56e6..d9d47dd 100644
--- a/packages/config/src/generated-template-packages.js
+++ b/packages/config/src/generated-template-packages.js
@@ -58,8 +58,7 @@ export const generatedTemplatePackageRegistry = [
],
"requiredCapabilities": [
"offerings",
- "inquiry",
- "booking"
+ "inquiry"
],
"dataSlots": [
{
@@ -319,6 +318,33 @@ export const generatedTemplatePackageRegistry = [
}
],
"fields": [
+ {
+ "key": "type",
+ "label": "咨询类型",
+ "type": "select",
+ "required": true,
+ "options": [
+ "日常留餐",
+ "宿舍开黑餐",
+ "社团 / 班级活动",
+ "生日聚会",
+ "考试周加餐",
+ "其他需求"
+ ]
+ },
+ {
+ "key": "people",
+ "label": "用餐人数",
+ "type": "select",
+ "required": true,
+ "options": [
+ "1 人(单点)",
+ "2-4 人(寝室小聚)",
+ "5-10 人(部门小聚)",
+ "10-30 人(社团活动)",
+ "30 人以上(大型活动)"
+ ]
+ },
{
"key": "date",
"label": "用餐日期",
@@ -326,14 +352,37 @@ export const generatedTemplatePackageRegistry = [
"required": true
},
{
- "key": "number",
- "label": "用餐人数",
- "type": "number",
- "required": true
+ "key": "budget",
+ "label": "人均预算",
+ "type": "select",
+ "required": false,
+ "options": [
+ "15 元左右 / 人(实惠)",
+ "18-22 元 / 人(荤素双拼)",
+ "25 元以上 / 人(高规格定制)"
+ ]
+ },
+ {
+ "key": "delivery",
+ "label": "取餐 / 配送方式",
+ "type": "select",
+ "required": false,
+ "options": [
+ "摊位自取(报手机尾号即拿)",
+ "送至宿舍楼下(满 3 份)",
+ "送至指定教室 / 场地"
+ ]
+ },
+ {
+ "key": "remark",
+ "label": "餐品 / 口味 / 忌口备注",
+ "type": "textarea",
+ "required": false,
+ "placeholder": "例:现炒牛肉饭 1 份,微辣多浇卤汁,不要香菜"
},
{
"key": "phone",
- "label": "联系方式",
+ "label": "联系手机",
"type": "phone",
"required": true
}
@@ -863,4 +912,4 @@ export const generatedTemplatePackageRegistry = [
}
];
export const generatedTemplatePackageRegistryHash =
- "254f31edcf4073091691fc5f88fced2b5857c60aec3d1175a5f1e44b9e45acd0";
+ "a2e3390bbd1557c4ae8836266c83cb13a265a693ac05927e3cacc3d73cdb1741";
diff --git a/packages/template-acheng-campus-food/miniapp/components/templates/acheng-home/acheng-home.js b/packages/template-acheng-campus-food/miniapp/components/templates/acheng-home/acheng-home.js
index 41ce8e5..93b1ac4 100644
--- a/packages/template-acheng-campus-food/miniapp/components/templates/acheng-home/acheng-home.js
+++ b/packages/template-acheng-campus-food/miniapp/components/templates/acheng-home/acheng-home.js
@@ -16,7 +16,7 @@ Component({
this.triggerEvent("offerings");
},
openService() {
- wx.navigateTo({ url: "/pages/stall-service/index" });
+ this.triggerEvent("service");
},
},
});
diff --git a/packages/template-acheng-campus-food/miniapp/components/templates/acheng-offerings/acheng-offerings.js b/packages/template-acheng-campus-food/miniapp/components/templates/acheng-offerings/acheng-offerings.js
index 32e9f64..d91ddee 100644
--- a/packages/template-acheng-campus-food/miniapp/components/templates/acheng-offerings/acheng-offerings.js
+++ b/packages/template-acheng-campus-food/miniapp/components/templates/acheng-offerings/acheng-offerings.js
@@ -3,6 +3,8 @@ Component({
brand: { type: Object, value: {} },
presentation: { type: Object, value: {} },
offerings: { type: Array, value: [] },
+ categories: { type: Array, value: [] },
+ category: { type: String, value: "all" },
},
data: { query: "", visibleOfferings: [] },
observers: {
@@ -26,6 +28,9 @@ Component({
search(e) {
this.setData({ query: e.detail.value });
},
+ chooseCategory(e) {
+ this.triggerEvent("category", { key: e.currentTarget.dataset.key });
+ },
open(e) {
this.triggerEvent("open", { id: e.currentTarget.dataset.id });
},
diff --git a/packages/template-acheng-campus-food/miniapp/components/templates/acheng-offerings/acheng-offerings.wxml b/packages/template-acheng-campus-food/miniapp/components/templates/acheng-offerings/acheng-offerings.wxml
index 24af042..09a52ba 100644
--- a/packages/template-acheng-campus-food/miniapp/components/templates/acheng-offerings/acheng-offerings.wxml
+++ b/packages/template-acheng-campus-food/miniapp/components/templates/acheng-offerings/acheng-offerings.wxml
@@ -1 +1 @@
-{{brand.name}}{{presentation.title || '今日菜单'}}{{presentation.subtitle || '现做现吃,支持提前预留和团体定制'}}全部餐品日常学生餐寝室 / 团体聚会定制⌕米饭免费续,支持微辣、免葱姜蒜,团体餐可提前预留。{{item.category || '现做餐品'}}{{item.name}}{{item.desc}}现做今日有售{{item.priceRange}}详情 / 预留 ›
+{{brand.name}}{{presentation.title || '今日菜单'}}{{presentation.subtitle || '现做现吃,支持提前预留和团体定制'}}{{item.label}}⌕米饭免费续,支持微辣、免葱姜蒜,团体餐可提前预留。{{item.category || '现做餐品'}}{{item.name}}{{item.desc}}现做今日有售{{item.priceRange}}详情 / 预留 ›
diff --git a/packages/template-acheng-campus-food/miniapp/pages/bookings/index.js b/packages/template-acheng-campus-food/miniapp/pages/bookings/index.js
index 0175d06..067f289 100644
--- a/packages/template-acheng-campus-food/miniapp/pages/bookings/index.js
+++ b/packages/template-acheng-campus-food/miniapp/pages/bookings/index.js
@@ -1,5 +1,6 @@
const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace");
const { customerRequest, customerTokenKey } = require("../../utils/request");
+const { openPage } = require("../../utils/navigation");
Page({
data: {
brand: {},
@@ -42,9 +43,9 @@ Page({
});
},
recordsPage() {
- wx.navigateTo({ url: "/pages/records/index" });
+ openPage("/pages/records/index");
},
inquire() {
- wx.navigateTo({ url: "/pages/inquiry/index" });
+ openPage("/pages/inquiry/index");
},
});
diff --git a/packages/template-acheng-campus-food/miniapp/pages/index/index.js b/packages/template-acheng-campus-food/miniapp/pages/index/index.js
index 8d2c13d..83003f7 100644
--- a/packages/template-acheng-campus-food/miniapp/pages/index/index.js
+++ b/packages/template-acheng-campus-food/miniapp/pages/index/index.js
@@ -1,4 +1,5 @@
const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace");
+const { openPage } = require("../../utils/navigation");
Page({
data: { brand: {}, presentation: {}, trustContent: [], offerings: [], error: "" },
@@ -15,12 +16,15 @@ Page({
.catch((error) => this.setData({ error: error.message }));
},
selectOffering(event) {
- wx.navigateTo({ url: "/pages/offering/detail?id=" + event.detail.id });
+ openPage("/pages/offering/detail?id=" + event.detail.id);
},
goWorks() {
- wx.navigateTo({ url: "/pages/services/index" });
+ openPage("/pages/services/index");
},
goInquiry() {
- wx.navigateTo({ url: "/pages/inquiry/index" });
+ openPage("/pages/inquiry/index");
+ },
+ goService() {
+ openPage("/pages/stall-service/index");
},
});
diff --git a/packages/template-acheng-campus-food/miniapp/pages/index/index.wxml b/packages/template-acheng-campus-food/miniapp/pages/index/index.wxml
index 759f3fc..88b3df9 100644
--- a/packages/template-acheng-campus-food/miniapp/pages/index/index.wxml
+++ b/packages/template-acheng-campus-food/miniapp/pages/index/index.wxml
@@ -1,4 +1,4 @@
{{error}}
-
+
diff --git a/packages/template-acheng-campus-food/miniapp/pages/inquiry-success/index.js b/packages/template-acheng-campus-food/miniapp/pages/inquiry-success/index.js
index d055a3e..0fa62ff 100644
--- a/packages/template-acheng-campus-food/miniapp/pages/inquiry-success/index.js
+++ b/packages/template-acheng-campus-food/miniapp/pages/inquiry-success/index.js
@@ -1,5 +1,6 @@
const { customerRequest, customerTokenKey } = require("../../utils/request");
const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace");
+const { openPage } = require("../../utils/navigation");
Page({
data: { record: {}, presentation: {} },
@@ -28,9 +29,9 @@ Page({
}
},
viewRecords() {
- wx.redirectTo({ url: "/pages/records/index" });
+ openPage("/pages/records/index");
},
home() {
- wx.navigateTo({ url: "/pages/index/index" });
+ openPage("/pages/index/index");
},
});
diff --git a/packages/template-acheng-campus-food/miniapp/pages/inquiry/index.js b/packages/template-acheng-campus-food/miniapp/pages/inquiry/index.js
index 6208c43..d6ae975 100644
--- a/packages/template-acheng-campus-food/miniapp/pages/inquiry/index.js
+++ b/packages/template-acheng-campus-food/miniapp/pages/inquiry/index.js
@@ -1,31 +1,7 @@
const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace");
const { request, customerRequest, customerTokenKey } = require("../../utils/request");
+const { takePageQuery } = require("../../utils/navigation");
-const typeOptions = [
- "日常留餐",
- "宿舍开黑餐",
- "社团 / 班级活动",
- "生日聚会",
- "考试周加餐",
- "其他需求",
-];
-const peopleOptions = [
- "1 人(单点)",
- "2-4 人(寝室小聚)",
- "5-10 人(部门小聚)",
- "10-30 人(社团活动)",
- "30 人以上(大型活动)",
-];
-const budgetOptions = [
- "15 元左右 / 人(实惠)",
- "18-22 元 / 人(荤素双拼)",
- "25 元以上 / 人(高规格定制)",
-];
-const deliveryOptions = [
- "摊位自取(报手机尾号即拿)",
- "送至宿舍楼下(满 3 份)",
- "送至指定教室 / 场地",
-];
const labels = {
new: "待处理",
reviewing: "沟通中",
@@ -35,50 +11,69 @@ const labels = {
closed: "已关闭",
};
+/** 按提交时的表单快照把记录还原成「标签:值」,后台以后改字段,历史记录仍然可读。 */
+function summarize(item) {
+ const fields = Array.isArray(item.fieldsSnapshot) ? item.fieldsSnapshot : [];
+ const values = item.values || {};
+ return fields
+ .filter((field) => values[field.key] !== undefined && values[field.key] !== "")
+ .map((field) => ({
+ key: field.key,
+ label: field.label || field.key,
+ value: values[field.key],
+ }));
+}
+
Page({
data: {
subView: "form",
records: [],
- typeOptions,
- peopleOptions,
- budgetOptions,
- deliveryOptions,
- peopleIndex: 1,
- budgetIndex: 1,
- deliveryIndex: 0,
- values: {
- type: "日常留餐",
- people: peopleOptions[1],
- budget: budgetOptions[1],
- delivery: deliveryOptions[0],
- },
+ // 字段全部来自后台已发布的咨询表单,模板只负责呈现。
+ fields: [],
+ values: {},
formId: "",
submitting: false,
formError: "",
},
onLoad(options) {
+ this.offeringId = options.offeringId || "";
loadWorkspaceWithFallback()
.then((workspace) => {
- const form =
- (workspace.inquiryForms || []).find((item) => item.targetId === options.offeringId) ||
- (workspace.inquiryForms || []).find((item) => item.target === "brand") ||
- workspace.inquiryForms?.[0];
- this.setData({ formId: form?.key || form?.id || "" });
+ this.forms = workspace.inquiryForms || [];
+ this.selectForm();
})
- .catch(() => {});
+ .catch((error) => this.setData({ formError: error.message }));
+ },
+ /** 按目标业务提供项选择表单;没有专属表单时回退到品牌表单。 */
+ selectForm() {
+ const forms = this.forms || [];
+ const form =
+ (this.offeringId && forms.find((item) => item.targetId === this.offeringId)) ||
+ forms.find((item) => item.target === "brand") ||
+ forms[0];
+ const formId = form?.key || form?.id || "";
+ if (formId !== this.data.formId)
+ this.setData({ formId, fields: form?.fields || [], values: {} });
},
onShow() {
+ // 本页是 tabBar 页,从详情页进入时参数经 openPage 暂存,而不是通过 onLoad 传入。
+ const query = takePageQuery("pages/inquiry/index");
+ if (query.offeringId) {
+ this.offeringId = query.offeringId;
+ this.setData({ subView: "form" });
+ if (this.forms) this.selectForm();
+ }
+ this.loadRecords();
+ },
+ loadRecords() {
if (!wx.getStorageSync(customerTokenKey())) return;
customerRequest("/customer/inquiry-submissions")
.then((items) =>
this.setData({
records: (items || []).map((item) => ({
...item,
- type: item.inquiryForm?.name || item.values?.type || "品牌咨询",
- people: item.values?.people || "",
- time: item.values?.date || "",
- delivery: item.values?.delivery || "",
- remark: item.values?.remark || "",
+ title: item.inquiryForm?.name || "品牌咨询",
+ summary: summarize(item),
status: labels[item.status] || item.status,
replyNote: item.replyNote,
createdAt: new Date(item.createdAt).toLocaleDateString("zh-CN"),
@@ -93,32 +88,20 @@ Page({
switchToForm() {
this.setData({ subView: "form" });
},
- chooseType(e) {
- this.setData({ "values.type": e.currentTarget.dataset.value });
- },
- choosePeople(e) {
- const index = Number(e.detail.value);
- this.setData({ peopleIndex: index, "values.people": peopleOptions[index] });
- },
- chooseBudget(e) {
- const index = Number(e.detail.value);
- this.setData({ budgetIndex: index, "values.budget": budgetOptions[index] });
- },
- chooseDelivery(e) {
- const index = Number(e.detail.value);
- this.setData({ deliveryIndex: index, "values.delivery": deliveryOptions[index] });
- },
- chooseDate(e) {
- this.setData({ "values.date": e.detail.value });
+ choose(e) {
+ const field = this.data.fields.find((item) => item.key === e.currentTarget.dataset.key);
+ const option = field?.options?.[Number(e.detail.value)];
+ if (option) this.setData({ ["values." + field.key]: option.value });
},
input(e) {
this.setData({ ["values." + e.currentTarget.dataset.key]: e.detail.value });
},
submit() {
- const { values, formId } = this.data;
- if (!values.phone)
- return this.setData({ formError: "请填写手机号或微信号,以便阿成加您发排菜菜单" });
- if (!values.date) return this.setData({ formError: "请选择期望用餐日期" });
+ const { values, formId, fields } = this.data;
+ const missing = fields.find(
+ (field) => field.required && (values[field.key] === undefined || values[field.key] === ""),
+ );
+ if (missing) return this.setData({ formError: "请填写" + missing.label });
if (!formId) return this.setData({ formError: "咨询表单暂不可用,请稍后重试" });
this.setData({ submitting: true, formError: "" });
const send = () =>
@@ -128,7 +111,7 @@ Page({
}).then((result) => {
wx.setStorageSync("latestInquirySubmission", result);
this.setData({ submitting: false, subView: "history" });
- this.onShow();
+ this.loadRecords();
wx.showToast({ title: "已提交,阿成会尽快联系你", icon: "none" });
});
const fail = (error) =>
diff --git a/packages/template-acheng-campus-food/miniapp/pages/inquiry/index.wxml b/packages/template-acheng-campus-food/miniapp/pages/inquiry/index.wxml
index 2e5e13c..beb6eba 100644
--- a/packages/template-acheng-campus-food/miniapp/pages/inquiry/index.wxml
+++ b/packages/template-acheng-campus-food/miniapp/pages/inquiry/index.wxml
@@ -1,5 +1,32 @@
▤ 新建咨询 / 预订▣ 我的咨询记录 ({{records.length}})
- 定制 / 预留需求登记告诉阿成时间与人数,阿成量身帮你们排菜(免收预约定金)1. 咨询类型 *{{item}}预计用餐人数 *{{values.people || '请选择人数'}}期望用餐时间 *{{values.date || '请选择日期'}}人均预算期望{{values.budget || '请选择预算'}}取餐 / 配送偏好{{values.delivery || '请选择方式'}}预留餐品 / 口味偏好 / 忌口备注联系手机或微信号 *! {{formError}}◷ 承诺:阿成将在 15~30 分钟内主动加微信沟通,未成单绝不骚扰。
- ▣暂无咨询记录快向阿成提交一份预订需求吧~单号 #{{item.id}}{{item.status}}{{item.type}}({{item.people}})◷ 时间:{{item.time || item.createdAt}}⌖ 配送 / 取餐:{{item.delivery || '待确认'}}备注:{{item.remark || item.flavor || '无'}}阿成微信留言:{{item.replyNote}}仅展示近 30 天内的微信预约咨询历史
+
+
+ 定制 / 预留需求登记
+ 告诉阿成时间与人数,阿成量身帮你们排菜(免收预约定金)
+
+ {{item.label}} *
+ {{values[item.key] || '请选择' + item.label}}
+ {{values[item.key] || '请选择日期'}}
+
+
+
+ ! {{formError}}
+ ◷ 承诺:阿成将在 15~30 分钟内主动加微信沟通,未成单绝不骚扰。
+
+
+
+
+ ▣暂无咨询记录快向阿成提交一份预订需求吧~
+
+
+ 单号 #{{item.id}}{{item.status}}
+ {{item.title}}
+ {{line.label}}:{{line.value}}
+ 阿成微信留言:{{item.replyNote}}
+
+
+ 仅展示近 30 天内的微信预约咨询历史
+
+
diff --git a/packages/template-acheng-campus-food/miniapp/pages/offering/detail.js b/packages/template-acheng-campus-food/miniapp/pages/offering/detail.js
index 895fd57..c7e93cd 100644
--- a/packages/template-acheng-campus-food/miniapp/pages/offering/detail.js
+++ b/packages/template-acheng-campus-food/miniapp/pages/offering/detail.js
@@ -1,4 +1,5 @@
const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace");
+const { openPage } = require("../../utils/navigation");
Page({
data: { item: null, loading: true, error: "", presentation: {} },
onLoad(options) {
@@ -17,6 +18,6 @@ Page({
.catch((error) => this.setData({ loading: false, error: error.message }));
},
inquire() {
- wx.navigateTo({ url: "/pages/inquiry/index?offeringId=" + this.data.item.id });
+ openPage("/pages/inquiry/index?offeringId=" + this.data.item.id);
},
});
diff --git a/packages/template-acheng-campus-food/miniapp/pages/records/index.js b/packages/template-acheng-campus-food/miniapp/pages/records/index.js
index 240a1ac..6b3f978 100644
--- a/packages/template-acheng-campus-food/miniapp/pages/records/index.js
+++ b/packages/template-acheng-campus-food/miniapp/pages/records/index.js
@@ -1,5 +1,6 @@
const { customerRequest, customerTokenKey } = require("../../utils/request");
const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace");
+const { openPage } = require("../../utils/navigation");
const statusLabels = {
new: "待处理",
@@ -46,6 +47,6 @@ Page({
});
},
inquire() {
- wx.navigateTo({ url: "/pages/inquiry/index" });
+ openPage("/pages/inquiry/index");
},
});
diff --git a/packages/template-acheng-campus-food/miniapp/pages/services/index.js b/packages/template-acheng-campus-food/miniapp/pages/services/index.js
index 71d946f..55c168d 100644
--- a/packages/template-acheng-campus-food/miniapp/pages/services/index.js
+++ b/packages/template-acheng-campus-food/miniapp/pages/services/index.js
@@ -1,17 +1,18 @@
const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace");
+const { openPage } = require("../../utils/navigation");
const config = require("../../utils/config");
+
Page({
data: {
- loading: false,
error: "",
offerings: [],
filtered: [],
brand: {},
presentation: {},
category: "all",
+ // 分类来自后台为业务提供项设置的分类,不在模板里写死。
categories: [],
loadedBrandSlug: "",
- navigation: [],
},
onLoad() {
this.loadWorkspace();
@@ -25,28 +26,24 @@ Page({
loadWorkspaceWithFallback()
.then((workspace) => {
const items = workspace.offerings || [];
+ const labels = Array.from(new Set(items.map((item) => item.category).filter(Boolean)));
this.setData({
offerings: items,
filtered: items,
+ category: "all",
categories: [
{ key: "all", label: "全部" },
- ...Array.from(new Set(items.map((item) => item.category).filter(Boolean))).map(
- (key) => ({
- key,
- label: key,
- }),
- ),
+ ...labels.map((label) => ({ key: label, label })),
],
brand: workspace.brand || {},
presentation: workspace.brand?.visualPresentation?.offerings || {},
- brand: workspace.brand || {},
loadedBrandSlug: config.brandSlug,
});
})
.catch((error) => this.setData({ error: error.message }));
},
switchCategory(e) {
- const category = e.currentTarget.dataset.category;
+ const category = e.detail.key;
const items = this.data.offerings || [];
this.setData({
category,
@@ -54,9 +51,9 @@ Page({
});
},
open(e) {
- wx.navigateTo({ url: "/pages/offering/detail?id=" + e.currentTarget.dataset.id });
+ openPage("/pages/offering/detail?id=" + e.detail.id);
},
inquire() {
- wx.navigateTo({ url: "/pages/inquiry/index" });
+ openPage("/pages/inquiry/index");
},
});
diff --git a/packages/template-acheng-campus-food/miniapp/pages/services/index.wxml b/packages/template-acheng-campus-food/miniapp/pages/services/index.wxml
index 8cfd78c..54636f8 100644
--- a/packages/template-acheng-campus-food/miniapp/pages/services/index.wxml
+++ b/packages/template-acheng-campus-food/miniapp/pages/services/index.wxml
@@ -1 +1 @@
-{{error}}
+{{error}}
diff --git a/packages/template-acheng-campus-food/miniapp/pages/stall-service/index.js b/packages/template-acheng-campus-food/miniapp/pages/stall-service/index.js
index 96b216f..351d7b7 100644
--- a/packages/template-acheng-campus-food/miniapp/pages/stall-service/index.js
+++ b/packages/template-acheng-campus-food/miniapp/pages/stall-service/index.js
@@ -1,4 +1,5 @@
const { loadWorkspaceWithFallback } = require("../../utils/runtime-workspace");
+const { openPage } = require("../../utils/navigation");
Page({
data: { brand: {}, presentation: {}, loading: true },
onLoad() {
@@ -13,6 +14,6 @@ Page({
.catch(() => this.setData({ loading: false }));
},
inquire() {
- wx.navigateTo({ url: "/pages/inquiry/index" });
+ openPage("/pages/inquiry/index");
},
});
diff --git a/packages/template-acheng-campus-food/template.json b/packages/template-acheng-campus-food/template.json
index f3f386e..0783b4c 100644
--- a/packages/template-acheng-campus-food/template.json
+++ b/packages/template-acheng-campus-food/template.json
@@ -52,7 +52,7 @@
"selectedIconPath": "assets/tab/booking-selected.png"
}
],
- "requiredCapabilities": ["offerings", "inquiry", "booking"],
+ "requiredCapabilities": ["offerings", "inquiry"],
"dataSlots": [
{
"key": "brand.identity",
@@ -303,9 +303,64 @@
{ "type": "process", "title": "从预订到取餐", "content": "示例内容,待品牌主理人完善。" }
],
"fields": [
+ {
+ "key": "type",
+ "label": "咨询类型",
+ "type": "select",
+ "required": true,
+ "options": [
+ "日常留餐",
+ "宿舍开黑餐",
+ "社团 / 班级活动",
+ "生日聚会",
+ "考试周加餐",
+ "其他需求"
+ ]
+ },
+ {
+ "key": "people",
+ "label": "用餐人数",
+ "type": "select",
+ "required": true,
+ "options": [
+ "1 人(单点)",
+ "2-4 人(寝室小聚)",
+ "5-10 人(部门小聚)",
+ "10-30 人(社团活动)",
+ "30 人以上(大型活动)"
+ ]
+ },
{ "key": "date", "label": "用餐日期", "type": "date", "required": true },
- { "key": "number", "label": "用餐人数", "type": "number", "required": true },
- { "key": "phone", "label": "联系方式", "type": "phone", "required": true }
+ {
+ "key": "budget",
+ "label": "人均预算",
+ "type": "select",
+ "required": false,
+ "options": [
+ "15 元左右 / 人(实惠)",
+ "18-22 元 / 人(荤素双拼)",
+ "25 元以上 / 人(高规格定制)"
+ ]
+ },
+ {
+ "key": "delivery",
+ "label": "取餐 / 配送方式",
+ "type": "select",
+ "required": false,
+ "options": [
+ "摊位自取(报手机尾号即拿)",
+ "送至宿舍楼下(满 3 份)",
+ "送至指定教室 / 场地"
+ ]
+ },
+ {
+ "key": "remark",
+ "label": "餐品 / 口味 / 忌口备注",
+ "type": "textarea",
+ "required": false,
+ "placeholder": "例:现炒牛肉饭 1 份,微辣多浇卤汁,不要香菜"
+ },
+ { "key": "phone", "label": "联系手机", "type": "phone", "required": true }
],
"capabilityKey": "booking"
}
diff --git a/packages/template-compiler/src/cli.mjs b/packages/template-compiler/src/cli.mjs
index f676d24..16e6b09 100644
--- a/packages/template-compiler/src/cli.mjs
+++ b/packages/template-compiler/src/cli.mjs
@@ -237,6 +237,7 @@ function writeGeneratedFiles(output, manifest, params, appJson, capabilities) {
templateKey: manifest.packageKey,
templateVersion: manifest.version,
runtimeContract: manifest.runtimeContract,
+ tabPages: appJson.tabBar.list.map((item) => item.pagePath),
};
fs.writeFileSync(
path.join(output, "runtime-config.js"),
@@ -314,6 +315,7 @@ function validateOutput(output, appJson, packageKey) {
}
}
const hasNpm = fs.existsSync(path.join(output, "miniprogram_npm"));
+ const tabPages = new Set(appJson.tabBar.list.map((item) => item.pagePath));
const forbiddenComponents = otherTemplateComponentNames(packageKey);
const sourceFiles = listFiles(output, new Set(["miniprogram_npm"])).filter((file) =>
/\.(js|json|wxml)$/.test(file),
@@ -337,6 +339,16 @@ function validateOutput(output, appJson, packageKey) {
if (!resolveRequire(output, file, match[1]))
errors.push(`${file}: require("${match[1]}") cannot be resolved`);
}
+ // 微信不允许 navigateTo/redirectTo 到 tabBar 页,switchTab 也不能带参数;失败时页面毫无反应。
+ for (const match of source.matchAll(
+ /wx\.(navigateTo|redirectTo|switchTab)\(\s*\{\s*url:\s*["'`]\/?([^"'`?]+)(\?)?/g,
+ )) {
+ const [, method, target, hasQuery] = match;
+ if (method !== "switchTab" && tabPages.has(target))
+ errors.push(`${file}: wx.${method} cannot open tabBar page ${target}; use openPage()`);
+ if (method === "switchTab" && hasQuery)
+ errors.push(`${file}: wx.switchTab cannot pass a query to ${target}; use openPage()`);
+ }
}
if (file.startsWith("pages/") || file.startsWith("components/")) {
for (const token of ["pageRenderer", "templateKey ==="]) {
diff --git a/packages/template-compiler/test/cli.test.mjs b/packages/template-compiler/test/cli.test.mjs
index 38c8784..ea466c2 100644
--- a/packages/template-compiler/test/cli.test.mjs
+++ b/packages/template-compiler/test/cli.test.mjs
@@ -43,7 +43,7 @@ test("compiler generates an isolated Acheng runtime manifest", () => {
true,
);
assert.equal(fs.existsSync(path.join(output, "pages/stall-service/index.wxml")), true);
- assert.equal(fs.existsSync(path.join(output, "pages/booking/index.wxml")), true);
+ assert.equal(fs.existsSync(path.join(output, "pages/booking")), false);
assert.equal(fs.existsSync(path.join(output, "assets/tab/booking.png")), true);
// 运行时的 npm 构建产物必须完整复制,不能被按名称排除的 src/test/dist 误伤。
const runtimeNpm = path.join(workspaceRoot, "apps/miniapp/miniprogram_npm");
@@ -190,6 +190,36 @@ test("compiler lets a template replace a runtime page declared in overrides", ()
);
});
+test("compiler rejects navigateTo calls that target tabBar pages", () => {
+ const templateDirectory = copyTemplate("linjing-editorial");
+ fs.appendFileSync(
+ path.join(templateDirectory, "miniapp/pages/index/index.js"),
+ '\nfunction broken() { wx.navigateTo({ url: "/pages/services/index" }); }\n',
+ );
+ const output = fs.mkdtempSync(path.join(os.tmpdir(), "personal-brand-template-"));
+ assert.throws(
+ () =>
+ execFileSync(
+ process.execPath,
+ [compiler, "--template-dir", templateDirectory, "--out", output],
+ { cwd: workspaceRoot, stdio: "pipe" },
+ ),
+ /wx\.navigateTo cannot open tabBar page pages\/services\/index/,
+ );
+});
+
+test("compiler writes tabBar pages into runtime-config for openPage", () => {
+ const output = fs.mkdtempSync(path.join(os.tmpdir(), "personal-brand-template-"));
+ execFileSync(process.execPath, [compiler, "--template", "acheng-campus-food", "--out", output], {
+ cwd: workspaceRoot,
+ stdio: "pipe",
+ });
+ const config = fs.readFileSync(path.join(output, "runtime-config.js"), "utf8");
+ assert.match(config, /"tabPages"/);
+ assert.match(config, /"pages\/inquiry\/index"/);
+ assert.equal(fs.existsSync(path.join(output, "utils/navigation.js")), true);
+});
+
test("compiler rejects unknown capabilities before copying layers", () => {
const templateDirectory = copyTemplate("linjing-editorial");
const manifestPath = path.join(templateDirectory, "template.json");
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 4c806db..ea14d42 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -134,6 +134,8 @@ importers:
specifier: workspace:*
version: link:../types
+ packages/capability-booking: {}
+
packages/config: {}
packages/template-acheng-campus-food: {}
@@ -146,6 +148,8 @@ importers:
packages/template-contract: {}
+ packages/template-linjing-editorial: {}
+
packages/types: {}
packages/validation: