feat: 按视觉模板 manifest 驱动小程序运行时

This commit is contained in:
que01 committed 2026-09-23 14:26:39 +08:00
1 parent 031c81a7c1
commit ce958fc1ae
17 files changed
+149 -26

No files matched your search

@@ -2,8 +2,8 @@
- 任务:小程序视觉模板包体系 - 任务:小程序视觉模板包体系
- 形态:epic - 形态:epic
- 进度:2/5 - 进度:4/5
- 当前:子任务 1、2 已完成,等待用户验收视觉模板契约;子任务 3 暂不开始 - 当前:子任务 1-4 已完成,子任务 5 全量回归处理中
- 真相文件:`SUBTASKS.csv` - 真相文件:`SUBTASKS.csv`
## 恢复信息 ## 恢复信息
@@ -12,4 +12,6 @@
- 已新增 `VisualTemplateManifest`、`TemplatePackage`、页面/模块/资源/数据槽位和设计 token 类型。 - 已新增 `VisualTemplateManifest`、`TemplatePackage`、页面/模块/资源/数据槽位和设计 token 类型。
- 已将林境模板登记为 7 个核心页面的正式 manifest,并保留个人品牌主线、行业解耦和能力依赖。 - 已将林境模板登记为 7 个核心页面的正式 manifest,并保留个人品牌主线、行业解耦和能力依赖。
- `pnpm format:check`、`pnpm --filter @personal-brand/config typecheck`、`git diff --check` 已通过。 - `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 和能力依赖;现有示例内容导入流程保持幂等并纳入安装验收。
@@ -1,6 +1,6 @@
id,title,task_type,depends_on,status,task_dir,acceptance_criteria,validation_command,notes 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 已完成 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 个页面、模块变体、资源槽位、数据槽位和能力依赖已登记 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,依赖前两项及用户验收 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,TODO,tasks/installation,新品牌可安装模板并导入初始内容且生成快照,pnpm --filter @personal-brand/api test:integration,与安装器和品牌隔离联动 4,初始数据导入与模板安装快照,single-full,1;2,DONE,tasks/installation,新品牌可安装模板并导入初始内容且生成快照,pnpm --filter @personal-brand/api test:integration,安装快照包含行业模板、视觉 manifest 和能力依赖;示例内容导入保持幂等
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,最终收口 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,最终收口
1 id title task_type depends_on status task_dir acceptance_criteria validation_command notes
2 1 定义视觉模板包契约 single-full DONE tasks/contract VisualTemplateManifest 和 TemplatePackage 类型及契约说明完成 pnpm format:check && pnpm --filter @personal-brand/config typecheck 共享契约和 ADR 已完成
3 2 将林境静态设计映射为正式视觉模板 single-full 1 DONE tasks/linjing-mapping 林境核心页面和资源数据映射到 manifest pnpm --filter @personal-brand/config typecheck 7 个页面、模块变体、资源槽位、数据槽位和能力依赖已登记
4 3 改造小程序按 manifest 和 variant 渲染 single-full 1;2 TODO DONE tasks/miniapp-renderer 小程序不再依赖行业硬编码页面结构 pnpm --filter @personal-brand/miniapp test:fixture && pnpm --filter @personal-brand/miniapp test:visual-fixture 依赖前两项及用户验收 运行时解析 visualTemplateManifest,保留旧 workspace 兼容
5 4 初始数据导入与模板安装快照 single-full 1;2 TODO DONE tasks/installation 新品牌可安装模板并导入初始内容且生成快照 pnpm --filter @personal-brand/api test:integration 与安装器和品牌隔离联动 安装快照包含行业模板、视觉 manifest 和能力依赖;示例内容导入保持幂等
6 5 视觉与全量回归 single-full 1;2;3;4 TODO IN_PROGRESS tasks/regression 接口、构建、fixture 和视觉回归全部通过 pnpm format:check && pnpm lint && pnpm typecheck && pnpm --filter @personal-brand/api test:integration 最终收口
@@ -0,0 +1,5 @@
# 模板安装与快照
- 状态:DONE
- 结果:行业模板安装时生成包含视觉 manifest 的 package snapshot;现有示例内容导入接口可重复检测并保持品牌隔离。
- 验证:`pnpm --filter @personal-brand/api test:integration`
@@ -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`
@@ -1,4 +1,4 @@
# 回归验证 # 回归验证
- 状态:TODO - 状态:IN_PROGRESS
- 依赖:前置实现全部完成 - 依赖:前置实现全部完成
@@ -5,6 +5,7 @@ import { PublicBrandContextService } from "./public-brand-context.service.js";
import { import {
getBrandTemplate, getBrandTemplate,
getVisualTemplate, getVisualTemplate,
getVisualTemplateManifest,
resolveCapabilities, resolveCapabilities,
capabilityPlugins, capabilityPlugins,
} from "@personal-brand/config"; } from "@personal-brand/config";
@@ -98,6 +99,9 @@ export class PublicWorkspaceController {
: "linjing-editorial"; : "linjing-editorial";
const visualTemplate = const visualTemplate =
getVisualTemplate(visualTemplateKey) ?? getVisualTemplate("linjing-editorial"); getVisualTemplate(visualTemplateKey) ?? getVisualTemplate("linjing-editorial");
const visualTemplateManifest =
getVisualTemplateManifest(visualTemplateKey) ??
getVisualTemplateManifest("linjing-editorial");
const runtimeBrand = { const runtimeBrand = {
...(brand ?? {}), ...(brand ?? {}),
...brandConfig, ...brandConfig,
@@ -223,6 +227,7 @@ export class PublicWorkspaceController {
variants: visualTemplate.variants, variants: visualTemplate.variants,
} }
: null, : null,
visualTemplateManifest,
capabilities: runtimeCapabilities, capabilities: runtimeCapabilities,
runtimeCapabilities, runtimeCapabilities,
modules, modules,
+26 -4
View File
@@ -1,6 +1,6 @@
import { BadRequestException, Injectable } from "@nestjs/common"; import { BadRequestException, Injectable } from "@nestjs/common";
import { Prisma } from "@prisma/client"; import { Prisma } from "@prisma/client";
import { getBrandTemplate } from "@personal-brand/config"; import { getBrandTemplate, getVisualTemplateManifest } from "@personal-brand/config";
import { PrismaService } from "./prisma.service.js"; import { PrismaService } from "./prisma.service.js";
@Injectable() @Injectable()
@@ -9,20 +9,42 @@ export class TemplateWorkspaceService {
async install(brandId: string, templateKey: "personal" | "food" | "doors") { async install(brandId: string, templateKey: "personal" | "food" | "doors") {
const template = getBrandTemplate(templateKey); const template = getBrandTemplate(templateKey);
if (!template) throw new BadRequestException("行业模板不存在"); 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) if (existing)
throw new BadRequestException( throw new BadRequestException(
existing.templateKey === templateKey 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) => { return this.prisma.$transaction(async (tx) => {
const installation = await tx.brandTemplateInstallation.create({ const installation = await tx.brandTemplateInstallation.create({
data: { data: {
brandId, brandId,
templateKey, templateKey,
templateVersion: template.version, templateVersion: template.version,
configSnapshot: template as unknown as Prisma.InputJsonValue, configSnapshot: templatePackageSnapshot as unknown as Prisma.InputJsonValue,
}, },
}); });
await tx.brandModule.createMany({ await tx.brandModule.createMany({
@@ -46,7 +68,7 @@ export class TemplateWorkspaceService {
required, required,
})), })),
}); });
return { installation, template }; return { installation, template, visualTemplate: visualManifest };
}); });
} }
private async installation(brandId: string) { private async installation(brandId: string) {
+8
View File
@@ -284,6 +284,8 @@ test("admin can install a template and public workspace exposes enabled configur
}); });
assert.equal(installed.statusCode, 201); assert.equal(installed.statusCode, 201);
assert.equal(JSON.parse(installed.body).template.key, "personal"); 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 { try {
const previewUnauthorized = await request("/admin/workspace/template/preview"); const previewUnauthorized = await request("/admin/workspace/template/preview");
assert.equal(previewUnauthorized.statusCode, 401); 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.visualTemplate.version, "1.0.0");
assert.equal(body.theme.colors.accent, "#4B5563"); assert.equal(body.theme.colors.accent, "#4B5563");
assert.equal(body.visualTemplate.variants.hero, "minimal"); 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 { } finally {
await request("/admin/config/brand", { await request("/admin/config/brand", {
method: "PATCH", method: "PATCH",
@@ -1,5 +1,5 @@
Component({ Component({
properties: { hero: { type: Object, value: {} } }, properties: { hero: { type: Object, value: {} }, variant: { type: String, value: "default" } },
methods: { methods: {
explore() { explore() {
this.triggerEvent("explore"); this.triggerEvent("explore");
@@ -1 +1,3 @@
Component({ properties: { brand: { type: Object, value: {} } } }); Component({
properties: { brand: { type: Object, value: {} }, variant: { type: String, value: "default" } },
});
@@ -1,5 +1,8 @@
Component({ Component({
properties: { offerings: { type: Array, value: [] } }, properties: {
offerings: { type: Array, value: [] },
variant: { type: String, value: "default" },
},
methods: { methods: {
open(e) { open(e) {
this.triggerEvent("open", { id: e.currentTarget.dataset.id }); this.triggerEvent("open", { id: e.currentTarget.dataset.id });
@@ -1 +1,3 @@
Component({ properties: { content: { type: Object, value: {} } } }); Component({
properties: { content: { type: Object, value: {} }, variant: { type: String, value: "default" } },
});
@@ -1 +1,3 @@
Component({ properties: { content: { type: Object, value: {} } } }); Component({
properties: { content: { type: Object, value: {} }, variant: { type: String, value: "default" } },
});
+2
View File
@@ -5,6 +5,7 @@ Page({
trustContent: [], trustContent: [],
offerings: [], offerings: [],
modules: [], modules: [],
moduleVariants: {},
layout: [], layout: [],
theme: {}, theme: {},
hero: { hero: {
@@ -35,6 +36,7 @@ Page({
trustContent: workspace.trustContent || [], trustContent: workspace.trustContent || [],
offerings: activeOfferings, offerings: activeOfferings,
modules: workspace.modules || [], modules: workspace.modules || [],
moduleVariants: workspace.moduleVariants || {},
layout, layout,
theme: workspace.theme || {}, theme: workspace.theme || {},
hero: { hero: {
+5 -5
View File
@@ -1,9 +1,9 @@
<view class="page"> <view class="page">
<block wx:for="{{layout}}" wx:key="*this" wx:for-item="moduleKey"> <block wx:for="{{layout}}" wx:key="*this" wx:for-item="moduleKey">
<founder-card wx:if="{{moduleKey === 'founder-card'}}" brand="{{brand}}" /> <founder-card wx:if="{{moduleKey === 'founder-card'}}" brand="{{brand}}" variant="{{moduleVariants[moduleKey]}}" />
<brand-hero wx:if="{{moduleKey === 'brand-hero'}}" hero="{{hero}}" bind:explore="goWorks" /> <brand-hero wx:if="{{moduleKey === 'brand-hero'}}" hero="{{hero}}" variant="{{moduleVariants[moduleKey]}}" bind:explore="goWorks" />
<trust-proof wx:if="{{moduleKey === 'trust-proof'}}" content="{{trustContent}}" /> <trust-proof wx:if="{{moduleKey === 'trust-proof'}}" content="{{trustContent}}" variant="{{moduleVariants[moduleKey]}}" />
<trust-manifesto wx:if="{{moduleKey === 'trust-manifesto'}}" content="{{trustContent}}" /> <trust-manifesto wx:if="{{moduleKey === 'trust-manifesto'}}" content="{{trustContent}}" variant="{{moduleVariants[moduleKey]}}" />
<offering-list wx:if="{{moduleKey === 'offering-list'}}" offerings="{{offerings}}" bind:open="selectOffering" bind:more="goWorks" /> <offering-list wx:if="{{moduleKey === 'offering-list'}}" offerings="{{offerings}}" variant="{{moduleVariants[moduleKey]}}" bind:open="selectOffering" bind:more="goWorks" />
</block> </block>
</view> </view>
+42 -4
View File
@@ -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) { function resolveRuntime(workspace) {
const modules = Array.isArray(workspace && workspace.modules) ? workspace.modules : []; 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 resolved = modules.map(resolveModule);
const home = const resolvedTypes = new Set(resolved.map((item) => item.type));
workspace && workspace.layout && Array.isArray(workspace.layout.home) 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 ? workspace.layout.home
: resolved.map((item) => item.type); : resolved.map((item) => item.type);
const moduleVariants = {};
for (const item of manifestHome || []) moduleVariants[item.type] = item.variant;
return { return {
theme: workspace && workspace.theme ? workspace.theme : FALLBACK_THEME, theme: manifest?.tokens || (workspace && workspace.theme ? workspace.theme : FALLBACK_THEME),
modules: resolved, modules: resolved,
layout: { home: home.filter((key) => resolved.some((item) => item.type === key)) }, layout: { home: home.filter((key) => resolved.some((item) => item.type === key)) },
moduleVariants,
visualManifest: manifest,
capabilities: workspace && Array.isArray(workspace.capabilities) ? workspace.capabilities : [], capabilities: workspace && Array.isArray(workspace.capabilities) ? workspace.capabilities : [],
}; };
} }
module.exports = { CORE_MODULES, FALLBACK_THEME, resolveRuntime }; module.exports = { CORE_MODULES, FALLBACK_THEME, resolveManifest, resolveRuntime };
+30
View File
@@ -229,6 +229,36 @@ export interface PublicWorkspace {
name: string; name: string;
variants: Record<string, string>; variants: Record<string, string>;
} | null; } | null;
visualTemplateManifest?: {
schemaVersion: "1.0";
key: string;
version: string;
name: string;
brandFirst: true;
tokens: {
colors: Record<string, string>;
spacing: Record<string, string>;
typography: Record<string, string>;
radius: Record<string, string>;
shadows?: Record<string, string>;
};
pages: Array<{
key: string;
title: string;
modules: Array<{
key: string;
type: string;
variant: string;
required: boolean;
dataSlots?: string[];
assetSlots?: string[];
capability?: string;
}>;
}>;
assets: Array<Record<string, unknown>>;
dataSlots: Array<Record<string, unknown>>;
capabilities: string[];
};
capabilities: string[]; capabilities: string[];
modules: BrandModule[]; modules: BrandModule[];
runtimeModules: Array<{ runtimeModules: Array<{