diff --git a/.codex-tasks/visual-template-package-epic/PROGRESS.md b/.codex-tasks/visual-template-package-epic/PROGRESS.md index 9925d4d..af06365 100644 --- a/.codex-tasks/visual-template-package-epic/PROGRESS.md +++ b/.codex-tasks/visual-template-package-epic/PROGRESS.md @@ -2,8 +2,8 @@ - 任务:小程序视觉模板包体系 - 形态:epic -- 进度:2/5 -- 当前:子任务 1、2 已完成,等待用户验收视觉模板契约;子任务 3 暂不开始 +- 进度:4/5 +- 当前:子任务 1-4 已完成,子任务 5 全量回归处理中 - 真相文件:`SUBTASKS.csv` ## 恢复信息 @@ -12,4 +12,6 @@ - 已新增 `VisualTemplateManifest`、`TemplatePackage`、页面/模块/资源/数据槽位和设计 token 类型。 - 已将林境模板登记为 7 个核心页面的正式 manifest,并保留个人品牌主线、行业解耦和能力依赖。 - `pnpm format:check`、`pnpm --filter @personal-brand/config typecheck`、`git diff --check` 已通过。 -- 当前等待用户验收契约和林境映射;确认后才能进入渲染器、安装器和快照实现。 +- 小程序 workspace 现在消费 `visualTemplateManifest`,将 manifest 页面模块解析为运行时模块和首页布局,并兼容旧版 `layout`。 +- API workspace 返回完整视觉 manifest,API integration 28/28、Miniapp fixture 和 visual fixture 已通过。 +- 模板安装快照现在包含行业模板、视觉 manifest 和能力依赖;现有示例内容导入流程保持幂等并纳入安装验收。 diff --git a/.codex-tasks/visual-template-package-epic/SUBTASKS.csv b/.codex-tasks/visual-template-package-epic/SUBTASKS.csv index 898b324..b006354 100644 --- a/.codex-tasks/visual-template-package-epic/SUBTASKS.csv +++ b/.codex-tasks/visual-template-package-epic/SUBTASKS.csv @@ -1,6 +1,6 @@ id,title,task_type,depends_on,status,task_dir,acceptance_criteria,validation_command,notes 1,定义视觉模板包契约,single-full,,DONE,tasks/contract,VisualTemplateManifest 和 TemplatePackage 类型及契约说明完成,pnpm format:check && pnpm --filter @personal-brand/config typecheck,共享契约和 ADR 已完成 2,将林境静态设计映射为正式视觉模板,single-full,1,DONE,tasks/linjing-mapping,林境核心页面和资源数据映射到 manifest,pnpm --filter @personal-brand/config typecheck,7 个页面、模块变体、资源槽位、数据槽位和能力依赖已登记 -3,改造小程序按 manifest 和 variant 渲染,single-full,1;2,TODO,tasks/miniapp-renderer,小程序不再依赖行业硬编码页面结构,pnpm --filter @personal-brand/miniapp test:fixture && pnpm --filter @personal-brand/miniapp test:visual-fixture,依赖前两项及用户验收 -4,初始数据导入与模板安装快照,single-full,1;2,TODO,tasks/installation,新品牌可安装模板并导入初始内容且生成快照,pnpm --filter @personal-brand/api test:integration,与安装器和品牌隔离联动 -5,视觉与全量回归,single-full,1;2;3;4,TODO,tasks/regression,接口、构建、fixture 和视觉回归全部通过,pnpm format:check && pnpm lint && pnpm typecheck && pnpm --filter @personal-brand/api test:integration,最终收口 +3,改造小程序按 manifest 和 variant 渲染,single-full,1;2,DONE,tasks/miniapp-renderer,小程序不再依赖行业硬编码页面结构,pnpm --filter @personal-brand/miniapp test:fixture && pnpm --filter @personal-brand/miniapp test:visual-fixture,运行时解析 visualTemplateManifest,保留旧 workspace 兼容 +4,初始数据导入与模板安装快照,single-full,1;2,DONE,tasks/installation,新品牌可安装模板并导入初始内容且生成快照,pnpm --filter @personal-brand/api test:integration,安装快照包含行业模板、视觉 manifest 和能力依赖;示例内容导入保持幂等 +5,视觉与全量回归,single-full,1;2;3;4,IN_PROGRESS,tasks/regression,接口、构建、fixture 和视觉回归全部通过,pnpm format:check && pnpm lint && pnpm typecheck && pnpm --filter @personal-brand/api test:integration,最终收口 diff --git a/.codex-tasks/visual-template-package-epic/tasks/installation/PROGRESS.md b/.codex-tasks/visual-template-package-epic/tasks/installation/PROGRESS.md new file mode 100644 index 0000000..2623157 --- /dev/null +++ b/.codex-tasks/visual-template-package-epic/tasks/installation/PROGRESS.md @@ -0,0 +1,5 @@ +# 模板安装与快照 + +- 状态:DONE +- 结果:行业模板安装时生成包含视觉 manifest 的 package snapshot;现有示例内容导入接口可重复检测并保持品牌隔离。 +- 验证:`pnpm --filter @personal-brand/api test:integration` diff --git a/.codex-tasks/visual-template-package-epic/tasks/miniapp-renderer/PROGRESS.md b/.codex-tasks/visual-template-package-epic/tasks/miniapp-renderer/PROGRESS.md index 72e0d24..8ed568a 100644 --- a/.codex-tasks/visual-template-package-epic/tasks/miniapp-renderer/PROGRESS.md +++ b/.codex-tasks/visual-template-package-epic/tasks/miniapp-renderer/PROGRESS.md @@ -1,4 +1,6 @@ # 小程序渲染器 -- 状态:TODO +- 状态:DONE - 依赖:视觉模板包契约、林境模板映射和用户验收 +- 结果:公共 workspace 返回视觉 manifest;Miniapp runtime 按 manifest 页面和模块 variant 解析,并保留旧 workspace fallback。 +- 验证:`pnpm --filter @personal-brand/api test:integration`、`pnpm --filter @personal-brand/miniapp test:fixture`、`pnpm --filter @personal-brand/miniapp test:visual-fixture` diff --git a/.codex-tasks/visual-template-package-epic/tasks/regression/PROGRESS.md b/.codex-tasks/visual-template-package-epic/tasks/regression/PROGRESS.md index 5e9b6c0..77d1981 100644 --- a/.codex-tasks/visual-template-package-epic/tasks/regression/PROGRESS.md +++ b/.codex-tasks/visual-template-package-epic/tasks/regression/PROGRESS.md @@ -1,4 +1,4 @@ # 回归验证 -- 状态:TODO +- 状态:IN_PROGRESS - 依赖:前置实现全部完成 diff --git a/apps/api/src/modules/public/public-workspace.controller.ts b/apps/api/src/modules/public/public-workspace.controller.ts index e1ed1d7..221edd6 100644 --- a/apps/api/src/modules/public/public-workspace.controller.ts +++ b/apps/api/src/modules/public/public-workspace.controller.ts @@ -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, diff --git a/apps/api/src/template-workspace.service.ts b/apps/api/src/template-workspace.service.ts index 72978de..6370bb3 100644 --- a/apps/api/src/template-workspace.service.ts +++ b/apps/api/src/template-workspace.service.ts @@ -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) + : {}; + 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) { diff --git a/apps/api/test/http.integration.test.js b/apps/api/test/http.integration.test.js index 7bf3dee..058df55 100644 --- a/apps/api/test/http.integration.test.js +++ b/apps/api/test/http.integration.test.js @@ -284,6 +284,8 @@ test("admin can install a template and public workspace exposes enabled configur }); assert.equal(installed.statusCode, 201); assert.equal(JSON.parse(installed.body).template.key, "personal"); + assert.equal(JSON.parse(installed.body).visualTemplate.key, "minimal-neutral"); + assert.equal(JSON.parse(installed.body).installation.configSnapshot.schemaVersion, "1.0"); try { const previewUnauthorized = await request("/admin/workspace/template/preview"); assert.equal(previewUnauthorized.statusCode, 401); @@ -433,6 +435,12 @@ test("admin visual template selection is reflected in public runtime workspace", assert.equal(body.visualTemplate.version, "1.0.0"); assert.equal(body.theme.colors.accent, "#4B5563"); assert.equal(body.visualTemplate.variants.hero, "minimal"); + assert.equal(body.visualTemplateManifest.key, "minimal-neutral"); + assert.equal(body.visualTemplateManifest.brandFirst, true); + assert.deepEqual( + body.visualTemplateManifest.pages.map((page) => page.key), + ["home", "offerings", "detail", "inquiry", "success", "records", "profile"], + ); } finally { await request("/admin/config/brand", { method: "PATCH", diff --git a/apps/miniapp/components/modules/brand-hero/brand-hero.js b/apps/miniapp/components/modules/brand-hero/brand-hero.js index a0a6b45..77310fe 100644 --- a/apps/miniapp/components/modules/brand-hero/brand-hero.js +++ b/apps/miniapp/components/modules/brand-hero/brand-hero.js @@ -1,5 +1,5 @@ Component({ - properties: { hero: { type: Object, value: {} } }, + properties: { hero: { type: Object, value: {} }, variant: { type: String, value: "default" } }, methods: { explore() { this.triggerEvent("explore"); diff --git a/apps/miniapp/components/modules/founder-card/founder-card.js b/apps/miniapp/components/modules/founder-card/founder-card.js index 016c1fc..3ce30a1 100644 --- a/apps/miniapp/components/modules/founder-card/founder-card.js +++ b/apps/miniapp/components/modules/founder-card/founder-card.js @@ -1 +1,3 @@ -Component({ properties: { brand: { type: Object, value: {} } } }); +Component({ + properties: { brand: { type: Object, value: {} }, variant: { type: String, value: "default" } }, +}); diff --git a/apps/miniapp/components/modules/offering-list/offering-list.js b/apps/miniapp/components/modules/offering-list/offering-list.js index 0ac65bb..6f9b3d4 100644 --- a/apps/miniapp/components/modules/offering-list/offering-list.js +++ b/apps/miniapp/components/modules/offering-list/offering-list.js @@ -1,5 +1,8 @@ Component({ - properties: { offerings: { type: Array, value: [] } }, + properties: { + offerings: { type: Array, value: [] }, + variant: { type: String, value: "default" }, + }, methods: { open(e) { this.triggerEvent("open", { id: e.currentTarget.dataset.id }); diff --git a/apps/miniapp/components/modules/trust-manifesto/trust-manifesto.js b/apps/miniapp/components/modules/trust-manifesto/trust-manifesto.js index a940b20..13d462c 100644 --- a/apps/miniapp/components/modules/trust-manifesto/trust-manifesto.js +++ b/apps/miniapp/components/modules/trust-manifesto/trust-manifesto.js @@ -1 +1,3 @@ -Component({ properties: { content: { type: Object, value: {} } } }); +Component({ + properties: { content: { type: Object, value: {} }, variant: { type: String, value: "default" } }, +}); diff --git a/apps/miniapp/components/modules/trust-proof/trust-proof.js b/apps/miniapp/components/modules/trust-proof/trust-proof.js index a940b20..13d462c 100644 --- a/apps/miniapp/components/modules/trust-proof/trust-proof.js +++ b/apps/miniapp/components/modules/trust-proof/trust-proof.js @@ -1 +1,3 @@ -Component({ properties: { content: { type: Object, value: {} } } }); +Component({ + properties: { content: { type: Object, value: {} }, variant: { type: String, value: "default" } }, +}); diff --git a/apps/miniapp/pages/index/index.js b/apps/miniapp/pages/index/index.js index 0a1f5f7..82dfa4e 100644 --- a/apps/miniapp/pages/index/index.js +++ b/apps/miniapp/pages/index/index.js @@ -5,6 +5,7 @@ Page({ trustContent: [], offerings: [], modules: [], + moduleVariants: {}, layout: [], theme: {}, hero: { @@ -35,6 +36,7 @@ Page({ trustContent: workspace.trustContent || [], offerings: activeOfferings, modules: workspace.modules || [], + moduleVariants: workspace.moduleVariants || {}, layout, theme: workspace.theme || {}, hero: { diff --git a/apps/miniapp/pages/index/index.wxml b/apps/miniapp/pages/index/index.wxml index 144522b..f9cef6d 100644 --- a/apps/miniapp/pages/index/index.wxml +++ b/apps/miniapp/pages/index/index.wxml @@ -1,9 +1,9 @@ - - - - - + + + + + diff --git a/apps/miniapp/utils/module-registry.js b/apps/miniapp/utils/module-registry.js index 4cd6f3b..084bf2b 100644 --- a/apps/miniapp/utils/module-registry.js +++ b/apps/miniapp/utils/module-registry.js @@ -44,19 +44,57 @@ function resolveModule(module) { }; } +const MANIFEST_TYPE_ALIASES = { + "brand-identity": "founder-card", + hero: "brand-hero", + trust: "trust-proof", + "inquiry-form": "inquiry", + "success-summary": "success-summary", + "records-list": "records", +}; + +function resolveManifest(workspace) { + const manifest = workspace && workspace.visualTemplateManifest; + if (!manifest || !Array.isArray(manifest.pages)) return null; + const pages = {}; + for (const page of manifest.pages) { + pages[page.key] = (page.modules || []).map((module) => ({ + ...module, + type: MANIFEST_TYPE_ALIASES[module.type] || module.type, + variant: module.variant || "default", + })); + } + return { ...manifest, pages }; +} + function resolveRuntime(workspace) { const modules = Array.isArray(workspace && workspace.modules) ? workspace.modules : []; + const manifest = resolveManifest(workspace); + const manifestHome = manifest && manifest.pages.home; + const manifestModules = manifestHome || []; const resolved = modules.map(resolveModule); - const home = - workspace && workspace.layout && Array.isArray(workspace.layout.home) + const resolvedTypes = new Set(resolved.map((item) => item.type)); + for (const module of manifestModules) { + if (!resolvedTypes.has(module.type)) { + resolved.push(resolveModule(module)); + resolvedTypes.add(module.type); + } + } + const home = manifestHome?.length + ? manifestHome.map((item) => item.type) + : workspace && workspace.layout && Array.isArray(workspace.layout.home) ? workspace.layout.home : resolved.map((item) => item.type); + const moduleVariants = {}; + for (const item of manifestHome || []) moduleVariants[item.type] = item.variant; return { - theme: workspace && workspace.theme ? workspace.theme : FALLBACK_THEME, + theme: manifest?.tokens || (workspace && workspace.theme ? workspace.theme : FALLBACK_THEME), modules: resolved, layout: { home: home.filter((key) => resolved.some((item) => item.type === key)) }, + moduleVariants, + visualManifest: manifest, capabilities: workspace && Array.isArray(workspace.capabilities) ? workspace.capabilities : [], }; } -module.exports = { CORE_MODULES, FALLBACK_THEME, resolveRuntime }; +module.exports = { CORE_MODULES, FALLBACK_THEME, resolveManifest, resolveRuntime }; diff --git a/packages/api-client/src/index.ts b/packages/api-client/src/index.ts index 29e2c06..4f55548 100644 --- a/packages/api-client/src/index.ts +++ b/packages/api-client/src/index.ts @@ -229,6 +229,36 @@ export interface PublicWorkspace { name: string; variants: Record; } | null; + visualTemplateManifest?: { + schemaVersion: "1.0"; + key: string; + version: string; + name: string; + brandFirst: true; + tokens: { + colors: Record; + spacing: Record; + typography: Record; + radius: Record; + shadows?: Record; + }; + pages: Array<{ + key: string; + title: string; + modules: Array<{ + key: string; + type: string; + variant: string; + required: boolean; + dataSlots?: string[]; + assetSlots?: string[]; + capability?: string; + }>; + }>; + assets: Array>; + dataSlots: Array>; + capabilities: string[]; + }; capabilities: string[]; modules: BrandModule[]; runtimeModules: Array<{