From a3434ce2b9b91d6b9777ba62c6de82d38f4ca052 Mon Sep 17 00:00:00 2001 From: que01 Date: Sun, 20 Sep 2026 17:37:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BB=BA=E7=AB=8B=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8C=96=E6=A8=A1=E6=9D=BF=E6=B3=A8=E5=86=8C=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/api/src/main.ts | 9 ++++--- packages/api-client/src/index.ts | 8 ++++++ packages/config/src/index.ts | 44 ++++++++++++++++++++++++++++++-- 3 files changed, 55 insertions(+), 6 deletions(-) diff --git a/apps/api/src/main.ts b/apps/api/src/main.ts index 4341d9e..d1f55cc 100644 --- a/apps/api/src/main.ts +++ b/apps/api/src/main.ts @@ -49,7 +49,7 @@ import type { TransformFnParams } from "class-transformer"; import { IsBoolean, IsEnum, IsOptional, IsString } from "class-validator"; import { readIdentity, signIdentity } from "./auth.js"; import { ApiExceptionFilter, RequestIdMiddleware } from "./http.js"; -import { brandTemplates, type BrandTemplateKey } from "@personal-brand/config"; +import { brandTemplates, getBrandTemplate } from "@personal-brand/config"; @Controller("health") export class HealthController { @@ -122,7 +122,7 @@ export class PublicTrustContentController { export class PublicTemplateController { @Get(":key") get(@Param("key") key: string): unknown { - const template = brandTemplates[key as BrandTemplateKey]; + const template = getBrandTemplate(key); if (!template) throw new BadRequestException("行业模板不存在"); return template; } @@ -354,7 +354,8 @@ export class AdminWorkspaceController { ): Promise { this.requireAdmin(request); const brandId = this.brandId(); - const template = brandTemplates[body.templateKey]; + const template = getBrandTemplate(body.templateKey); + if (!template) throw new BadRequestException("行业模板不存在"); const existing = await this.prisma.brandTemplateInstallation.findFirst({ where: { brandId } }); if (existing) { if (existing.templateKey === body.templateKey) @@ -376,7 +377,7 @@ export class AdminWorkspaceController { ] as const; return this.prisma.$transaction(async (tx) => { const installation = await tx.brandTemplateInstallation.create({ - data: { brandId, templateKey: body.templateKey, templateVersion: "1.0.0" }, + data: { brandId, templateKey: body.templateKey, templateVersion: template.version }, }); await tx.brandModule.createMany({ data: modules.map(([type, title], sortOrder) => ({ diff --git a/packages/api-client/src/index.ts b/packages/api-client/src/index.ts index c24b14b..0b93805 100644 --- a/packages/api-client/src/index.ts +++ b/packages/api-client/src/index.ts @@ -103,10 +103,18 @@ export interface ApiErrorBody { } export interface BrandTemplateDefinition { key: "personal" | "food"; + version: string; name: string; description: string; serviceCategories: string[]; trustContentTypes: string[]; + modules: Array<{ + key: string; + type: string; + title: string; + required: boolean; + }>; + capabilities: string[]; } export interface OfferingSection { type: "text" | "image-list" | "timeline" | "faq"; diff --git a/packages/config/src/index.ts b/packages/config/src/index.ts index 81d0aab..6305eb7 100644 --- a/packages/config/src/index.ts +++ b/packages/config/src/index.ts @@ -1,16 +1,31 @@ export const configPackageName = "personal-brand-config"; export type BrandTemplateKey = "personal" | "food"; + +export type BrandTemplateModuleType = "identity" | "trust" | "offering" | "inquiry" | "contact"; + +export interface BrandTemplateModuleDefinition { + key: string; + type: BrandTemplateModuleType; + title: string; + required: boolean; +} + export interface BrandTemplateDefinition { key: BrandTemplateKey; + version: string; name: string; description: string; serviceCategories: string[]; trustContentTypes: string[]; + modules: BrandTemplateModuleDefinition[]; + capabilities: string[]; } -export const brandTemplates: Record = { + +export const brandTemplates = { personal: { key: "personal", + version: "1.0.0", name: "个人品牌", description: "围绕定位、信任、作品与合作建立个人品牌。", serviceCategories: ["consulting", "collaboration", "custom"], @@ -22,9 +37,18 @@ export const brandTemplates: Record = "process", "testimonial", ], + modules: [ + { key: "identity", type: "identity", title: "品牌身份", required: true }, + { key: "trust", type: "trust", title: "信任内容", required: true }, + { key: "offerings", type: "offering", title: "业务提供项", required: true }, + { key: "inquiry", type: "inquiry", title: "联系与咨询", required: true }, + { key: "contact", type: "contact", title: "品牌表达", required: true }, + ], + capabilities: ["offerings", "inquiry"], }, food: { key: "food", + version: "1.0.0", name: "餐饮模板", description: "适用于餐饮服务与套餐预约的行业模板。", serviceCategories: ["food-package", "private-chef", "custom"], @@ -36,5 +60,21 @@ export const brandTemplates: Record = "process", "testimonial", ], + modules: [ + { key: "identity", type: "identity", title: "品牌身份", required: true }, + { key: "trust", type: "trust", title: "信任内容", required: true }, + { key: "offerings", type: "offering", title: "菜单与服务", required: true }, + { key: "inquiry", type: "inquiry", title: "预约与咨询", required: true }, + { key: "contact", type: "contact", title: "品牌表达", required: true }, + ], + capabilities: ["offerings", "inquiry", "booking"], }, -}; +} satisfies Record; + +export function isBrandTemplateKey(value: string): value is BrandTemplateKey { + return Object.prototype.hasOwnProperty.call(brandTemplates, value); +} + +export function getBrandTemplate(key: string): BrandTemplateDefinition | undefined { + return isBrandTemplateKey(key) ? brandTemplates[key] : undefined; +}