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

@@ -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) => ({