feat: 完善模板驱动的品牌内容工作台
This commit is contained in:
1 parent
77224ea51f
commit
dd55af8d73
46 files changed
+2204
-295
No files matched your search
@@ -7,6 +7,59 @@ export type TemplateRenderers = Partial<Record<"home" | "offerings" | "profile",
|
||||
|
||||
export type TemplateRuntimeOwnedPage = "detail" | "inquiry" | "success" | "records";
|
||||
|
||||
/**
|
||||
* 模板向平台声明的内容来源。它只描述稳定的业务事实,不描述页面结构或 renderer。
|
||||
*/
|
||||
export type TemplateContentSource = "brand" | "offering" | "trust" | "inquiry" | "records";
|
||||
|
||||
/** 模板需要的小程序数据集合,用于 Runtime 投影和发布前校验。 */
|
||||
export type TemplateDataSlot = {
|
||||
key: string;
|
||||
source: TemplateContentSource;
|
||||
required: boolean;
|
||||
description: string;
|
||||
};
|
||||
|
||||
/** 图片、标志等媒体需求;label/help 是给品牌管理员看到的业务语言。 */
|
||||
export type TemplateAssetSlot = {
|
||||
key: string;
|
||||
binding: string;
|
||||
target: "brand" | "offering" | "trust";
|
||||
label: string;
|
||||
help: string;
|
||||
required: boolean;
|
||||
kind: "image" | "logo" | "portrait" | "texture";
|
||||
aspectRatio?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* 一个可由普通品牌管理员编辑的字段。
|
||||
* key 是稳定语义标识,binding 是平台内部的存储映射;两者均不直接展示给用户。
|
||||
*/
|
||||
export type TemplateAdminField = {
|
||||
key: string;
|
||||
binding: string;
|
||||
label: string;
|
||||
help?: string;
|
||||
input: "text" | "textarea" | "phone" | "image" | "number";
|
||||
required?: boolean;
|
||||
maxLength?: number;
|
||||
placeholder?: string;
|
||||
};
|
||||
|
||||
/** 一个面向业务用户的编辑分组,而不是技术 schema 或 JSON 编辑器。 */
|
||||
export type TemplateAdminSection = {
|
||||
key: string;
|
||||
title: string;
|
||||
description: string;
|
||||
target: "brand" | "offering" | "trust" | "inquiry";
|
||||
fields: TemplateAdminField[];
|
||||
};
|
||||
|
||||
export type TemplateAdminManifest = {
|
||||
sections: TemplateAdminSection[];
|
||||
};
|
||||
|
||||
export type TemplatePackageManifest = {
|
||||
packageKey: string;
|
||||
version: string;
|
||||
@@ -25,6 +78,9 @@ export type TemplatePackageManifest = {
|
||||
renderers?: TemplateRenderers;
|
||||
runtimeOwnedPages?: TemplateRuntimeOwnedPage[];
|
||||
ownedPaths?: string[];
|
||||
dataSlots: TemplateDataSlot[];
|
||||
assetSlots: TemplateAssetSlot[];
|
||||
admin: TemplateAdminManifest;
|
||||
};
|
||||
|
||||
export function validateTemplatePackageManifest(value: unknown): string[] {
|
||||
@@ -43,6 +99,37 @@ export function validateTemplatePackageManifest(value: unknown): string[] {
|
||||
errors.push("supportedIndustryTemplates must not be empty");
|
||||
if (!Array.isArray(manifest.navigation) || !manifest.navigation.length)
|
||||
errors.push("navigation must not be empty");
|
||||
if (!Array.isArray(manifest.dataSlots) || !manifest.dataSlots.length)
|
||||
errors.push("dataSlots must not be empty");
|
||||
else {
|
||||
for (const slot of manifest.dataSlots) {
|
||||
if (!slot?.key?.trim() || !slot.description?.trim())
|
||||
errors.push("every data slot requires key and description");
|
||||
if (!(["brand", "offering", "trust", "inquiry", "records"] as string[]).includes(slot.source))
|
||||
errors.push("data slot source is invalid");
|
||||
}
|
||||
}
|
||||
if (!Array.isArray(manifest.assetSlots)) errors.push("assetSlots must be an array");
|
||||
else {
|
||||
for (const slot of manifest.assetSlots) {
|
||||
if (!slot?.key?.trim() || !slot.binding?.trim() || !slot.label?.trim() || !slot.help?.trim())
|
||||
errors.push("every asset slot requires key, binding, label and help");
|
||||
}
|
||||
}
|
||||
if (!manifest.admin || !Array.isArray(manifest.admin.sections) || !manifest.admin.sections.length)
|
||||
errors.push("admin.sections must not be empty");
|
||||
else {
|
||||
for (const section of manifest.admin.sections) {
|
||||
if (!section?.key?.trim() || !section.title?.trim() || !section.description?.trim())
|
||||
errors.push("every admin section requires key, title and description");
|
||||
if (!Array.isArray(section.fields) || !section.fields.length)
|
||||
errors.push("every admin section must contain fields");
|
||||
for (const field of section.fields ?? []) {
|
||||
if (!field?.key?.trim() || !field.binding?.trim() || !field.label?.trim())
|
||||
errors.push("every admin field requires key, binding and label");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (manifest.ownedPaths !== undefined && !Array.isArray(manifest.ownedPaths))
|
||||
errors.push("ownedPaths must be an array when provided");
|
||||
if (
|
||||
|
||||
Reference in new issue
Block a user