From a95150456366fa7ca9a67805b77072691b09a079 Mon Sep 17 00:00:00 2001 From: que01 Date: Tue, 22 Sep 2026 23:33:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8C=81=E4=B9=85=E5=8C=96=E8=A7=86?= =?UTF-8?q?=E8=A7=89=E6=A8=A1=E6=9D=BF=E5=88=87=E6=8D=A2=E5=8E=86=E5=8F=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/api/src/main.ts | 39 +++++++++++++++++++++++++++++++ docs/template-runtime-progress.md | 1 + packages/api-client/src/index.ts | 5 ++++ 3 files changed, 45 insertions(+) diff --git a/apps/api/src/main.ts b/apps/api/src/main.ts index 338b38b..9e5a5ee 100644 --- a/apps/api/src/main.ts +++ b/apps/api/src/main.ts @@ -655,6 +655,28 @@ export class AdminConfigController { ? (current.config as Record) : {}; const nextConfig = config ? { ...currentConfig, ...config } : undefined; + if (config?.visualTemplateKey && config.visualTemplateKey !== currentConfig.visualTemplateKey) { + const installation = await this.prisma.brandTemplateInstallation.findFirst({ + where: { brandId: this.brandId() }, + }); + if (installation) { + const history = Array.isArray(installation.previousSnapshots) + ? installation.previousSnapshots + : []; + await this.prisma.brandTemplateInstallation.update({ + where: { id: installation.id }, + data: { + previousSnapshots: [ + ...history, + { + visualTemplateKey: currentConfig.visualTemplateKey ?? "linjing-editorial", + savedAt: new Date().toISOString(), + }, + ], + }, + }); + } + } return this.prisma.brandProfile.update({ where: { id: this.brandId() }, data: { @@ -663,6 +685,23 @@ export class AdminConfigController { }, }); } + @Get("visual-template/history") + getVisualTemplateHistory(@Req() request: FastifyRequest): unknown { + this.requireAdmin(request); + return this.prisma.brandTemplateInstallation + .findFirst({ where: { brandId: this.brandId() }, select: { previousSnapshots: true } }) + .then((installation) => ({ + history: Array.isArray(installation?.previousSnapshots) + ? installation.previousSnapshots.filter( + (item) => + item && + typeof item === "object" && + !Array.isArray(item) && + "visualTemplateKey" in item, + ) + : [], + })); + } @Get("visual-template/preview") getVisualTemplatePreview(@Req() request: FastifyRequest): unknown { this.requireAdmin(request); diff --git a/docs/template-runtime-progress.md b/docs/template-runtime-progress.md index f5cbe18..1d2be3f 100644 --- a/docs/template-runtime-progress.md +++ b/docs/template-runtime-progress.md @@ -47,6 +47,7 @@ - [x] 集成测试验证视觉模板切换会影响公开 Runtime Workspace 的主题和变体。 - [x] 增加视觉模板预览接口,并在品牌配置更新时合并 config,避免覆盖其他配置。 - [x] 后台视觉模板切换增加确认和差异说明,避免误操作覆盖业务内容。 +- [x] 视觉模板切换记录历史快照,并提供后台历史查询接口。 - [ ] 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 31a10da..0ab6024 100644 --- a/packages/api-client/src/index.ts +++ b/packages/api-client/src/index.ts @@ -378,6 +378,11 @@ export class ApiClient { }> { return this.request("/admin/config/visual-template/preview"); } + getAdminVisualTemplateHistory(): Promise<{ + history: Array<{ visualTemplateKey: string; savedAt: string }>; + }> { + return this.request("/admin/config/visual-template/history"); + } updateAdminBrand(body: BrandUpdate): Promise { return this.request("/admin/config/brand", { method: "PATCH", body }); }