feat: 按视觉模板 manifest 驱动小程序运行时
This commit is contained in:
1 parent
031c81a7c1
commit
ce958fc1ae
17 files changed
+149
-26
No files matched your search
@@ -5,6 +5,7 @@ import { PublicBrandContextService } from "./public-brand-context.service.js";
|
||||
import {
|
||||
getBrandTemplate,
|
||||
getVisualTemplate,
|
||||
getVisualTemplateManifest,
|
||||
resolveCapabilities,
|
||||
capabilityPlugins,
|
||||
} from "@personal-brand/config";
|
||||
@@ -98,6 +99,9 @@ export class PublicWorkspaceController {
|
||||
: "linjing-editorial";
|
||||
const visualTemplate =
|
||||
getVisualTemplate(visualTemplateKey) ?? getVisualTemplate("linjing-editorial");
|
||||
const visualTemplateManifest =
|
||||
getVisualTemplateManifest(visualTemplateKey) ??
|
||||
getVisualTemplateManifest("linjing-editorial");
|
||||
const runtimeBrand = {
|
||||
...(brand ?? {}),
|
||||
...brandConfig,
|
||||
@@ -223,6 +227,7 @@ export class PublicWorkspaceController {
|
||||
variants: visualTemplate.variants,
|
||||
}
|
||||
: null,
|
||||
visualTemplateManifest,
|
||||
capabilities: runtimeCapabilities,
|
||||
runtimeCapabilities,
|
||||
modules,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { BadRequestException, Injectable } from "@nestjs/common";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { getBrandTemplate } from "@personal-brand/config";
|
||||
import { getBrandTemplate, getVisualTemplateManifest } from "@personal-brand/config";
|
||||
import { PrismaService } from "./prisma.service.js";
|
||||
|
||||
@Injectable()
|
||||
@@ -9,20 +9,42 @@ export class TemplateWorkspaceService {
|
||||
async install(brandId: string, templateKey: "personal" | "food" | "doors") {
|
||||
const template = getBrandTemplate(templateKey);
|
||||
if (!template) throw new BadRequestException("行业模板不存在");
|
||||
const existing = await this.prisma.brandTemplateInstallation.findFirst({ where: { brandId } });
|
||||
const [existing, brand] = await Promise.all([
|
||||
this.prisma.brandTemplateInstallation.findFirst({ where: { brandId } }),
|
||||
this.prisma.brandProfile.findUnique({ where: { id: brandId }, select: { config: true } }),
|
||||
]);
|
||||
if (existing)
|
||||
throw new BadRequestException(
|
||||
existing.templateKey === templateKey
|
||||
? "该模板已经安装"
|
||||
: "品牌已经安装主模板,请先完成模板切换流程",
|
||||
);
|
||||
const brandConfig =
|
||||
brand?.config && typeof brand.config === "object" && !Array.isArray(brand.config)
|
||||
? (brand.config as Record<string, unknown>)
|
||||
: {};
|
||||
const visualTemplateKey =
|
||||
typeof brandConfig.visualTemplateKey === "string"
|
||||
? brandConfig.visualTemplateKey
|
||||
: templateKey === "doors"
|
||||
? "linjing-editorial"
|
||||
: "minimal-neutral";
|
||||
const visualManifest = getVisualTemplateManifest(visualTemplateKey);
|
||||
if (!visualManifest) throw new BadRequestException("视觉模板不存在");
|
||||
const templatePackageSnapshot = {
|
||||
schemaVersion: "1.0",
|
||||
version: template.version,
|
||||
industryTemplate: template,
|
||||
visualTemplate: visualManifest,
|
||||
capabilities: template.capabilities,
|
||||
};
|
||||
return this.prisma.$transaction(async (tx) => {
|
||||
const installation = await tx.brandTemplateInstallation.create({
|
||||
data: {
|
||||
brandId,
|
||||
templateKey,
|
||||
templateVersion: template.version,
|
||||
configSnapshot: template as unknown as Prisma.InputJsonValue,
|
||||
configSnapshot: templatePackageSnapshot as unknown as Prisma.InputJsonValue,
|
||||
},
|
||||
});
|
||||
await tx.brandModule.createMany({
|
||||
@@ -46,7 +68,7 @@ export class TemplateWorkspaceService {
|
||||
required,
|
||||
})),
|
||||
});
|
||||
return { installation, template };
|
||||
return { installation, template, visualTemplate: visualManifest };
|
||||
});
|
||||
}
|
||||
private async installation(brandId: string) {
|
||||
|
||||
Reference in new issue
Block a user