fix: 收敛模板编辑发布契约并还原餐饮页面视觉
This commit is contained in:
1 parent
20bcb43534
commit
f4061a24bd
102 files changed
+4510
-870
No files matched your search
@@ -45,7 +45,16 @@ export type TemplateAdminField = {
|
||||
binding: string;
|
||||
label: string;
|
||||
help?: string;
|
||||
input: "text" | "textarea" | "phone" | "image" | "number" | "list";
|
||||
input:
|
||||
| "text"
|
||||
| "textarea"
|
||||
| "phone"
|
||||
| "image"
|
||||
| "number"
|
||||
| "boolean"
|
||||
| "select"
|
||||
| "multi-select"
|
||||
| "list";
|
||||
itemFields?: Array<{
|
||||
key: string;
|
||||
label: string;
|
||||
@@ -56,6 +65,14 @@ export type TemplateAdminField = {
|
||||
required?: boolean;
|
||||
maxLength?: number;
|
||||
placeholder?: string;
|
||||
options?: Array<{ value: string; label: string }>;
|
||||
};
|
||||
|
||||
/** 模板自己的浅层品牌字段,值存于 BrandProfile.config.templateData。 */
|
||||
export type TemplateField = Omit<TemplateAdminField, "binding"> & {
|
||||
key: string;
|
||||
page?: TemplatePageKey;
|
||||
binding?: `brand.config.templateData.${string}`;
|
||||
};
|
||||
|
||||
/** 一个面向业务用户的编辑分组,而不是技术 schema 或 JSON 编辑器。 */
|
||||
@@ -63,6 +80,8 @@ export type TemplateAdminSection = {
|
||||
key: string;
|
||||
title: string;
|
||||
description: string;
|
||||
/** Exact Mini Program page that displays this section's content. */
|
||||
page: TemplatePageKey;
|
||||
target: "brand" | "offering" | "trust" | "inquiry";
|
||||
fields: TemplateAdminField[];
|
||||
};
|
||||
@@ -74,14 +93,26 @@ export type TemplateAdminManifest = {
|
||||
export type TemplateTrustContentType = {
|
||||
type: "schedule" | "coverage" | "process" | "credential" | "case" | "promise" | (string & {});
|
||||
label: string;
|
||||
/** Labels for the persisted TrustContent columns edited in Admin. */
|
||||
adminFields: {
|
||||
title: string;
|
||||
summary: string;
|
||||
content: string;
|
||||
summaryHelp?: string;
|
||||
summaryPlaceholder?: string;
|
||||
};
|
||||
pages?: TemplatePageKey[];
|
||||
help?: string;
|
||||
placeholder?: string;
|
||||
required?: boolean;
|
||||
configFields?: TemplateAdminField[];
|
||||
maxPublishedItems?: number;
|
||||
hideStandardFields?: Array<"summary" | "content">;
|
||||
};
|
||||
|
||||
export type TemplateSampleContent = {
|
||||
templateKey: string;
|
||||
inquiryFormName: string;
|
||||
offerings: Array<Record<string, unknown>>;
|
||||
trustContent: Array<Record<string, unknown>>;
|
||||
fields: Array<Record<string, unknown>>;
|
||||
@@ -110,6 +141,7 @@ export type TemplatePackageManifest = {
|
||||
/** 开发时的默认品牌;构建参数 `--brand` 优先。 */
|
||||
defaultBrandSlug?: string;
|
||||
dataSlots: TemplateDataSlot[];
|
||||
templateFields?: TemplateField[];
|
||||
assetSlots: TemplateAssetSlot[];
|
||||
admin: TemplateAdminManifest;
|
||||
trustContentTypes?: TemplateTrustContentType[];
|
||||
@@ -142,6 +174,14 @@ export function validateTemplatePackageManifest(value: unknown): string[] {
|
||||
errors.push("data slot source is invalid");
|
||||
}
|
||||
}
|
||||
for (const [index, field] of (manifest.templateFields ?? []).entries()) {
|
||||
if (!field?.key?.trim() || !field?.label?.trim())
|
||||
errors.push(`templateFields.${index} requires key and label`);
|
||||
if (field.binding && !field.binding.startsWith("brand.config.templateData."))
|
||||
errors.push(`templateFields.${index}.binding must target templateData`);
|
||||
if (field.input === "list" && !field.itemFields?.length)
|
||||
errors.push(`templateFields.${index}.list requires itemFields`);
|
||||
}
|
||||
if (manifest.trustContentTypes !== undefined) {
|
||||
if (!Array.isArray(manifest.trustContentTypes))
|
||||
errors.push("trustContentTypes must be an array");
|
||||
@@ -155,6 +195,19 @@ export function validateTemplatePackageManifest(value: unknown): string[] {
|
||||
errors.push(`trustContentTypes.${index}.type is required`);
|
||||
if (typeof item.label !== "string" || !item.label.trim())
|
||||
errors.push(`trustContentTypes.${index}.label is required`);
|
||||
for (const key of ["title", "summary", "content"] as const) {
|
||||
if (typeof item.adminFields?.[key] !== "string" || !item.adminFields[key].trim())
|
||||
errors.push(`trustContentTypes.${index}.adminFields.${key} is required`);
|
||||
}
|
||||
for (const page of item.pages ?? []) {
|
||||
if (!manifest.entrypoints?.[page])
|
||||
errors.push(`trustContentTypes.${index}.pages contains an undeclared entrypoint`);
|
||||
}
|
||||
if (
|
||||
item.maxPublishedItems !== undefined &&
|
||||
(!Number.isInteger(item.maxPublishedItems) || item.maxPublishedItems < 1)
|
||||
)
|
||||
errors.push(`trustContentTypes.${index}.maxPublishedItems must be a positive integer`);
|
||||
for (const field of item.configFields ?? []) {
|
||||
if (!field.key?.trim() || !field.binding?.startsWith("trust.config."))
|
||||
errors.push(`trustContentTypes.${index}.configFields binding is invalid`);
|
||||
@@ -164,6 +217,41 @@ export function validateTemplatePackageManifest(value: unknown): string[] {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (manifest.sampleContent && typeof manifest.sampleContent === "object") {
|
||||
for (const [industry, sample] of Object.entries(manifest.sampleContent)) {
|
||||
if (!sample.inquiryFormName?.trim())
|
||||
errors.push(`sampleContent.${industry}.inquiryFormName is required`);
|
||||
for (const [index, item] of (sample.trustContent ?? []).entries()) {
|
||||
if (!manifest.trustContentTypes?.some((type) => type.type === item.type))
|
||||
errors.push(
|
||||
`sampleContent.${industry}.trustContent.${index} uses an undeclared trust content type`,
|
||||
);
|
||||
}
|
||||
for (const [index, field] of (sample.fields ?? []).entries()) {
|
||||
if (
|
||||
typeof field.key !== "string" ||
|
||||
!field.key.trim() ||
|
||||
typeof field.label !== "string" ||
|
||||
!field.label.trim()
|
||||
)
|
||||
errors.push(`sampleContent.${industry}.fields.${index} requires key and label`);
|
||||
if (
|
||||
![
|
||||
"text",
|
||||
"tel",
|
||||
"phone",
|
||||
"number",
|
||||
"select",
|
||||
"radio",
|
||||
"multi-select",
|
||||
"textarea",
|
||||
"date",
|
||||
].includes(String(field.type))
|
||||
)
|
||||
errors.push(`sampleContent.${industry}.fields.${index} has an unsupported Runtime type`);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!Array.isArray(manifest.assetSlots)) errors.push("assetSlots must be an array");
|
||||
else {
|
||||
for (const slot of manifest.assetSlots) {
|
||||
@@ -177,6 +265,10 @@ export function validateTemplatePackageManifest(value: unknown): string[] {
|
||||
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 (!section?.page?.trim() || !manifest.entrypoints?.[section.page])
|
||||
errors.push(
|
||||
`admin section ${section?.key ?? "<unknown>"} must target a declared entrypoint`,
|
||||
);
|
||||
if (!Array.isArray(section.fields) || !section.fields.length)
|
||||
errors.push("every admin section must contain fields");
|
||||
for (const field of section.fields ?? []) {
|
||||
|
||||
Reference in new issue
Block a user