feat: 完善模板字段编辑与分类治理

This commit is contained in:
que01 committed 2026-10-11 23:07:53 +08:00
1 parent 91322fa9a0
commit 26bcb2b66e
23 files changed
+631 -250

No files matched your search

@@ -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;
-10
View File
@@ -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: [],
+2 -1
View File
@@ -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<typeof getBrandTemplate> | null;
visualTemplateDefinition?: ReturnType<typeof getVisualTemplate> | null;
visualTemplateManifest?: ReturnType<typeof getVisualTemplateManifest> | null;
templatePackageManifest?: ReturnType<typeof getTemplatePackageManifestForVisualKey> | null;
templatePackageManifest?: TemplatePackageManifest | null;
brand: Record<string, unknown> | null;
installation: Record<string, unknown> | null;
fields: unknown[];
@@ -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
+15 -9
View File
@@ -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");