fix: 收敛模板编辑发布契约并还原餐饮页面视觉

This commit is contained in:
que01 committed 2026-10-08 13:36:59 +08:00
1 parent 20bcb43534
commit f4061a24bd
102 files changed
+4510 -870

No files matched your search

@@ -5,6 +5,22 @@ Component({
submitting: { type: Boolean, value: false },
submitLabel: { type: String, value: "提交需求" },
},
observers: {
"fields, values": function (fields, values) {
const selectedValues = values || {};
this.setData({
renderFields: (fields || []).map((field) => ({
...field,
options: (field.options || []).map((option) => ({
...option,
checked:
Array.isArray(selectedValues[field.key]) &&
selectedValues[field.key].includes(option.value),
})),
})),
});
},
},
methods: {
input(e) {
this.triggerEvent("input", { key: e.currentTarget.dataset.key, value: e.detail.value });
@@ -14,6 +30,12 @@ Component({
const option = field?.options?.[e.detail.value];
if (option) this.triggerEvent("input", { key: field.key, value: option.value ?? option });
},
checkboxChange(e) {
this.triggerEvent("input", {
key: e.currentTarget.dataset.key,
value: e.detail.value,
});
},
dateChange(e) {
this.triggerEvent("input", { key: e.currentTarget.dataset.key, value: e.detail.value });
},
@@ -1 +1,16 @@
<view class="form"><view wx:for="{{fields}}" wx:key="key" class="field"><text class="label">{{item.label}}{{item.required ? ' *' : ''}}</text><input wx:if="{{item.type === 'tel' || item.type === 'phone' || item.type === 'number' || item.type === 'text'}}" type="{{item.type === 'number' ? 'number' : item.type === 'tel' || item.type === 'phone' ? 'number' : 'text'}}" data-key="{{item.key}}" placeholder="{{item.placeholder || '请填写'}}" value="{{values[item.key]}}" bindinput="input"/><textarea wx:elif="{{item.type === 'textarea'}}" data-key="{{item.key}}" placeholder="{{item.placeholder || '请填写'}}" value="{{values[item.key]}}" bindinput="input" auto-height="true"/><picker wx:elif="{{item.type === 'date'}}" mode="date" data-key="{{item.key}}" value="{{values[item.key]}}" bindchange="dateChange"><view class="picker-value">{{values[item.key] || '请选择日期'}}</view></picker><picker wx:elif="{{item.type === 'select' || item.type === 'radio'}}" mode="selector" range="{{item.options}}" range-key="label" data-key="{{item.key}}" bindchange="choose"><view class="picker-value">{{values[item.key] || '请选择'}}</view></picker></view><button class="submit" loading="{{submitting}}" bindtap="submit">{{submitLabel || '提交需求'}}</button></view>
<view class="form">
<view wx:for="{{renderFields}}" wx:key="key" class="field">
<text class="label">{{item.label}}{{item.required ? ' *' : ''}}</text>
<input wx:if="{{item.type === 'tel' || item.type === 'phone' || item.type === 'number' || item.type === 'text'}}" type="{{item.type === 'number' ? 'number' : item.type === 'tel' || item.type === 'phone' ? 'number' : 'text'}}" data-key="{{item.key}}" placeholder="{{item.placeholder || '请填写'}}" value="{{values[item.key]}}" bindinput="input" />
<textarea wx:elif="{{item.type === 'textarea'}}" data-key="{{item.key}}" placeholder="{{item.placeholder || '请填写'}}" value="{{values[item.key]}}" bindinput="input" auto-height="true" />
<picker wx:elif="{{item.type === 'date'}}" mode="date" data-key="{{item.key}}" value="{{values[item.key]}}" bindchange="dateChange"><view class="picker-value">{{values[item.key] || '请选择日期'}}</view></picker>
<picker wx:elif="{{item.type === 'select' || item.type === 'radio'}}" mode="selector" range="{{item.options}}" range-key="label" data-key="{{item.key}}" bindchange="choose"><view class="picker-value">{{values[item.key] || '请选择'}}</view></picker>
<checkbox-group wx:elif="{{item.type === 'checkbox'}}" class="checkbox-group" data-key="{{item.key}}" bindchange="checkboxChange">
<label wx:for="{{item.options}}" wx:for-item="option" wx:key="value" class="checkbox-option">
<checkbox value="{{option.value}}" checked="{{option.checked}}" />
<text>{{option.label}}</text>
</label>
</checkbox-group>
</view>
<button class="submit" loading="{{submitting}}" bindtap="submit">{{submitLabel || '提交需求'}}</button>
</view>
@@ -29,6 +29,16 @@
.picker-value {
color: #77736b;
}
.checkbox-group {
flex: 1;
}
.checkbox-option {
display: flex;
align-items: center;
min-height: 64rpx;
color: #252827;
font-size: 24rpx;
}
.submit {
margin-top: 30rpx;
background: #252827;
@@ -1 +1 @@
<view class="detail"><view class="hero-wrap"><image class="hero" src="{{item.detailHero || item.image}}" mode="aspectFill"/><view class="hero-shade"></view><view class="hero-copy"><text>{{item.category}} · {{item.area}}</text><text>{{item.name}}</text><text>{{item.series}}</text></view></view><view class="content"><view class="price-card"><view><text>{{presentation.priceLabel}}</text><text>{{item.priceRange}}</text></view><view><text>{{presentation.spaceLabel}}</text><text>{{item.spaceType}}</text></view></view><view class="detail-section"><text class="section-title">{{presentation.backgroundTitle}}</text><text class="body">{{item.details.background || item.desc}}</text></view><view wx:if="{{item.details.designConcept}}" class="detail-section"><text class="section-title">{{presentation.conceptTitle}}</text><text class="body warm">{{item.details.designConcept}}</text></view><view wx:if="{{item.details.crafts.length}}" class="detail-section"><text class="section-title">{{presentation.craftsTitle}}</text><view wx:for="{{item.details.crafts}}" wx:key="*this" class="craft"><text>0{{index + 1}}</text><text>{{item}}</text></view></view><view wx:if="{{item.details.materialsList.length}}" class="detail-section"><text class="section-title">{{presentation.materialsTitle}}</text><view class="materials"><view wx:for="{{item.details.materialsList}}" wx:key="name"><text>{{item.name}}</text><text>{{item.spec}}</text></view></view></view><view class="chips"><text wx:for="{{item.keywords}}" wx:key="*this">{{item}}</text></view></view><view class="bar"><button bindtap="inquire">{{presentation.inquiryAction}}</button><text>{{presentation.inquiryHint}}</text></view></view>
<view class="detail"><view class="hero-wrap"><image class="hero" src="{{item.detailHero || item.image}}" mode="aspectFill"/><view class="hero-shade"></view><view class="hero-copy"><text>{{item.presentation.categoryLabel || item.category}} · {{item.area}}</text><text>{{item.name}}</text><text>{{item.series}}</text></view></view><view class="content"><view class="price-card"><view><text>{{presentation.priceLabel}}</text><text>{{item.priceRange}}</text></view><view><text>{{presentation.spaceLabel}}</text><text>{{item.spaceType}}</text></view></view><view class="detail-section"><text class="section-title">{{presentation.backgroundTitle}}</text><text class="body">{{item.details.background || item.desc}}</text></view><view wx:if="{{item.details.designConcept}}" class="detail-section"><text class="section-title">{{presentation.conceptTitle}}</text><text class="body warm">{{item.details.designConcept}}</text></view><view wx:if="{{item.details.crafts.length}}" class="detail-section"><text class="section-title">{{presentation.craftsTitle}}</text><view wx:for="{{item.details.crafts}}" wx:key="*this" class="craft"><text>0{{index + 1}}</text><text>{{item}}</text></view></view><view wx:if="{{item.details.materialsList.length}}" class="detail-section"><text class="section-title">{{presentation.materialsTitle}}</text><view class="materials"><view wx:for="{{item.details.materialsList}}" wx:key="name"><text>{{item.name}}</text><text>{{item.spec}}</text></view></view></view><view class="chips"><text wx:for="{{item.keywords}}" wx:key="*this">{{item}}</text></view></view><view class="bar"><button bindtap="inquire">{{presentation.inquiryAction}}</button><text>{{presentation.inquiryHint}}</text></view></view>
+1 -1
View File
@@ -8,7 +8,7 @@
"tdesign-miniprogram": "^1.16.1"
},
"scripts": {
"test:fixture": "node test/validate-fixture.cjs && node --test test/runtime-workspace.test.cjs",
"test:fixture": "node test/validate-fixture.cjs && node --test test/*.test.cjs",
"test:visual-fixture": "node test/validate-visual-fixture.cjs",
"lint": "eslint src --ext .ts",
"typecheck": "tsc -p tsconfig.json --noEmit",
@@ -0,0 +1,66 @@
const assert = require("node:assert/strict");
const fs = require("node:fs");
const path = require("node:path");
const vm = require("node:vm");
const test = require("node:test");
const root = path.resolve(__dirname, "../../..");
const template = path.join(root, "packages/template-acheng-campus-food");
const fields = JSON.parse(fs.readFileSync(path.join(template, "template.json"))).sampleContent.food
.fields;
async function loadPage() {
let page;
vm.runInNewContext(
fs.readFileSync(path.join(template, "miniapp/pages/inquiry/index.js"), "utf8"),
{
Page(value) {
page = value;
},
require(name) {
if (name.includes("runtime-workspace"))
return {
loadWorkspaceWithFallback: () =>
Promise.resolve({
brand: {},
inquiryForms: [{ id: "brand-form", target: "brand", fields }],
}),
};
if (name.includes("navigation")) return { takePageQuery: () => ({}) };
return {};
},
},
);
page.setData = (data) => {
for (const [key, value] of Object.entries(data)) {
if (key.startsWith("values.")) page.data.values[key.slice(7)] = value;
else if (key.startsWith("displayValues.")) page.data.displayValues[key.slice(14)] = value;
else page.data[key] = value;
}
};
await page.onLoad({});
return page;
}
test("餐饮咨询布局保留原型类型按钮和双列字段,文案与选项仍读取表单", async () => {
const page = await loadPage();
assert.equal(page.data.formId, "brand-form");
assert.equal(page.data.fields.find((field) => field.key === "type").useChips, true);
assert.equal(page.data.fields.filter((field) => field.halfWidth).length, 4);
assert.equal(page.data.fields.find((field) => field.key === "type").options.length, 6);
assert.equal(
page.data.fields.find((field) => field.key === "remark").label,
"餐品 / 口味 / 忌口备注",
);
});
test("选择类型或选项保存真实值,选择器展示标签;空数组不能通过必填检查", async () => {
const page = await loadPage();
page.chooseChip({ currentTarget: { dataset: { key: "type", value: "日常留餐" } } });
assert.equal(page.data.values.type, "日常留餐");
const people = page.data.fields.find((field) => field.key === "people");
people.options = [{ label: "人数显示标签", value: "people-value" }];
page.choose({ currentTarget: { dataset: { key: "people" } }, detail: { value: "0" } });
assert.equal(page.data.values.people, "people-value");
assert.equal(page.data.displayValues.people, "人数显示标签");
page.data.fields = [{ key: "allergy", label: "饮食要求", required: true }];
page.data.values = { allergy: [] };
page.submit();
assert.equal(page.data.formError, "请填写饮食要求");
});
@@ -0,0 +1,38 @@
const assert = require("node:assert/strict");
const fs = require("node:fs");
const path = require("node:path");
const vm = require("node:vm");
const test = require("node:test");
const root = path.resolve(__dirname, "../../../packages/template-acheng-campus-food/miniapp");
test("主理人页只呈现资质、案例和承诺,不混入出摊区块", async () => {
let page;
const items = ["schedule", "coverage", "process", "credential", "case", "promise"].map(
(type) => ({ id: type, type, title: type, content: "后台编辑内容" }),
);
vm.runInNewContext(fs.readFileSync(path.join(root, "pages/bookings/index.js"), "utf8"), {
Page(value) {
page = value;
},
require(name) {
return name.includes("runtime-workspace")
? {
loadWorkspaceWithFallback: () =>
Promise.resolve({ brand: { description: "主理人简介" }, trustItems: items }),
}
: {};
},
});
page.setData = (data) => Object.assign(page.data, data);
page.onLoad();
await new Promise((resolve) => setImmediate(resolve));
assert.equal(page.data.credentials.length, 1);
assert.equal(page.data.cases[0].content, "后台编辑内容");
assert.equal(page.data.promises.length, 1);
const markup = fs.readFileSync(
path.join(root, "components/templates/acheng-profile/acheng-profile.wxml"),
"utf8",
);
assert.ok(markup.includes("brand.description"));
assert.ok(!markup.includes("brand.slogan"));
assert.ok(!markup.includes("coverageContent"));
});
@@ -0,0 +1,63 @@
const assert = require("node:assert/strict");
const fs = require("node:fs");
const path = require("node:path");
const vm = require("node:vm");
const test = require("node:test");
const root = path.resolve(__dirname, "../../..");
const template = path.join(root, "packages/template-acheng-campus-food");
const sample = JSON.parse(fs.readFileSync(path.join(template, "template.json"))).sampleContent.food;
async function loadPage(items) {
let page;
vm.runInNewContext(
fs.readFileSync(path.join(template, "miniapp/pages/stall-service/index.js"), "utf8"),
{
Page(value) {
page = value;
},
require(name) {
return name.includes("runtime-workspace")
? { loadWorkspaceWithFallback: () => Promise.resolve({ brand: {}, trustItems: items }) }
: { openPage() {} };
},
},
);
page.setData = (data) => Object.assign(page.data, data);
await page.load();
return page.data;
}
test("旧记录不遮住结构化内容,每种内容只投影一个固定区域", async () => {
const old = ["schedule", "coverage", "process"].map((type) => ({
type,
title: "旧记录",
content: "旧正文",
}));
const data = await loadPage([...old, ...sample.trustContent, ...sample.trustContent]);
assert.equal(data.schedule.rows.length, 2);
assert.equal(data.schedule.rows[0].title, sample.trustContent[0].config.weekdayLabel);
assert.equal(data.schedule.rows[1].title, sample.trustContent[0].config.weekendLabel);
assert.equal(data.coverage.config.pickupDetail, sample.trustContent[1].config.pickupDetail);
assert.equal(data.coverage.config.deliveryDetail, sample.trustContent[1].config.deliveryDetail);
assert.equal(data.process.steps.length, 4);
assert.equal(new Set(data.process.steps.map((step) => step.index)).size, 4);
assert.ok(data.process.steps.every((step) => step.title && step.detail));
});
test("缺少配置时不渲染空配送卡和空流程卡", async () => {
const data = await loadPage([
{ type: "coverage", title: "地点", config: {} },
{ type: "process", title: "旧流程", content: "步骤一\n步骤二" },
]);
assert.equal(data.coverage, null);
assert.equal(data.process, null);
});
test("编辑工作日、周末、配送和步骤变量后页面数据同时更新", async () => {
const items = JSON.parse(JSON.stringify(sample.trustContent));
items[0].config.weekdayDetail = "工作日新地点";
items[0].config.weekendHours = "周末新时间";
items[1].config.deliveryDetail = "新配送规则";
items[2].config.steps[0].detail = "新第一步";
const data = await loadPage(items);
assert.equal(data.schedule.rows[0].detail, "工作日新地点");
assert.equal(data.schedule.rows[1].hours, "周末新时间");
assert.equal(data.coverage.config.deliveryDetail, "新配送规则");
assert.equal(data.process.steps[0].detail, "新第一步");
});
@@ -0,0 +1,50 @@
const assert = require("node:assert/strict");
const fs = require("node:fs");
const path = require("node:path");
const test = require("node:test");
const vm = require("node:vm");
const componentDirectory = path.join(__dirname, "../components/modules/inquiry-form");
let definition;
vm.runInNewContext(fs.readFileSync(path.join(componentDirectory, "inquiry-form.js"), "utf8"), {
Component: (value) => {
definition = value;
},
});
test("多选字段根据已有值标记选项并把选中值数组传回表单", () => {
const context = {
data: {},
events: [],
setData(value) {
this.data = { ...this.data, ...value };
},
triggerEvent(name, detail) {
this.events.push({ name, detail });
},
};
definition.observers["fields, values"].call(
context,
[
{
key: "topics",
type: "checkbox",
options: [
{ label: "咨询", value: "consulting" },
{ label: "设计", value: "design" },
],
},
],
{ topics: ["design"] },
);
assert.equal(context.data.renderFields[0].options[0].checked, false);
assert.equal(context.data.renderFields[0].options[1].checked, true);
definition.methods.checkboxChange.call(context, {
currentTarget: { dataset: { key: "topics" } },
detail: { value: ["consulting", "design"] },
});
assert.equal(context.events[0].name, "input");
assert.equal(context.events[0].detail.key, "topics");
assert.deepEqual(context.events[0].detail.value, ["consulting", "design"]);
});
+1 -1
View File
@@ -53,7 +53,7 @@ test("运行时保留模板业务数据,不再解释视觉模块", async () =>
modules: [{ key: "brand-hero" }],
visualTemplateManifest: { pages: [] },
});
assert.deepEqual(workspace.trustContent, { bio: "品牌介绍" });
assert.deepEqual(workspace.trustPresentation, { bio: "品牌介绍" });
assert.equal(workspace.fields, undefined);
assert.equal(workspace.inquiryForm, undefined);
assert.equal(workspace.modules[0].key, "brand-hero");
+24
View File
@@ -0,0 +1,24 @@
const assert = require("node:assert/strict");
const fs = require("node:fs");
const path = require("node:path");
const test = require("node:test");
const vm = require("node:vm");
const source = fs.readFileSync(path.join(__dirname, "../utils/trust-content.js"), "utf8");
const trustModule = { exports: {} };
vm.runInNewContext(source, { module: trustModule });
const { prepareTrustItems } = trustModule.exports;
test("流程信任内容按换行整理为非空步骤", () => {
const [process] = prepareTrustItems([
{ type: "process", title: "定制流程", content: " 沟通需求\r\n\n确认菜单\n 现场交付 " },
]);
assert.equal(JSON.stringify(process.lines), JSON.stringify(["沟通需求", "确认菜单", "现场交付"]));
assert.equal(process.content, " 沟通需求\r\n\n确认菜单\n 现场交付 ");
});
test("非流程信任内容不添加步骤列表", () => {
const [schedule] = prepareTrustItems([{ type: "schedule", content: "工作日营业" }]);
assert.equal("lines" in schedule, false);
assert.equal(prepareTrustItems(null).length, 0);
});
+2 -2
View File
@@ -29,7 +29,7 @@ function normalizeWorkspace(workspace) {
const offerings = Array.isArray(workspace && workspace.offerings)
? workspace.offerings.map(toOffering)
: [];
const trustContent =
const trustPresentation =
workspace && workspace.trustPresentation && typeof workspace.trustPresentation === "object"
? workspace.trustPresentation
: {};
@@ -43,7 +43,7 @@ function normalizeWorkspace(workspace) {
...workspace,
brand,
offerings,
trustContent,
trustPresentation,
trustItems,
plugins: Array.isArray(workspace.plugins) ? workspace.plugins : [],
};
+19
View File
@@ -0,0 +1,19 @@
function prepareTrustItems(items) {
if (!Array.isArray(items)) return [];
return items.map((item) => ({
...item,
...(item.type === "process"
? {
lines:
typeof item.content === "string"
? item.content
.split(/\r?\n/)
.map((line) => line.trim())
.filter(Boolean)
: [],
}
: {}),
}));
}
module.exports = { prepareTrustItems };