fix: 收敛模板编辑发布契约并还原餐饮页面视觉

This commit is contained in:
que01 committed 2026-10-08 13:36:59 +08:00
1 parent 20bcb43534
commit f4061a24bd
102 files changed
+4510 -870

No files matched your search

@@ -80,7 +80,15 @@ export class AdminConfigController {
current?.config && typeof current.config === "object" && !Array.isArray(current.config)
? (current.config as Record<string, unknown>)
: {};
const nextConfig = config ? { ...currentConfig, ...config } : undefined;
const nextConfig = {
...currentConfig,
...(config ?? {}),
// 兼容旧模板:品牌简介的唯一编辑入口是 BrandProfile.description,
// 旧视觉模板仍从 config.slogan 读取,保存时保持两者同步。
...(fields.description !== undefined && config?.slogan === undefined
? { slogan: fields.description }
: {}),
};
if (config?.visualTemplateKey && config.visualTemplateKey !== currentConfig.visualTemplateKey) {
const templateKey = await this.templateWorkspace.getEffectiveTemplateKey(
this.brandId(request),
@@ -121,7 +129,7 @@ export class AdminConfigController {
where: { id: this.brandId(request) },
data: {
...fields,
...(nextConfig ? { config: nextConfig as Prisma.InputJsonValue } : {}),
...(Object.keys(nextConfig).length ? { config: nextConfig } : {}),
},
});
}
@@ -300,34 +308,17 @@ export class AdminConfigController {
@Body() body: CreateTrustContentDto,
): Promise<unknown> {
this.requireAdmin(request);
const { config, ...fields } = body;
return this.prisma.trustContent.create({
data: {
...fields,
brandId: this.brandId(request),
...(config === undefined ? {} : { config: config as Prisma.InputJsonValue }),
},
});
const brandId = this.brandId(request);
return this.templateWorkspace.createTrustContent(brandId, body);
}
@Patch("trust-content/:id")
async updateTrustContent(
updateTrustContent(
@Req() request: FastifyRequest,
@Param("id") id: string,
@Body() body: UpdateTrustContentDto,
): Promise<unknown> {
this.requireAdmin(request);
const item = await this.prisma.trustContent.findFirst({
where: { id, brandId: this.brandId(request) },
});
if (!item) throw new BadRequestException("信任内容不存在");
const { config, ...fields } = body;
return this.prisma.trustContent.update({
where: { id },
data: {
...fields,
...(config === undefined ? {} : { config: config as Prisma.InputJsonValue }),
},
});
return this.templateWorkspace.updateTrustContent(this.brandId(request), id, body);
}
@Delete("trust-content/:id")
async deleteTrustContent(
@@ -18,6 +18,13 @@ import type {
RuntimeTrustItem,
RuntimeWorkspace,
} from "@personal-brand/types";
import {
projectBrandAliases,
projectOfferingDetails,
projectTemplateData,
projectTrustItem,
projectTrustPresentation,
} from "@personal-brand/types";
@Controller("public/workspace")
export class PublicWorkspaceController {
@@ -113,15 +120,19 @@ export class PublicWorkspaceController {
const templatePackageManifest =
releaseSnapshot.templatePackageManifest ??
getTemplatePackageManifestForVisualKey(visualTemplateKey);
const runtimeBrand = {
...brandData,
...brandConfig,
};
// 标准 BrandProfile 字段优先,兼容旧模板仍使用的 config 字段。
// 这样后台编辑 description/contactPhone 等标准字段后,旧模板也会立即读取新值。
const runtimeBrand = projectBrandAliases(brandData, brandConfig);
const declaredTemplateFields = templatePackageManifest?.templateFields ?? [];
const templateData = projectTemplateData(
brandConfig,
declaredTemplateFields.map((field) => field.key),
);
const runtimeOfferings: RuntimeOffering[] = offeringsData.map((raw) => {
const item = raw;
const config = this.jsonObject(item.config);
const sections = Array.isArray(config.sections) ? config.sections : [];
const details = this.jsonObject(config.details);
const details = projectOfferingDetails(config);
const media = Array.isArray(config.media)
? config.media.flatMap((entry) => {
const value = this.jsonObject(entry);
@@ -139,14 +150,6 @@ export class PublicWorkspaceController {
: [];
})
: [];
const materialsList = Array.isArray(details.materialsList)
? details.materialsList.flatMap((entry) => {
const value = this.jsonObject(entry);
return typeof value.name === "string" && typeof value.spec === "string"
? [{ name: value.name, spec: value.spec }]
: [];
})
: [];
return {
id: this.string(item.id),
name: this.string(item.name),
@@ -187,12 +190,10 @@ export class PublicWorkspaceController {
: [],
media,
details: {
background: typeof details.background === "string" ? details.background : "",
designConcept: typeof details.designConcept === "string" ? details.designConcept : "",
crafts: Array.isArray(details.crafts)
? details.crafts.filter((craft): craft is string => typeof craft === "string")
: [],
materialsList,
background: details.background,
designConcept: details.designConcept,
crafts: details.crafts,
materialsList: details.materialsList,
},
},
sections: sections
@@ -211,18 +212,25 @@ export class PublicWorkspaceController {
if (!field || typeof field !== "object") return [];
const value = field as Record<string, unknown>;
if (typeof value.key !== "string" || typeof value.label !== "string") return [];
const type = [
"text",
"tel",
"number",
"select",
"radio",
"checkbox",
"textarea",
"date",
].includes(this.string(value.type))
? (value.type as RuntimeInquiryField["type"])
: "text";
const sourceType = this.string(value.type);
const type =
sourceType === "phone"
? "tel"
: sourceType === "multi-select"
? "checkbox"
: [
"text",
"tel",
"number",
"select",
"radio",
"checkbox",
"checkbox",
"textarea",
"date",
].includes(sourceType)
? (sourceType as RuntimeInquiryField["type"])
: "text";
const options = Array.isArray(value.options)
? value.options.flatMap((option) => {
if (typeof option === "string") return [{ label: option, value: option }];
@@ -243,28 +251,14 @@ export class PublicWorkspaceController {
},
];
});
const trustPresentation = trustData.reduce<Record<string, unknown>>((result, raw) => {
const item = this.jsonObject(raw);
const config = this.jsonObject(item.config);
for (const [key, value] of Object.entries(config)) {
if (!(key in result)) result[key] = value;
}
if (item.type === "profile" && typeof result.bio !== "string") result.bio = item.content;
return result;
}, {});
const trustDeclarations = templatePackageManifest?.trustContentTypes ?? [];
const trustItems: RuntimeTrustItem[] = trustData.flatMap((raw) => {
const item = this.jsonObject(raw);
if (typeof item.type !== "string" || typeof item.title !== "string") return [];
return [
{
type: item.type,
title: item.title,
summary: typeof item.summary === "string" ? item.summary : null,
content: typeof item.content === "string" ? item.content : "",
config: this.jsonObject(item.config),
},
];
const item = projectTrustItem(this.jsonObject(raw));
return item && trustDeclarations.some((declaration) => declaration.type === item.type)
? [item]
: [];
});
const trustPresentation = projectTrustPresentation(trustItems, trustDeclarations);
const runtimeWorkspace: RuntimeWorkspace = {
schemaVersion: "1.0.0",
publication: {
@@ -273,6 +267,7 @@ export class PublicWorkspaceController {
publishedAt: release.createdAt.toISOString(),
},
brand: runtimeBrand,
templateData,
navigation: {
tabs:
templatePackageManifest?.navigation.map((tab) => ({