refactor: 将模板示例内容移入模板包

This commit is contained in:
que01 committed 2026-09-25 08:32:57 +08:00
1 parent dd55af8d73
commit 6218ed395b
7 files changed
+517 -18

No files matched your search

+25 -15
View File
@@ -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<string, unknown>;
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)