From 4810ed7bdeccd91e2856fa5a0cc11ebe684dc098 Mon Sep 17 00:00:00 2001 From: que01 Date: Tue, 22 Sep 2026 23:28:41 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E8=A7=86=E8=A7=89?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E9=A2=84=E8=A7=88=E4=B8=8E=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/api/src/main.ts | 45 +++++++++++++++++++++++++++++-- docs/template-runtime-progress.md | 1 + packages/api-client/src/index.ts | 12 +++++++++ 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/apps/api/src/main.ts b/apps/api/src/main.ts index e49b374..338b38b 100644 --- a/apps/api/src/main.ts +++ b/apps/api/src/main.ts @@ -640,17 +640,58 @@ export class AdminConfigController { return this.prisma.brandProfile.findUnique({ where: { id: this.brandId() } }); } @Patch("brand") - updateBrand(@Req() request: FastifyRequest, @Body() body: UpdateBrandDto): Promise { + async updateBrand( + @Req() request: FastifyRequest, + @Body() body: UpdateBrandDto, + ): Promise { this.requireAdmin(request); const { config, ...fields } = body; + const current = await this.prisma.brandProfile.findUnique({ + where: { id: this.brandId() }, + select: { config: true }, + }); + const currentConfig = + current?.config && typeof current.config === "object" && !Array.isArray(current.config) + ? (current.config as Record) + : {}; + const nextConfig = config ? { ...currentConfig, ...config } : undefined; return this.prisma.brandProfile.update({ where: { id: this.brandId() }, data: { ...fields, - ...(config ? { config: config as Prisma.InputJsonValue } : {}), + ...(nextConfig ? { config: nextConfig as Prisma.InputJsonValue } : {}), }, }); } + @Get("visual-template/preview") + getVisualTemplatePreview(@Req() request: FastifyRequest): unknown { + this.requireAdmin(request); + return this.prisma.brandProfile + .findUnique({ where: { id: this.brandId() }, select: { config: true } }) + .then((brand) => { + const config = + brand?.config && typeof brand.config === "object" && !Array.isArray(brand.config) + ? (brand.config as Record) + : {}; + const currentKey = + typeof config.visualTemplateKey === "string" + ? config.visualTemplateKey + : "linjing-editorial"; + const current = getVisualTemplate(currentKey) ?? getVisualTemplate("linjing-editorial"); + return { + current: current + ? { + key: current.key, + version: current.version, + name: current.name, + theme: current.theme, + variants: current.variants, + } + : null, + available: ["linjing-editorial", "minimal-neutral"], + }; + }); + } @Get("trust-content") listTrustContent(@Req() request: FastifyRequest): Promise { this.requireAdmin(request); diff --git a/docs/template-runtime-progress.md b/docs/template-runtime-progress.md index 089079d..0c6a31e 100644 --- a/docs/template-runtime-progress.md +++ b/docs/template-runtime-progress.md @@ -45,6 +45,7 @@ - [x] Runtime Workspace 合并品牌配置中的视觉模板主题、版本和模块变体。 - [x] Admin 工作空间支持切换视觉模板并保存 `visualTemplateKey`。 - [x] 集成测试验证视觉模板切换会影响公开 Runtime Workspace 的主题和变体。 +- [x] 增加视觉模板预览接口,并在品牌配置更新时合并 config,避免覆盖其他配置。 - [ ] Phase 4:Capability Plugin。 - [ ] Phase 5:林境门作与第二行业双模板验证。 - [ ] Phase 6:Stitch 到 Manifest 的转换流水线。 diff --git a/packages/api-client/src/index.ts b/packages/api-client/src/index.ts index 6f286b4..31a10da 100644 --- a/packages/api-client/src/index.ts +++ b/packages/api-client/src/index.ts @@ -366,6 +366,18 @@ export class ApiClient { getAdminBrand(): Promise { return this.request("/admin/config/brand"); } + getAdminVisualTemplatePreview(): Promise<{ + current: { + key: string; + version: string; + name: string; + theme: unknown; + variants: Record; + } | null; + available: string[]; + }> { + return this.request("/admin/config/visual-template/preview"); + } updateAdminBrand(body: BrandUpdate): Promise { return this.request("/admin/config/brand", { method: "PATCH", body }); }