feat: 完善模板驱动的品牌内容工作台
This commit is contained in:
1 parent
77224ea51f
commit
dd55af8d73
46 files changed
+2204
-295
No files matched your search
@@ -10,6 +10,7 @@ import {
|
||||
getVisualTemplate,
|
||||
isVisualTemplateCompatible,
|
||||
getDefaultVisualTemplateKey,
|
||||
getTemplatePackageManifestForVisualKey,
|
||||
} from "@personal-brand/config";
|
||||
import { PrismaService } from "./prisma.service.js";
|
||||
import { BrandReleaseService } from "./brand-release.service.js";
|
||||
@@ -44,7 +45,13 @@ export class BrandReleaseApiService {
|
||||
database: Prisma.TransactionClient = this.prisma,
|
||||
): Promise<{
|
||||
ready: boolean;
|
||||
checks: Array<{ key: string; label: string; passed: boolean }>;
|
||||
checks: Array<{
|
||||
key: string;
|
||||
label: string;
|
||||
passed: boolean;
|
||||
help?: string;
|
||||
destination?: string;
|
||||
}>;
|
||||
}> {
|
||||
const brand = await database.brandProfile.findUnique({
|
||||
where: { id: brandId },
|
||||
@@ -61,8 +68,12 @@ export class BrandReleaseApiService {
|
||||
? config.visualTemplateKey
|
||||
: getDefaultVisualTemplateKey(brand?.templateKey ?? "personal");
|
||||
const visual = getVisualTemplate(visualKey);
|
||||
const packageManifest = getTemplatePackageManifestForVisualKey(visualKey);
|
||||
const [offerings, forms, trust] = await Promise.all([
|
||||
database.offering.findMany({ where: { brandId, isEnabled: true }, select: { id: true } }),
|
||||
database.offering.findMany({
|
||||
where: { brandId, isEnabled: true },
|
||||
select: { id: true, name: true, coverUrl: true, config: true },
|
||||
}),
|
||||
database.inquiryForm.findMany({
|
||||
where: { brandId, isEnabled: true },
|
||||
select: { offeringId: true, fieldsSnapshot: true },
|
||||
@@ -77,26 +88,115 @@ export class BrandReleaseApiService {
|
||||
form.fieldsSnapshot.length > 0 &&
|
||||
validateFieldSnapshot(form.fieldsSnapshot).length === 0,
|
||||
);
|
||||
const checks = [
|
||||
{ key: "brand", label: "请先完善品牌名称", passed: Boolean(brand?.name.trim()) },
|
||||
const checks: Array<{
|
||||
key: string;
|
||||
label: string;
|
||||
passed: boolean;
|
||||
help?: string;
|
||||
destination?: string;
|
||||
}> = [
|
||||
{
|
||||
key: "brand",
|
||||
label: "请先完善品牌名称",
|
||||
passed: Boolean(brand?.name.trim()),
|
||||
destination: "/admin/brand",
|
||||
},
|
||||
{
|
||||
key: "positioning",
|
||||
label: "请先完善品牌定位和介绍",
|
||||
passed: Boolean(brand?.tagline?.trim() && brand.description?.trim()),
|
||||
destination: "/admin/brand",
|
||||
},
|
||||
{ key: "template", label: "当前行业模板不存在", passed: Boolean(template) },
|
||||
{
|
||||
key: "visual",
|
||||
label: "当前视觉模板不适配行业模板",
|
||||
passed: Boolean(visual && template && isVisualTemplateCompatible(visual, template.key)),
|
||||
destination: "/admin/publication",
|
||||
},
|
||||
{
|
||||
key: "offerings",
|
||||
label: "至少需要一项已启用的业务提供项",
|
||||
passed: offerings.length > 0,
|
||||
destination: "/admin/services",
|
||||
},
|
||||
{
|
||||
key: "forms",
|
||||
label: "至少需要一个可用的咨询表单",
|
||||
passed: usableForms.length > 0,
|
||||
destination: "/admin/workspace",
|
||||
},
|
||||
{
|
||||
key: "trust",
|
||||
label: "至少需要一条已发布的信任内容",
|
||||
passed: trust > 0,
|
||||
destination: "/admin/trust",
|
||||
},
|
||||
{ key: "offerings", label: "至少需要一项已启用的业务提供项", passed: offerings.length > 0 },
|
||||
{ key: "forms", label: "至少需要一个可用的咨询表单", passed: usableForms.length > 0 },
|
||||
{ key: "trust", label: "至少需要一条已发布的信任内容", passed: trust > 0 },
|
||||
];
|
||||
const brandRecord = { ...this.jsonObject(brand), config };
|
||||
for (const section of packageManifest?.admin.sections ?? []) {
|
||||
for (const field of section.fields) {
|
||||
if (field.required !== true) continue;
|
||||
const present = this.resolveBinding(field.binding, {
|
||||
brand: brandRecord,
|
||||
offerings,
|
||||
});
|
||||
checks.push({
|
||||
key: `content:${section.key}:${field.key}`,
|
||||
label: present
|
||||
? `${section.title}:${field.label}`
|
||||
: `请补充「${section.title}」中的「${field.label}」`,
|
||||
passed: present,
|
||||
help: section.description,
|
||||
destination:
|
||||
section.target === "offering"
|
||||
? "/admin/services"
|
||||
: section.target === "trust"
|
||||
? "/admin/trust"
|
||||
: section.target === "inquiry"
|
||||
? "/admin/workspace"
|
||||
: "/admin/brand",
|
||||
});
|
||||
}
|
||||
}
|
||||
for (const slot of packageManifest?.assetSlots ?? []) {
|
||||
if (slot.required !== true) continue;
|
||||
const present =
|
||||
slot.target === "offering"
|
||||
? offerings.length > 0 && offerings.every((item) => Boolean(item.coverUrl?.trim()))
|
||||
: slot.target === "brand"
|
||||
? this.resolveBinding(slot.binding, { brand: brandRecord, offerings })
|
||||
: trust > 0;
|
||||
checks.push({
|
||||
key: `asset:${String(slot.key)}`,
|
||||
label: present ? `已添加${String(slot.label)}` : `请添加${String(slot.label)}`,
|
||||
passed: present,
|
||||
help: String(slot.help),
|
||||
destination: slot.target === "offering" ? "/admin/services" : "/admin/brand",
|
||||
});
|
||||
}
|
||||
return { ready: checks.every((check) => check.passed), checks };
|
||||
}
|
||||
|
||||
private resolveBinding(
|
||||
binding: string,
|
||||
context: {
|
||||
brand: Record<string, unknown>;
|
||||
offerings: Array<{ id: string; name: string; coverUrl: string | null; config: unknown }>;
|
||||
},
|
||||
): boolean {
|
||||
const segments = binding.split(".");
|
||||
let value: unknown;
|
||||
if (segments[0] === "brand") value = context.brand;
|
||||
else if (segments[0] === "offering") value = context.offerings[0];
|
||||
else return false;
|
||||
for (const segment of segments.slice(1)) {
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
||||
value = (value as Record<string, unknown>)[segment];
|
||||
}
|
||||
return typeof value === "string" ? value.trim().length > 0 : Boolean(value);
|
||||
}
|
||||
|
||||
async publish(brandId: string, actorId: string, note?: string): Promise<unknown> {
|
||||
return this.withVersionRetry(() =>
|
||||
this.prisma.$transaction(
|
||||
|
||||
Reference in new issue
Block a user