fix: 修复模板页面跳转并移除无入口的下单页
新增运行时 openPage/takePageQuery,tabBar 页自动使用 switchTab 并传递参数 - 编译器写入 tabPages,并拒绝 navigateTo/redirectTo 到 tabBar 页或 switchTab 带参数 - 阿成首页、套餐、出摊、主理人、详情、记录、成功页跳转统一改用 openPage - 套餐筛选改用后台业务提供项分类;详情跳咨询时携带业务提供项 - 移除 capability-booking:小程序无入口且依赖已删除的 /public/brand,需求由咨询表单覆盖"
This commit is contained in:
1 parent
a97cc860cf
commit
55989a5dfe
29 files changed
+353
-119
No files matched your search
@@ -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 });
|
||||
|
||||
@@ -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";
|
||||
+1
-1
@@ -16,7 +16,7 @@ Component({
|
||||
this.triggerEvent("offerings");
|
||||
},
|
||||
openService() {
|
||||
wx.navigateTo({ url: "/pages/stall-service/index" });
|
||||
this.triggerEvent("service");
|
||||
},
|
||||
},
|
||||
});
|
||||
+5
@@ -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 });
|
||||
},
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
<view class="page"><view class="head"><text class="eyebrow">{{brand.name}}</text><text class="title">{{presentation.title || '今日菜单'}}</text><text class="subtitle">{{presentation.subtitle || '现做现吃,支持提前预留和团体定制'}}</text></view><view class="filters"><view class="filter active">全部餐品</view><view class="filter">日常学生餐</view><view class="filter">寝室 / 团体</view><view class="filter">聚会定制</view></view><view class="search"><text class="search-icon">⌕</text><input value="{{query}}" placeholder="搜索餐品、牛肉、卤肉、鸡腿" bindinput="search" /></view><view class="tip">米饭免费续,支持微辣、免葱姜蒜,团体餐可提前预留。</view><view class="list"><view wx:for="{{visibleOfferings}}" wx:key="id" class="dish" data-id="{{item.id}}" bindtap="open"><view class="dish-media"><image src="{{item.image}}" mode="aspectFill"/><text class="tag">{{item.category || '现做餐品'}}</text></view><view class="copy"><text class="name">{{item.name}}</text><text class="desc">{{item.desc}}</text><view class="chips"><text>现做</text><text>今日有售</text></view><view class="bottom"><text class="price">{{item.priceRange}}</text><text class="action">详情 / 预留 ›</text></view></view></view></view><button class="cta" bindtap="inquire">团体活动 / 定制餐咨询</button></view>
|
||||
<view class="page"><view class="head"><text class="eyebrow">{{brand.name}}</text><text class="title">{{presentation.title || '今日菜单'}}</text><text class="subtitle">{{presentation.subtitle || '现做现吃,支持提前预留和团体定制'}}</text></view><view wx:if="{{categories.length > 1}}" class="filters"><view wx:for="{{categories}}" wx:key="key" class="filter {{item.key === category ? 'active' : ''}}" data-key="{{item.key}}" bindtap="chooseCategory">{{item.label}}</view></view><view class="search"><text class="search-icon">⌕</text><input value="{{query}}" placeholder="搜索餐品、牛肉、卤肉、鸡腿" bindinput="search" /></view><view class="tip">米饭免费续,支持微辣、免葱姜蒜,团体餐可提前预留。</view><view class="list"><view wx:for="{{visibleOfferings}}" wx:key="id" class="dish" data-id="{{item.id}}" bindtap="open"><view class="dish-media"><image src="{{item.image}}" mode="aspectFill"/><text class="tag">{{item.category || '现做餐品'}}</text></view><view class="copy"><text class="name">{{item.name}}</text><text class="desc">{{item.desc}}</text><view class="chips"><text>现做</text><text>今日有售</text></view><view class="bottom"><text class="price">{{item.priceRange}}</text><text class="action">详情 / 预留 ›</text></view></view></view></view><button class="cta" bindtap="inquire">团体活动 / 定制餐咨询</button></view>
|
||||
@@ -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");
|
||||
},
|
||||
});
|
||||
@@ -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");
|
||||
},
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
<view class="page">
|
||||
<view wx:if="{{error}}" class="runtime-error">{{error}}</view>
|
||||
<acheng-home wx:else brand="{{brand}}" presentation="{{presentation}}" trust-content="{{trustContent}}" offerings="{{offerings}}" bind:select="selectOffering" bind:inquiry="goInquiry" bind:offerings="goWorks" />
|
||||
<acheng-home wx:else brand="{{brand}}" presentation="{{presentation}}" trust-content="{{trustContent}}" offerings="{{offerings}}" bind:select="selectOffering" bind:inquiry="goInquiry" bind:offerings="goWorks" bind:service="goService" />
|
||||
</view>
|
||||
@@ -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");
|
||||
},
|
||||
});
|
||||
@@ -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) =>
|
||||
|
||||
@@ -1,5 +1,32 @@
|
||||
<view class="page booking-page">
|
||||
<view class="sub-tabs"><view class="sub-tab {{subView === 'form' ? 'active' : ''}}" data-view="form" bindtap="switchView">▤ 新建咨询 / 预订</view><view class="sub-tab {{subView === 'history' ? 'active' : ''}}" data-view="history" bindtap="switchView">▣ 我的咨询记录 ({{records.length}})</view></view>
|
||||
<block wx:if="{{subView === 'form'}}"><view class="form-card"><text class="form-title">定制 / 预留需求登记</text><text class="form-desc">告诉阿成时间与人数,阿成量身帮你们排菜(免收预约定金)</text><view class="field"><text class="label">1. 咨询类型 <b>*</b></text><view class="type-grid"><view wx:for="{{typeOptions}}" wx:key="*this" class="type-option {{values.type === item ? 'selected' : ''}}" data-value="{{item}}" bindtap="chooseType">{{item}}</view></view></view><view class="two-col"><view class="field"><text class="label">预计用餐人数 <b>*</b></text><picker range="{{peopleOptions}}" value="{{peopleIndex}}" bindchange="choosePeople"><view class="picker">{{values.people || '请选择人数'}}</view></picker></view><view class="field"><text class="label">期望用餐时间 <b>*</b></text><picker mode="date" value="{{values.date}}" bindchange="chooseDate"><view class="picker">{{values.date || '请选择日期'}}</view></picker></view></view><view class="two-col"><view class="field"><text class="label">人均预算期望</text><picker range="{{budgetOptions}}" value="{{budgetIndex}}" bindchange="chooseBudget"><view class="picker">{{values.budget || '请选择预算'}}</view></picker></view><view class="field"><text class="label">取餐 / 配送偏好</text><picker range="{{deliveryOptions}}" value="{{deliveryIndex}}" bindchange="chooseDelivery"><view class="picker">{{values.delivery || '请选择方式'}}</view></picker></view></view><view class="field"><text class="label">预留餐品 / 口味偏好 / 忌口备注</text><textarea value="{{values.remark}}" data-key="remark" bindinput="input" placeholder="例:现炒牛肉饭 1 份,微辣多浇卤汁,不要香菜;或活动特殊要求" /></view><view class="field"><text class="label">联系手机或微信号 <b>*</b></text><input value="{{values.phone}}" data-key="phone" bindinput="input" placeholder="阿成将第一时间加微信发排菜明细与确认" /></view><view wx:if="{{formError}}" class="error">! {{formError}}</view><view class="promise">◷ <text>承诺:阿成将在 15~30 分钟内主动加微信沟通,未成单绝不骚扰。</text></view><button class="submit" loading="{{submitting}}" bindtap="submit">➤ 立即提交咨询(免收定金)</button></view></block>
|
||||
<block wx:else><view wx:if="{{!records.length}}" class="empty"><text class="empty-icon">▣</text><text class="empty-title">暂无咨询记录</text><text>快向阿成提交一份预订需求吧~</text><button bindtap="switchToForm">新建咨询</button></view><view wx:else class="history-list"><view wx:for="{{records}}" wx:key="id" class="history-card"><view class="history-head"><text class="record-id">单号 #{{item.id}}</text><text class="record-status">{{item.status}}</text></view><text class="history-title">{{item.type}}({{item.people}})</text><text>◷ 时间:{{item.time || item.createdAt}}</text><text>⌖ 配送 / 取餐:{{item.delivery || '待确认'}}</text><text>备注:{{item.remark || item.flavor || '无'}}</text><view wx:if="{{item.replyNote}}" class="reply"><b>阿成微信留言:</b>{{item.replyNote}}</view><view class="history-foot">提交时间:{{item.createdAt}}<text>如有修改可随时微信留言</text></view></view><text class="history-note">仅展示近 30 天内的微信预约咨询历史</text></view></block>
|
||||
<block wx:if="{{subView === 'form'}}">
|
||||
<view class="form-card">
|
||||
<text class="form-title">定制 / 预留需求登记</text>
|
||||
<text class="form-desc">告诉阿成时间与人数,阿成量身帮你们排菜(免收预约定金)</text>
|
||||
<view wx:for="{{fields}}" wx:key="key" class="field">
|
||||
<text class="label">{{item.label}} <b wx:if="{{item.required}}">*</b></text>
|
||||
<picker wx:if="{{item.type === 'select' || item.type === 'radio'}}" range="{{item.options}}" range-key="label" data-key="{{item.key}}" bindchange="choose"><view class="picker">{{values[item.key] || '请选择' + item.label}}</view></picker>
|
||||
<picker wx:elif="{{item.type === 'date'}}" mode="date" value="{{values[item.key]}}" data-key="{{item.key}}" bindchange="input"><view class="picker">{{values[item.key] || '请选择日期'}}</view></picker>
|
||||
<textarea wx:elif="{{item.type === 'textarea'}}" value="{{values[item.key]}}" data-key="{{item.key}}" bindinput="input" placeholder="{{item.placeholder || '请填写' + item.label}}" />
|
||||
<input wx:else type="{{item.type === 'number' ? 'number' : 'text'}}" value="{{values[item.key]}}" data-key="{{item.key}}" bindinput="input" placeholder="{{item.placeholder || '请填写' + item.label}}" />
|
||||
</view>
|
||||
<view wx:if="{{formError}}" class="error">! {{formError}}</view>
|
||||
<view class="promise">◷ <text>承诺:阿成将在 15~30 分钟内主动加微信沟通,未成单绝不骚扰。</text></view>
|
||||
<button class="submit" loading="{{submitting}}" bindtap="submit">➤ 立即提交咨询(免收定金)</button>
|
||||
</view>
|
||||
</block>
|
||||
<block wx:else>
|
||||
<view wx:if="{{!records.length}}" class="empty"><text class="empty-icon">▣</text><text class="empty-title">暂无咨询记录</text><text>快向阿成提交一份预订需求吧~</text><button bindtap="switchToForm">新建咨询</button></view>
|
||||
<view wx:else class="history-list">
|
||||
<view wx:for="{{records}}" wx:key="id" class="history-card">
|
||||
<view class="history-head"><text class="record-id">单号 #{{item.id}}</text><text class="record-status">{{item.status}}</text></view>
|
||||
<text class="history-title">{{item.title}}</text>
|
||||
<text wx:for="{{item.summary}}" wx:for-item="line" wx:key="key">{{line.label}}:{{line.value}}</text>
|
||||
<view wx:if="{{item.replyNote}}" class="reply"><b>阿成微信留言:</b>{{item.replyNote}}</view>
|
||||
<view class="history-foot">提交时间:{{item.createdAt}}<text>如有修改可随时微信留言</text></view>
|
||||
</view>
|
||||
<text class="history-note">仅展示近 30 天内的微信预约咨询历史</text>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
@@ -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);
|
||||
},
|
||||
});
|
||||
@@ -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");
|
||||
},
|
||||
});
|
||||
@@ -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");
|
||||
},
|
||||
});
|
||||
@@ -1 +1 @@
|
||||
<view class="page"><view wx:if="{{error}}" class="runtime-error">{{error}}</view><block wx:else><acheng-offerings brand="{{brand}}" presentation="{{presentation}}" offerings="{{filtered}}" bind:open="open" bind:inquire="inquire" /></block></view>
|
||||
<view class="page"><view wx:if="{{error}}" class="runtime-error">{{error}}</view><block wx:else><acheng-offerings brand="{{brand}}" presentation="{{presentation}}" offerings="{{filtered}}" categories="{{categories}}" category="{{category}}" bind:category="switchCategory" bind:open="open" bind:inquire="inquire" /></block></view>
|
||||
@@ -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");
|
||||
},
|
||||
});
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
@@ -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 ==="]) {
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in new issue
Block a user