)}
>
@@ -507,6 +528,7 @@ export function ServicesPage() {
...templateFieldSection,
fields: activeTemplateFields,
}}
+ sectionKey="offering"
/>
) : null}
diff --git a/apps/admin/src/features/workspace/WorkspacePage.tsx b/apps/admin/src/features/workspace/WorkspacePage.tsx
index 49630c7..d42cada 100644
--- a/apps/admin/src/features/workspace/WorkspacePage.tsx
+++ b/apps/admin/src/features/workspace/WorkspacePage.tsx
@@ -36,25 +36,16 @@ const inquiryFieldTypes = [
{ value: "multi-select", label: "多项选择" },
];
-function optionsToText(options: unknown): string {
- if (!Array.isArray(options)) return "";
- return options
- .map((option) => {
- if (!option || typeof option !== "object") return "";
- const label = (option as { label?: unknown }).label;
- return typeof label === "string" ? label : "";
- })
- .filter(Boolean)
- .join("\n");
+function readOptionLabel(option: unknown): string {
+ const value = option as { label?: unknown } | null | undefined;
+ return typeof value?.label === "string" ? value.label : "";
}
-function optionsFromText(value: unknown): Array<{ label: string; value: string }> {
- if (typeof value !== "string") return [];
- return value
- .split(/\r?\n|、|,/)
- .map((item) => item.trim())
- .filter(Boolean)
- .map((item) => ({ label: item, value: item }));
+function normalizeOptionLabels(options: unknown): Array<{ label: string; value: string }> {
+ return (Array.isArray(options) ? options : [])
+ .map(readOptionLabel)
+ .filter((label) => label.trim())
+ .map((label) => ({ label, value: label }));
}
function supportsIndustry(
@@ -541,11 +532,11 @@ export function WorkspacePage() {
name: item.name,
purpose: item.purpose,
offeringId: item.offeringId ?? undefined,
- fieldsSnapshot: item.fieldsSnapshot.map((field) => {
+ fieldsSnapshot: item.fieldsSnapshot.map((field: unknown) => {
const value = field as Record;
return {
...value,
- optionsText: optionsToText(value.options),
+ options: normalizeOptionLabels(value.options),
};
}),
});
@@ -719,12 +710,15 @@ export function WorkspacePage() {
fieldsSnapshot: (Array.isArray(values.fieldsSnapshot)
? values.fieldsSnapshot
: []
- ).map((field) => {
+ ).map((field: unknown) => {
const item = field as Record;
- const { optionsText, ...rest } = item;
+ const { options, ...rest } = item;
const type = typeof rest.type === "string" ? rest.type : "text";
return ["select", "radio", "multi-select"].includes(type)
- ? { ...rest, options: optionsFromText(optionsText) }
+ ? {
+ ...rest,
+ options: normalizeOptionLabels(options),
+ }
: rest;
}),
};
@@ -824,18 +818,54 @@ export function WorkspacePage() {
["select", "radio", "multi-select"].includes(
String(getFieldValue(["fieldsSnapshot", name, "type"])),
) ? (
-
+ Array.isArray(value) &&
+ value.some((option: unknown) => readOptionLabel(option).trim())
+ ? Promise.resolve()
+ : Promise.reject(new Error("请至少添加一个选项")),
+ },
+ ]}
>
-
-
+ {(optionFields, { add, remove }, { errors }) => (
+ <>
+ {optionFields.map((optionField) => (
+
+
+
+
+
+
+ ))}
+
+
+ >
+ )}
+
) : null
}
diff --git a/apps/api/prisma/migrations/20261011120000_normalize_offering_categories/migration.sql b/apps/api/prisma/migrations/20261011120000_normalize_offering_categories/migration.sql
new file mode 100644
index 0000000..cb11e86
--- /dev/null
+++ b/apps/api/prisma/migrations/20261011120000_normalize_offering_categories/migration.sql
@@ -0,0 +1,5 @@
+-- Normalize offering category storage: categoryKey is authoritative.
+-- Display labels are projected from the active template manifest.
+UPDATE "Offering"
+SET "config" = "config" - 'categoryLabel'
+WHERE "config" IS NOT NULL;
diff --git a/apps/api/prisma/seed.ts b/apps/api/prisma/seed.ts
index ff052c5..2c54f5c 100644
--- a/apps/api/prisma/seed.ts
+++ b/apps/api/prisma/seed.ts
@@ -128,7 +128,6 @@ const runtimeSeedTemplates: Record<"personal" | "food" | "doors", RuntimeSeedTem
kind: "service",
config: {
categoryKey: "consulting",
- categoryLabel: "策略咨询",
keywords: ["定位", "诊断", "表达"],
},
},
@@ -139,7 +138,6 @@ const runtimeSeedTemplates: Record<"personal" | "food" | "doors", RuntimeSeedTem
kind: "subscription",
config: {
categoryKey: "advisory",
- categoryLabel: "长期顾问",
keywords: ["陪跑", "内容", "转化"],
},
},
@@ -248,7 +246,6 @@ const runtimeSeedTemplates: Record<"personal" | "food" | "doors", RuntimeSeedTem
priceAmount: 2800,
config: {
categoryKey: "set-meal",
- categoryLabel: "套餐",
keywords: ["现做", "家常", "定制"],
},
},
@@ -260,7 +257,6 @@ const runtimeSeedTemplates: Record<"personal" | "food" | "doors", RuntimeSeedTem
priceAmount: 3200,
config: {
categoryKey: "set-meal",
- categoryLabel: "套餐",
keywords: ["现做", "家常", "定制"],
},
},
@@ -271,7 +267,6 @@ const runtimeSeedTemplates: Record<"personal" | "food" | "doors", RuntimeSeedTem
kind: "service",
config: {
categoryKey: "private-chef",
- categoryLabel: "私厨",
keywords: ["现做", "家常", "定制"],
},
},
@@ -410,7 +405,6 @@ const runtimeSeedTemplates: Record<"personal" | "food" | "doors", RuntimeSeedTem
priceText: "¥38,000 - ¥85,000 / 樘",
config: {
categoryKey: "entrance-door",
- categoryLabel: "入户大门",
series: "「万籁」重型天地轴入户系统",
tag: "主理人年度代表作",
area: "浙江·莫干山私家山庄",
@@ -446,7 +440,6 @@ const runtimeSeedTemplates: Record<"personal" | "food" | "doors", RuntimeSeedTem
priceText: "¥42,000 - ¥98,000 / 樘",
config: {
categoryKey: "garden-door",
- categoryLabel: "庭院围墙门",
series: "「虚实」透光私家庭院门",
tag: "建筑级耐候工艺",
area: "上海·佘山高尔夫别墅",
@@ -481,7 +474,6 @@ const runtimeSeedTemplates: Record<"personal" | "food" | "doors", RuntimeSeedTem
priceText: "¥7,800 - ¥16,000 / 樘",
config: {
categoryKey: "interior-door",
- categoryLabel: "室内户内门",
series: "「空灵」2.8m - 3.2m 满高通顶系统",
tag: "极简建筑平直感",
area: "江苏·苏州金鸡湖独栋",
@@ -516,7 +508,6 @@ const runtimeSeedTemplates: Record<"personal" | "food" | "doors", RuntimeSeedTem
priceText: "¥18,000 - ¥36,000 / 樘",
config: {
categoryKey: "stealth-door",
- categoryLabel: "装饰隐形门",
series: "「无垠」密室及背景墙融合门",
tag: "精密收口工程",
area: "广东·深圳香蜜湖一号",
@@ -729,7 +720,6 @@ async function ensureRuntimeContent(brandId: string, template: RuntimeSeedTempla
coverUrl: image,
config: {
categoryKey: "custom",
- categoryLabel: "自定义业务",
keywords: [],
media: [{ url: image, alt: item.name, type: "image" }],
sections: [],
diff --git a/apps/api/src/brand-release.service.ts b/apps/api/src/brand-release.service.ts
index ef50038..4e5314d 100644
--- a/apps/api/src/brand-release.service.ts
+++ b/apps/api/src/brand-release.service.ts
@@ -7,6 +7,7 @@ import {
getDefaultVisualTemplateKey,
getTemplatePackageManifestForVisualKey,
} from "@personal-brand/config";
+import type { TemplatePackageManifest } from "@personal-brand/config";
import { PrismaService } from "./prisma.service.js";
export interface BrandReleaseSnapshot {
@@ -16,7 +17,7 @@ export interface BrandReleaseSnapshot {
templateDefinition?: ReturnType | null;
visualTemplateDefinition?: ReturnType | null;
visualTemplateManifest?: ReturnType | null;
- templatePackageManifest?: ReturnType | null;
+ templatePackageManifest?: TemplatePackageManifest | null;
brand: Record | null;
installation: Record | null;
fields: unknown[];
diff --git a/apps/api/src/modules/public/public-workspace.controller.ts b/apps/api/src/modules/public/public-workspace.controller.ts
index d50751d..73337b2 100644
--- a/apps/api/src/modules/public/public-workspace.controller.ts
+++ b/apps/api/src/modules/public/public-workspace.controller.ts
@@ -119,6 +119,14 @@ export class PublicWorkspaceService {
const templatePackageManifest =
releaseSnapshot.templatePackageManifest ??
getTemplatePackageManifestForVisualKey(visualTemplateKey);
+ const categoryOptions = new Map(
+ (templatePackageManifest?.admin.sections ?? [])
+ .filter((section) => section.target === "offering")
+ .flatMap((section) => section.fields)
+ .filter((field) => field.binding === "offering.config.categoryKey")
+ .flatMap((field) => field.options ?? [])
+ .map((option) => [option.value, option.label]),
+ );
// 标准 BrandProfile 字段优先,兼容旧模板仍使用的 config 字段。
// 这样后台编辑 description/contactPhone 等标准字段后,旧模板也会立即读取新值。
const runtimeBrand = projectBrandAliases(brandData, brandConfig);
@@ -177,7 +185,9 @@ export class PublicWorkspaceService {
...this.jsonObject(config.presentation),
categoryKey: typeof config.categoryKey === "string" ? config.categoryKey : "custom",
categoryLabel:
- typeof config.categoryLabel === "string" ? config.categoryLabel : "业务提供项",
+ categoryOptions.get(
+ typeof config.categoryKey === "string" ? config.categoryKey : "custom",
+ ) ?? "",
heroImage:
typeof config.detailHero === "string"
? config.detailHero
diff --git a/apps/api/test/http.integration.test.js b/apps/api/test/http.integration.test.js
index f30fea0..03233d3 100644
--- a/apps/api/test/http.integration.test.js
+++ b/apps/api/test/http.integration.test.js
@@ -1034,14 +1034,6 @@ test("visual template compatibility is enforced by catalog, preview, and brand s
test("seeded public workspaces keep personal, food, and doors brands isolated", async () => {
const expected = [
- {
- slug: "linran-brand",
- id: "00000000-0000-0000-0000-000000000003",
- templateKey: "personal",
- founder: "林然",
- offeringKind: "service",
- categoryLabel: "策略咨询",
- },
{
slug: "default-brand",
id: "00000000-0000-0000-0000-000000000001",
@@ -1089,7 +1081,7 @@ test("seeded public workspaces keep personal, food, and doors brands isolated",
return workspace;
}),
);
- assert.equal(new Set(workspaces.map((workspace) => workspace.brand.id)).size, 3);
+ assert.equal(new Set(workspaces.map((workspace) => workspace.brand.id)).size, 2);
});
test("public workspace uses brand-scoped capability installations and preserves status", async () => {
@@ -2207,6 +2199,20 @@ test("admin can manage offerings and public endpoint hides disabled offerings",
});
assert.equal(listed.statusCode, 200);
assert.ok(JSON.parse(listed.body).some((item) => item.id === id));
+ const withCategory = await request(`/admin/workspace/offerings/${id}`, {
+ method: "PATCH",
+ headers: { authorization: `Bearer ${token}` },
+ payload: { config: { categoryKey: "set-meal" } },
+ });
+ assert.equal(withCategory.statusCode, 200);
+ const preview = await request("/admin/workspace/preview", {
+ headers: { authorization: `Bearer ${token}` },
+ });
+ assert.equal(preview.statusCode, 200);
+ const draft = JSON.parse(preview.body);
+ const previewOffering = draft.offerings.find((item) => item.id === id);
+ assert.equal(previewOffering?.presentation?.categoryKey, "set-meal");
+ assert.equal(previewOffering?.presentation?.categoryLabel, "套餐");
const publicItem = await request(`/public/offerings/${id}`);
assert.equal(publicItem.statusCode, 400);
const publicList = await request("/public/offerings");
diff --git a/apps/taro/test/browser/admin-editor.spec.ts b/apps/taro/test/browser/admin-editor.spec.ts
index 88bc693..9ff5f82 100644
--- a/apps/taro/test/browser/admin-editor.spec.ts
+++ b/apps/taro/test/browser/admin-editor.spec.ts
@@ -102,7 +102,7 @@ const adminOffering = {
coverUrl: brand.avatarUrl,
isEnabled: true,
sortOrder: 0,
- config: { categoryLabel: "业务提供项" },
+ config: { categoryKey: "custom" },
};
const adminTrust = {
id: "schedule-fixture",
@@ -139,7 +139,7 @@ const runtimeWorkspace = {
priceText: adminOffering.priceText,
coverUrl: adminOffering.coverUrl,
presentation: {
- categoryLabel: "业务提供项",
+ categoryLabel: "定制餐品",
keywords: [],
details: { background: "餐品详情", designConcept: "", crafts: [], materialsList: [] },
},
diff --git a/apps/taro/test/browser/services-editor.spec.ts b/apps/taro/test/browser/services-editor.spec.ts
index 3b229bf..e423860 100644
--- a/apps/taro/test/browser/services-editor.spec.ts
+++ b/apps/taro/test/browser/services-editor.spec.ts
@@ -38,7 +38,7 @@ const adminOffering = {
isEnabled: true,
sortOrder: 0,
config: {
- categoryLabel: "家庭餐",
+ categoryKey: "private-chef",
area: "东门",
series: "预约制",
spaceType: "8 人聚餐",
@@ -67,7 +67,7 @@ const runtimeWorkspace = {
priceText: adminOffering.priceText,
coverUrl: adminOffering.coverUrl,
presentation: {
- categoryLabel: adminOffering.config.categoryLabel,
+ categoryLabel: "私厨",
area: adminOffering.config.area,
series: adminOffering.config.series,
spaceType: adminOffering.config.spaceType,
diff --git a/packages/config/src/generated-template-packages.js b/packages/config/src/generated-template-packages.js
index 775bfca..c73a8ad 100644
--- a/packages/config/src/generated-template-packages.js
+++ b/packages/config/src/generated-template-packages.js
@@ -509,9 +509,23 @@ export const generatedTemplatePackageRegistry = [
},
{
"key": "categoryLabel",
- "binding": "offering.config.categoryLabel",
+ "binding": "offering.config.categoryKey",
"label": "餐品类别",
- "input": "text",
+ "input": "select",
+ "options": [
+ {
+ "value": "set-meal",
+ "label": "套餐"
+ },
+ {
+ "value": "private-chef",
+ "label": "私厨"
+ },
+ {
+ "value": "custom",
+ "label": "定制餐品"
+ }
+ ],
"previewTarget": "acheng-campus-food.offerings.item"
}
],
@@ -615,9 +629,23 @@ export const generatedTemplatePackageRegistry = [
"fields": [
{
"key": "categoryLabel",
- "binding": "offering.config.categoryLabel",
+ "binding": "offering.config.categoryKey",
"label": "餐品类别",
- "input": "text",
+ "input": "select",
+ "options": [
+ {
+ "value": "set-meal",
+ "label": "套餐"
+ },
+ {
+ "value": "private-chef",
+ "label": "私厨"
+ },
+ {
+ "value": "custom",
+ "label": "定制餐品"
+ }
+ ],
"previewTarget": "acheng-campus-food.detail.dishDetail"
},
{
@@ -1753,9 +1781,31 @@ export const generatedTemplatePackageRegistry = [
},
{
"key": "categoryLabel",
- "binding": "offering.config.categoryLabel",
+ "binding": "offering.config.categoryKey",
"label": "案例类别",
- "input": "text",
+ "input": "select",
+ "options": [
+ {
+ "value": "entrance-door",
+ "label": "入户大门"
+ },
+ {
+ "value": "garden-door",
+ "label": "庭院围墙门"
+ },
+ {
+ "value": "interior-door",
+ "label": "室内户内门"
+ },
+ {
+ "value": "stealth-door",
+ "label": "装饰隐形门"
+ },
+ {
+ "value": "custom",
+ "label": "设计咨询"
+ }
+ ],
"previewTarget": "linjing-editorial.home.offering"
},
{
@@ -2189,9 +2239,31 @@ export const generatedTemplatePackageRegistry = [
},
{
"key": "categoryLabel",
- "binding": "offering.config.categoryLabel",
+ "binding": "offering.config.categoryKey",
"label": "案例类别",
- "input": "text",
+ "input": "select",
+ "options": [
+ {
+ "value": "entrance-door",
+ "label": "入户大门"
+ },
+ {
+ "value": "garden-door",
+ "label": "庭院围墙门"
+ },
+ {
+ "value": "interior-door",
+ "label": "室内户内门"
+ },
+ {
+ "value": "stealth-door",
+ "label": "装饰隐形门"
+ },
+ {
+ "value": "custom",
+ "label": "设计咨询"
+ }
+ ],
"previewTarget": "linjing-editorial.offerings.item"
},
{
@@ -2320,9 +2392,31 @@ export const generatedTemplatePackageRegistry = [
"fields": [
{
"key": "categoryLabel",
- "binding": "offering.config.categoryLabel",
+ "binding": "offering.config.categoryKey",
"label": "案例类别",
- "input": "text",
+ "input": "select",
+ "options": [
+ {
+ "value": "entrance-door",
+ "label": "入户大门"
+ },
+ {
+ "value": "garden-door",
+ "label": "庭院围墙门"
+ },
+ {
+ "value": "interior-door",
+ "label": "室内户内门"
+ },
+ {
+ "value": "stealth-door",
+ "label": "装饰隐形门"
+ },
+ {
+ "value": "custom",
+ "label": "设计咨询"
+ }
+ ],
"previewTarget": "linjing-editorial.detail.projectDetail"
},
{
@@ -3028,4 +3122,4 @@ export const generatedTemplatePackageRegistry = [
}
];
export const generatedTemplatePackageRegistryHash =
- "dbe686adc4c4efa5a7667c08671381fb28152c688baefcc70bf52655bed3012e";
+ "56656913de9cbf7f406e705cfea33698f2404b23f3b6fe9423345a8bef57708e";
diff --git a/packages/config/src/index.ts b/packages/config/src/index.ts
index b68183e..e98155b 100644
--- a/packages/config/src/index.ts
+++ b/packages/config/src/index.ts
@@ -235,15 +235,27 @@ export interface TemplatePackageManifest {
key: string;
title: string;
description: string;
+ page: string;
target: "brand" | "offering" | "trust" | "inquiry";
+ previewTargets?: readonly {
+ key: string;
+ label: string;
+ composite?: boolean;
+ children?: readonly string[];
+ }[];
fields: readonly {
key: string;
binding: string;
label: string;
input: string;
+ help?: string;
required?: boolean;
itemFields?: readonly { key: string; label: string; input?: string; required?: boolean }[];
itemValueKey?: string;
+ maxLength?: number;
+ placeholder?: string;
+ options?: readonly { value: string; label: string }[];
+ previewTarget?: string;
}[];
}[];
};
diff --git a/packages/template-acheng-campus-food/template.json b/packages/template-acheng-campus-food/template.json
index c0a493a..de2960e 100644
--- a/packages/template-acheng-campus-food/template.json
+++ b/packages/template-acheng-campus-food/template.json
@@ -496,9 +496,14 @@
},
{
"key": "categoryLabel",
- "binding": "offering.config.categoryLabel",
+ "binding": "offering.config.categoryKey",
"label": "餐品类别",
- "input": "text",
+ "input": "select",
+ "options": [
+ { "value": "set-meal", "label": "套餐" },
+ { "value": "private-chef", "label": "私厨" },
+ { "value": "custom", "label": "定制餐品" }
+ ],
"previewTarget": "acheng-campus-food.offerings.item"
}
],
@@ -602,9 +607,14 @@
"fields": [
{
"key": "categoryLabel",
- "binding": "offering.config.categoryLabel",
+ "binding": "offering.config.categoryKey",
"label": "餐品类别",
- "input": "text",
+ "input": "select",
+ "options": [
+ { "value": "set-meal", "label": "套餐" },
+ { "value": "private-chef", "label": "私厨" },
+ { "value": "custom", "label": "定制餐品" }
+ ],
"previewTarget": "acheng-campus-food.detail.dishDetail"
},
{
diff --git a/packages/template-linjing-editorial/template.json b/packages/template-linjing-editorial/template.json
index ce17d08..65cba47 100644
--- a/packages/template-linjing-editorial/template.json
+++ b/packages/template-linjing-editorial/template.json
@@ -224,9 +224,16 @@
},
{
"key": "categoryLabel",
- "binding": "offering.config.categoryLabel",
+ "binding": "offering.config.categoryKey",
"label": "案例类别",
- "input": "text",
+ "input": "select",
+ "options": [
+ { "value": "entrance-door", "label": "入户大门" },
+ { "value": "garden-door", "label": "庭院围墙门" },
+ { "value": "interior-door", "label": "室内户内门" },
+ { "value": "stealth-door", "label": "装饰隐形门" },
+ { "value": "custom", "label": "设计咨询" }
+ ],
"previewTarget": "linjing-editorial.home.offering"
},
{
@@ -660,9 +667,16 @@
},
{
"key": "categoryLabel",
- "binding": "offering.config.categoryLabel",
+ "binding": "offering.config.categoryKey",
"label": "案例类别",
- "input": "text",
+ "input": "select",
+ "options": [
+ { "value": "entrance-door", "label": "入户大门" },
+ { "value": "garden-door", "label": "庭院围墙门" },
+ { "value": "interior-door", "label": "室内户内门" },
+ { "value": "stealth-door", "label": "装饰隐形门" },
+ { "value": "custom", "label": "设计咨询" }
+ ],
"previewTarget": "linjing-editorial.offerings.item"
},
{
@@ -791,9 +805,16 @@
"fields": [
{
"key": "categoryLabel",
- "binding": "offering.config.categoryLabel",
+ "binding": "offering.config.categoryKey",
"label": "案例类别",
- "input": "text",
+ "input": "select",
+ "options": [
+ { "value": "entrance-door", "label": "入户大门" },
+ { "value": "garden-door", "label": "庭院围墙门" },
+ { "value": "interior-door", "label": "室内户内门" },
+ { "value": "stealth-door", "label": "装饰隐形门" },
+ { "value": "custom", "label": "设计咨询" }
+ ],
"previewTarget": "linjing-editorial.detail.projectDetail"
},
{
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 32d7790..0d452b5 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -32,6 +32,9 @@ importers:
apps/admin:
dependencies:
+ '@ant-design/icons':
+ specifier: ^6.3.4
+ version: 6.3.4(react-dom@19.3.0(react@19.3.0))(react@19.3.0)
'@personal-brand/api-client':
specifier: workspace:*
version: link:../../packages/api-client
diff --git a/scripts/lib/template-doctor.mjs b/scripts/lib/template-doctor.mjs
index dc84da8..aa7a934 100644
--- a/scripts/lib/template-doctor.mjs
+++ b/scripts/lib/template-doctor.mjs
@@ -101,7 +101,7 @@ export function diagnoseTemplate(manifest, source, file = "taro/index.tsx") {
image: "offering.config.detailHero",
desc: "offering.summary",
priceRange: "offering.priceText",
- category: "offering.config.categoryLabel",
+ category: "offering.config.categoryKey",
area: "offering.config.area",
series: "offering.config.series",
keywords: "offering.config.keywords",