diff --git a/apps/api/prisma/seed.ts b/apps/api/prisma/seed.ts index a7d1239..8d86828 100644 --- a/apps/api/prisma/seed.ts +++ b/apps/api/prisma/seed.ts @@ -1,6 +1,7 @@ import { PrismaClient } from "@prisma/client"; import bcrypt from "bcryptjs"; import { buildBrandReleaseSnapshot } from "../src/brand-release.service.js"; +import { getTemplateSampleContent } from "@personal-brand/config"; const prisma = new PrismaClient(); @@ -24,6 +25,7 @@ const runtimeImages = { type OfferingKind = "service" | "product" | "package" | "subscription"; interface RuntimeSeedTemplate { + templateKey: "personal" | "food" | "doors"; brandConfig: Record; retiredOfferingNames?: string[]; offerings: Array<{ @@ -46,6 +48,7 @@ interface RuntimeSeedTemplate { const runtimeSeedTemplates: Record<"personal" | "food" | "doors", RuntimeSeedTemplate> = { personal: { + templateKey: "personal", brandConfig: { visualTemplateKey: "linjing-editorial", founder: "林然", @@ -161,6 +164,7 @@ const runtimeSeedTemplates: Record<"personal" | "food" | "doors", RuntimeSeedTem }, }, food: { + templateKey: "food", brandConfig: { visualTemplateKey: "acheng-campus-food", founder: "阿成", @@ -285,6 +289,7 @@ const runtimeSeedTemplates: Record<"personal" | "food" | "doors", RuntimeSeedTem }, }, doors: { + templateKey: "doors", retiredOfferingNames: ["别墅入户大门", "院门与围合系统", "室内户内门系统"], brandConfig: { visualTemplateKey: "linjing-editorial", @@ -590,11 +595,11 @@ const runtimeSeedTemplates: Record<"personal" | "food" | "doors", RuntimeSeedTem type: "select", required: true, options: [ - "入户大门(防暴铸铜 / 实木)", - "庭院围墙门(耐候格栅 / 对开)", - "全屋室内门系统(通顶隐形)", - "背景墙一体门 / 密室门", - "整栋别墅门系统全案一体化", + { label: "入户大门(防暴铸铜 / 实木)", value: "entry" }, + { label: "庭院围墙门(耐候格栅 / 对开)", value: "yard" }, + { label: "全屋室内门系统(通顶隐形)", value: "interior" }, + { label: "背景墙一体门 / 密室门", value: "wall" }, + { label: "整栋别墅门系统全案一体化", value: "whole-home" }, ], }, { key: "cityArea", label: "房屋 / 别墅所在城市与楼盘", type: "text", required: true }, @@ -604,10 +609,10 @@ const runtimeSeedTemplates: Record<"personal" | "food" | "doors", RuntimeSeedTem type: "radio", required: true, options: [ - "土建结构阶段(适合预埋加固)", - "水电木工阶段(适合精确测距)", - "硬装收尾阶段", - "旧宅门体翻新改造", + { label: "土建结构阶段(适合预埋加固)", value: "structure" }, + { label: "水电木工阶段(适合精确测距)", value: "rough-in" }, + { label: "硬装收尾阶段", value: "finishing" }, + { label: "旧宅门体翻新改造", value: "renovation" }, ], }, { @@ -616,10 +621,10 @@ const runtimeSeedTemplates: Record<"personal" | "food" | "doors", RuntimeSeedTem type: "select", required: false, options: [ - "5 万 - 10 万", - "10 万 - 20 万", - "20 万 - 50 万(全宅全案)", - "50 万以上(顶级孤品定制)", + { label: "5 万 - 10 万", value: "50k-100k" }, + { label: "10 万 - 20 万", value: "100k-200k" }, + { label: "20 万 - 50 万(全宅全案)", value: "200k-500k" }, + { label: "50 万以上(顶级孤品定制)", value: "500k-plus" }, ], }, { @@ -627,7 +632,10 @@ const runtimeSeedTemplates: Record<"personal" | "food" | "doors", RuntimeSeedTem label: "是否需要主理人上门现场量房", type: "radio", required: true, - options: ["需要(预约排期现场勘测)", "暂不需要(先发图纸在线深化评估)"], + options: [ + { label: "需要(预约排期现场勘测)", value: "yes" }, + { label: "暂不需要(先发图纸在线深化评估)", value: "no" }, + ], }, { key: "contactName", label: "贵姓称谓", type: "text", required: true }, { key: "contactPhone", label: "联系手机号(微信同号)", type: "tel", required: true }, @@ -723,12 +731,14 @@ async function ensureRuntimeContent(brandId: string, template: RuntimeSeedTempla where: { brandId, targetType: "brand" }, orderBy: { createdAt: "asc" }, }); + const packageSample = getTemplateSampleContent(template.templateKey); const formData = { name: template.inquiryForm.name, purpose: "inquiry", targetType: "brand", submissionAction: "create-inquiry", - fieldsSnapshot: template.inquiryForm.fieldsSnapshot, + fieldsSnapshot: (packageSample?.fields ?? + template.inquiryForm.fieldsSnapshot) as Prisma.InputJsonValue, isEnabled: true, } as const; if (existingForm) diff --git a/docs/adr/0014-template-admin-content-contract.md b/docs/adr/0014-template-admin-content-contract.md index cb671eb..3bb9d17 100644 --- a/docs/adr/0014-template-admin-content-contract.md +++ b/docs/adr/0014-template-admin-content-contract.md @@ -11,6 +11,7 @@ - `dataSlots`:运行时和发布检查需要的稳定业务数据集合; - `assetSlots`:图片和媒体的业务名称、用途、必填性与推荐比例; - `admin.sections`:品牌管理员看到的编辑分组、字段文案、帮助、输入类型与内部绑定。 +- `sampleContent`:安装模板时可选择导入的品牌示例业务内容,包括提供项、信任内容和咨询字段。 模板 package 是页面结构、视觉、交互和内容编辑说明的唯一来源。后端负责校验、品牌隔离、快照与稳定数据投影;Admin 读取声明并渲染业务化表单。`binding`、renderer、capability、schema 等技术信息不会展示给品牌管理员。 @@ -25,6 +26,7 @@ - 新模板必须同时交付页面代码、内容契约、媒体要求和业务化编辑文案。 - RuntimeWorkspace、发布检查和 Admin 需要在后续任务消费同一契约。 - 包内 manifest 的版本变更将进入发布快照,保证已发布品牌的展示可追溯。 +- 模板示例内容随 package 版本管理,不进入后端 `seed.ts`;导入后复制为品牌自己的草稿数据。 ## Migration Plan @@ -32,3 +34,4 @@ 2. 将契约投影到 RuntimeWorkspace 和发布快照。 3. 发布前按必填槽位输出可行动提示。 4. 用声明驱动品牌管理员工作台,移除硬编码的通用页面表达表单。 +5. 将模板示例内容迁移到 package manifest,seed 仅保留开发环境基础品牌 fixture。 diff --git a/packages/config/src/generated-template-packages.js b/packages/config/src/generated-template-packages.js index bcca46b..07845c6 100644 --- a/packages/config/src/generated-template-packages.js +++ b/packages/config/src/generated-template-packages.js @@ -289,6 +289,58 @@ export const generatedTemplatePackageRegistry = [ } ] }, + "sampleContent": { + "food": { + "templateKey": "food", + "offerings": [ + { + "kind": "package", + "name": "示例·今日套餐", + "summary": "现做家常套餐示例内容。", + "categoryKey": "set-meal" + }, + { + "kind": "service", + "name": "示例·聚餐定制", + "summary": "按人数和口味沟通定制餐品。", + "categoryKey": "private-chef" + } + ], + "trustContent": [ + { + "type": "profile", + "title": "关于主理人", + "content": "示例内容,待品牌主理人完善。" + }, + { + "type": "process", + "title": "从预订到取餐", + "content": "示例内容,待品牌主理人完善。" + } + ], + "fields": [ + { + "key": "date", + "label": "用餐日期", + "type": "date", + "required": true + }, + { + "key": "number", + "label": "用餐人数", + "type": "number", + "required": true + }, + { + "key": "phone", + "label": "联系方式", + "type": "phone", + "required": true + } + ], + "capabilityKey": "booking" + } + }, "renderers": { "home": "acheng-home", "offerings": "acheng-offerings", @@ -592,6 +644,228 @@ export const generatedTemplatePackageRegistry = [ } ] }, + "sampleContent": { + "doors": { + "templateKey": "doors", + "offerings": [ + { + "kind": "product", + "name": "序章·入户门", + "summary": "为别墅入口定制的整樘门系统", + "categoryKey": "entrance-door" + }, + { + "kind": "product", + "name": "庭院·边界门", + "summary": "连接建筑与庭院的定制门", + "categoryKey": "garden-door" + }, + { + "kind": "product", + "name": "室内·静谧门", + "summary": "统一室内空间秩序的户内门", + "categoryKey": "interior-door" + }, + { + "kind": "service", + "name": "一对一门系统设计咨询", + "summary": "从现场到方案的完整设计沟通", + "categoryKey": "custom" + } + ], + "trustContent": [ + { + "type": "profile", + "title": "主理人的门作观", + "content": "示例内容,待品牌主理人完善。" + }, + { + "type": "portfolio", + "title": "别墅门系统案例", + "content": "示例内容,待品牌主理人完善。" + }, + { + "type": "process", + "title": "从测量到交付", + "content": "示例内容,待品牌主理人完善。" + }, + { + "type": "credential", + "title": "材料与工艺标准", + "content": "示例内容,待品牌主理人完善。" + } + ], + "fields": [ + { + "key": "doorType", + "label": "期望定制的门类型", + "type": "select", + "required": true, + "options": [ + { + "label": "入户大门(防暴铸铜 / 实木)", + "value": "入户大门(防暴铸铜 / 实木)" + }, + { + "label": "庭院围墙门(耐候格栅 / 对开)", + "value": "庭院围墙门(耐候格栅 / 对开)" + }, + { + "label": "全屋室内门系统(通顶隐形)", + "value": "全屋室内门系统(通顶隐形)" + }, + { + "label": "背景墙一体门 / 密室门", + "value": "背景墙一体门 / 密室门" + }, + { + "label": "整栋别墅门系统全案一体化", + "value": "整栋别墅门系统全案一体化" + } + ] + }, + { + "key": "cityArea", + "label": "房屋 / 别墅所在城市与楼盘", + "type": "text", + "required": true + }, + { + "key": "projectStage", + "label": "项目阶段", + "type": "select", + "required": true, + "options": [ + { + "label": "土建结构阶段(适合预埋加固)", + "value": "土建结构阶段(适合预埋加固)" + }, + { + "label": "水电木工阶段(适合精确测距)", + "value": "水电木工阶段(适合精确测距)" + }, + { + "label": "硬装收尾阶段", + "value": "硬装收尾阶段" + }, + { + "label": "旧宅门体翻新改造", + "value": "旧宅门体翻新改造" + } + ] + }, + { + "key": "budgetRange", + "label": "预估门系统投资预算", + "type": "select", + "required": false, + "options": [ + { + "label": "5 万 - 10 万", + "value": "5 万 - 10 万" + }, + { + "label": "10 万 - 20 万", + "value": "10 万 - 20 万" + }, + { + "label": "20 万 - 50 万(全宅全案)", + "value": "20 万 - 50 万(全宅全案)" + }, + { + "label": "50 万以上(顶级孤品定制)", + "value": "50 万以上(顶级孤品定制)" + } + ] + }, + { + "key": "needMeasure", + "label": "是否需要主理人上门现场量房", + "type": "radio", + "required": true, + "options": [ + { + "label": "需要(预约排期现场勘测)", + "value": "需要(预约排期现场勘测)" + }, + { + "label": "暂不需要(先发图纸在线深化评估)", + "value": "暂不需要(先发图纸在线深化评估)" + } + ] + }, + { + "key": "contactName", + "label": "贵姓称谓", + "type": "text", + "required": true + }, + { + "key": "contactPhone", + "label": "联系手机号(微信同号)", + "type": "tel", + "required": true + }, + { + "key": "specialNote", + "label": "空间想法或特殊需求描述", + "type": "textarea", + "required": false + } + ], + "capabilityKey": "doors" + }, + "personal": { + "templateKey": "personal", + "offerings": [ + { + "kind": "service", + "name": "示例·品牌定位咨询", + "summary": "梳理品牌定位与下一步行动。", + "categoryKey": "consulting" + }, + { + "kind": "service", + "name": "示例·长期顾问支持", + "summary": "围绕表达和转化提供持续支持。", + "categoryKey": "advisory" + } + ], + "trustContent": [ + { + "type": "profile", + "title": "关于主理人", + "content": "示例内容,待品牌主理人完善。" + }, + { + "type": "process", + "title": "合作方法", + "content": "示例内容,待品牌主理人完善。" + } + ], + "fields": [ + { + "key": "name", + "label": "您的称呼", + "type": "text", + "required": true + }, + { + "key": "phone", + "label": "联系方式", + "type": "phone", + "required": true + }, + { + "key": "remark", + "label": "合作需求", + "type": "textarea", + "required": true + } + ], + "capabilityKey": "inquiry" + } + }, "renderers": { "home": "linjing-home", "offerings": "linjing-offerings", @@ -612,4 +886,4 @@ export const generatedTemplatePackageRegistry = [ } ]; export const generatedTemplatePackageRegistryHash = - "ff79864f3873fe627710c092622abd26212a8c25ab52c422ee4e22e95f4d2d73"; + "6d56212ec96d9b7b99a9e12aa278ca0927dc5e4472ec6ece3098a7d99842897b"; diff --git a/packages/config/src/index.ts b/packages/config/src/index.ts index 47a85b7..f9f64b7 100644 --- a/packages/config/src/index.ts +++ b/packages/config/src/index.ts @@ -225,6 +225,7 @@ export interface TemplatePackageManifest { fields: readonly { key: string; binding: string; label: string; required?: boolean }[]; }[]; }; + sampleContent?: Partial>; } export const templatePackageRegistry: readonly TemplatePackageManifest[] = @@ -270,7 +271,13 @@ export interface TemplateSampleContent { categoryKey: string; }>; trustContent: Array<{ type: string; title: string; content: string }>; - fields: Array<{ key: string; label: string; type: string; required: boolean }>; + fields: Array<{ + key: string; + label: string; + type: string; + required: boolean; + options?: Array<{ label: string; value: string }>; + }>; capabilityKey: string; } @@ -380,7 +387,10 @@ export const templateSampleContent: Record + item.supportedIndustryTemplates.includes(templateKey as BrandTemplateKey), + )?.sampleContent?.[templateKey as BrandTemplateKey]; + return packageSample ?? templateSampleContent[templateKey as keyof typeof templateSampleContent]; } const linjingEditorialManifest: VisualTemplateManifest = { diff --git a/packages/template-acheng-campus-food/template.json b/packages/template-acheng-campus-food/template.json index 00a097b..5a6a152 100644 --- a/packages/template-acheng-campus-food/template.json +++ b/packages/template-acheng-campus-food/template.json @@ -281,6 +281,35 @@ } ] }, + "sampleContent": { + "food": { + "templateKey": "food", + "offerings": [ + { + "kind": "package", + "name": "示例·今日套餐", + "summary": "现做家常套餐示例内容。", + "categoryKey": "set-meal" + }, + { + "kind": "service", + "name": "示例·聚餐定制", + "summary": "按人数和口味沟通定制餐品。", + "categoryKey": "private-chef" + } + ], + "trustContent": [ + { "type": "profile", "title": "关于主理人", "content": "示例内容,待品牌主理人完善。" }, + { "type": "process", "title": "从预订到取餐", "content": "示例内容,待品牌主理人完善。" } + ], + "fields": [ + { "key": "date", "label": "用餐日期", "type": "date", "required": true }, + { "key": "number", "label": "用餐人数", "type": "number", "required": true }, + { "key": "phone", "label": "联系方式", "type": "phone", "required": true } + ], + "capabilityKey": "booking" + } + }, "renderers": { "home": "acheng-home", "offerings": "acheng-offerings", diff --git a/packages/template-contract/src/index.ts b/packages/template-contract/src/index.ts index f90dec7..1bbad6d 100644 --- a/packages/template-contract/src/index.ts +++ b/packages/template-contract/src/index.ts @@ -60,6 +60,14 @@ export type TemplateAdminManifest = { sections: TemplateAdminSection[]; }; +export type TemplateSampleContent = { + templateKey: string; + offerings: Array>; + trustContent: Array>; + fields: Array>; + capabilityKey: string; +}; + export type TemplatePackageManifest = { packageKey: string; version: string; @@ -81,6 +89,7 @@ export type TemplatePackageManifest = { dataSlots: TemplateDataSlot[]; assetSlots: TemplateAssetSlot[]; admin: TemplateAdminManifest; + sampleContent?: Record; }; export function validateTemplatePackageManifest(value: unknown): string[] { @@ -149,5 +158,25 @@ export function validateTemplatePackageManifest(value: unknown): string[] { if (!manifest.entrypoints || typeof manifest.entrypoints[page] !== "string") errors.push(`entrypoints.${page} is required`); } + if (manifest.sampleContent !== undefined) { + for (const [industryKey, sample] of Object.entries(manifest.sampleContent)) { + if (!manifest.supportedIndustryTemplates.includes(industryKey)) + errors.push(`sampleContent.${industryKey} is not a supported industry template`); + if (sample.templateKey !== industryKey) + errors.push(`sampleContent.${industryKey}.templateKey must match its key`); + if (!Array.isArray(sample.offerings) || !Array.isArray(sample.trustContent)) + errors.push(`sampleContent.${industryKey} requires offerings and trustContent arrays`); + if (!Array.isArray(sample.fields) || !sample.fields.length) + errors.push(`sampleContent.${industryKey} requires fields`); + for (const field of sample.fields ?? []) { + if (typeof field.key !== "string" || typeof field.label !== "string") + errors.push(`sampleContent.${industryKey} fields require key and label`); + if (["select", "radio", "multi-select"].includes(String(field.type))) { + if (!Array.isArray(field.options) || !field.options.length) + errors.push(`sampleContent.${industryKey}.${String(field.key)} requires options`); + } + } + } + } return errors; } diff --git a/packages/template-linjing-editorial/template.json b/packages/template-linjing-editorial/template.json index ff5995f..53e822e 100644 --- a/packages/template-linjing-editorial/template.json +++ b/packages/template-linjing-editorial/template.json @@ -269,6 +269,150 @@ } ] }, + "sampleContent": { + "doors": { + "templateKey": "doors", + "offerings": [ + { + "kind": "product", + "name": "序章·入户门", + "summary": "为别墅入口定制的整樘门系统", + "categoryKey": "entrance-door" + }, + { + "kind": "product", + "name": "庭院·边界门", + "summary": "连接建筑与庭院的定制门", + "categoryKey": "garden-door" + }, + { + "kind": "product", + "name": "室内·静谧门", + "summary": "统一室内空间秩序的户内门", + "categoryKey": "interior-door" + }, + { + "kind": "service", + "name": "一对一门系统设计咨询", + "summary": "从现场到方案的完整设计沟通", + "categoryKey": "custom" + } + ], + "trustContent": [ + { "type": "profile", "title": "主理人的门作观", "content": "示例内容,待品牌主理人完善。" }, + { + "type": "portfolio", + "title": "别墅门系统案例", + "content": "示例内容,待品牌主理人完善。" + }, + { "type": "process", "title": "从测量到交付", "content": "示例内容,待品牌主理人完善。" }, + { + "type": "credential", + "title": "材料与工艺标准", + "content": "示例内容,待品牌主理人完善。" + } + ], + "fields": [ + { + "key": "doorType", + "label": "期望定制的门类型", + "type": "select", + "required": true, + "options": [ + { "label": "入户大门(防暴铸铜 / 实木)", "value": "入户大门(防暴铸铜 / 实木)" }, + { "label": "庭院围墙门(耐候格栅 / 对开)", "value": "庭院围墙门(耐候格栅 / 对开)" }, + { "label": "全屋室内门系统(通顶隐形)", "value": "全屋室内门系统(通顶隐形)" }, + { "label": "背景墙一体门 / 密室门", "value": "背景墙一体门 / 密室门" }, + { "label": "整栋别墅门系统全案一体化", "value": "整栋别墅门系统全案一体化" } + ] + }, + { + "key": "cityArea", + "label": "房屋 / 别墅所在城市与楼盘", + "type": "text", + "required": true + }, + { + "key": "projectStage", + "label": "项目阶段", + "type": "select", + "required": true, + "options": [ + { "label": "土建结构阶段(适合预埋加固)", "value": "土建结构阶段(适合预埋加固)" }, + { "label": "水电木工阶段(适合精确测距)", "value": "水电木工阶段(适合精确测距)" }, + { "label": "硬装收尾阶段", "value": "硬装收尾阶段" }, + { "label": "旧宅门体翻新改造", "value": "旧宅门体翻新改造" } + ] + }, + { + "key": "budgetRange", + "label": "预估门系统投资预算", + "type": "select", + "required": false, + "options": [ + { "label": "5 万 - 10 万", "value": "5 万 - 10 万" }, + { "label": "10 万 - 20 万", "value": "10 万 - 20 万" }, + { "label": "20 万 - 50 万(全宅全案)", "value": "20 万 - 50 万(全宅全案)" }, + { "label": "50 万以上(顶级孤品定制)", "value": "50 万以上(顶级孤品定制)" } + ] + }, + { + "key": "needMeasure", + "label": "是否需要主理人上门现场量房", + "type": "radio", + "required": true, + "options": [ + { "label": "需要(预约排期现场勘测)", "value": "需要(预约排期现场勘测)" }, + { + "label": "暂不需要(先发图纸在线深化评估)", + "value": "暂不需要(先发图纸在线深化评估)" + } + ] + }, + { "key": "contactName", "label": "贵姓称谓", "type": "text", "required": true }, + { + "key": "contactPhone", + "label": "联系手机号(微信同号)", + "type": "tel", + "required": true + }, + { + "key": "specialNote", + "label": "空间想法或特殊需求描述", + "type": "textarea", + "required": false + } + ], + "capabilityKey": "doors" + }, + "personal": { + "templateKey": "personal", + "offerings": [ + { + "kind": "service", + "name": "示例·品牌定位咨询", + "summary": "梳理品牌定位与下一步行动。", + "categoryKey": "consulting" + }, + { + "kind": "service", + "name": "示例·长期顾问支持", + "summary": "围绕表达和转化提供持续支持。", + "categoryKey": "advisory" + } + ], + "trustContent": [ + { "type": "profile", "title": "关于主理人", "content": "示例内容,待品牌主理人完善。" }, + { "type": "process", "title": "合作方法", "content": "示例内容,待品牌主理人完善。" } + ], + "fields": [ + { "key": "name", "label": "您的称呼", "type": "text", "required": true }, + { "key": "phone", "label": "联系方式", "type": "phone", "required": true }, + { "key": "remark", "label": "合作需求", "type": "textarea", "required": true } + ], + "capabilityKey": "inquiry" + } + }, "renderers": { "home": "linjing-home", "offerings": "linjing-offerings",