feat: 完成模板管理阶段4闭环

This commit is contained in:
que01 committed 2026-10-17 13:56:19 +08:00
1 parent b1e8012ded
commit d1958a7d7f
26 files changed
+1179 -310

No files matched your search

+25 -19
View File
@@ -643,23 +643,29 @@ const runtimeSeedTemplates: Record<"personal" | "food" | "doors", RuntimeSeedTem
};
async function ensureRuntimeContent(brandId: string, template: RuntimeSeedTemplate): Promise<void> {
// 这里只初始化明确的开发演示品牌;餐饮结构化槽位和表单取自对应 package,
// 这里只初始化明确的开发演示品牌;业务内容统一来自视觉包 sampleContent,
// 新增生产模板无需添加 seed 分支,品牌样例内容仍须由管理员显式导入。
const offerings = template.offerings;
const foodSample =
template.templateKey === "food"
? getTemplatePackageManifestForVisualKey("acheng-campus-food")?.sampleContent?.food
: undefined;
if (template.templateKey === "food" && !foodSample)
throw new Error("Food development sample is missing");
const trustContent = foodSample
? foodSample.trustContent.map((item) => {
const fixture = template.trustContent.find((entry) => entry.type === item.type);
return { ...item, ...fixture, config: { ...item.config, ...fixture?.config } };
})
: template.trustContent;
const inquiryFields = foodSample?.fields ?? template.inquiryForm?.fieldsSnapshot;
const inquiryFormName = foodSample?.inquiryFormName ?? template.inquiryForm?.name;
const visualKey = template.templateKey === "food" ? "acheng-campus-food" : "linjing-editorial";
const packageSample =
getTemplatePackageManifestForVisualKey(visualKey)?.sampleContent?.[template.templateKey];
if (!packageSample)
throw new Error(`Development sample is missing for ${visualKey}/${template.templateKey}`);
const offerings = packageSample.offerings.map((item) => ({
name: item.name,
summary: item.summary,
image: item.coverUrl ?? "",
kind: item.kind as OfferingKind,
priceText: item.priceText,
priceAmount: item.priceAmount,
config: { categoryKey: item.categoryKey, ...(item.config ?? {}) },
}));
const trustContent = packageSample.trustContent;
const inquiryFields = packageSample.fields;
const inquiryFormName = packageSample.inquiryFormName;
const seedBrandConfig = {
...(packageSample.brandConfig ?? {}),
...template.brandConfig,
};
if (!inquiryFields?.length || !inquiryFormName)
throw new Error("Development inquiry fixture is missing");
const existingBrand = await prisma.brandProfile.findUniqueOrThrow({ where: { id: brandId } });
@@ -672,7 +678,7 @@ async function ensureRuntimeContent(brandId: string, template: RuntimeSeedTempla
await prisma.brandProfile.update({
where: { id: brandId },
data: {
config: { ...existingConfig, ...template.brandConfig } as Prisma.InputJsonValue,
config: { ...existingConfig, ...seedBrandConfig } as Prisma.InputJsonValue,
...(existingBrand.slug === "default-brand" && !existingBrand.avatarUrl
? { avatarUrl: "/assets/owner/portrait.jpg" }
: {}),
@@ -710,7 +716,7 @@ async function ensureRuntimeContent(brandId: string, template: RuntimeSeedTempla
select: { id: true, name: true },
});
for (const [index, item] of incompleteOfferings.entries()) {
const image = template.offerings[index % template.offerings.length]?.image;
const image = offerings[index % offerings.length]?.image;
if (!image) throw new Error("Development fixture has no offering image");
await prisma.offering.update({
where: { id: item.id },
@@ -727,7 +733,7 @@ async function ensureRuntimeContent(brandId: string, template: RuntimeSeedTempla
}
for (const [sortOrder, item] of trustContent.entries()) {
const existing = await prisma.trustContent.findFirst({
where: { brandId, type: item.type },
where: { brandId, type: item.type, title: item.title },
orderBy: [{ isPublished: "desc" }, { sortOrder: "asc" }],
});
const { config, ...fields } = item;