fetchSchemaLayer/putOverlay/restoreStandard 全仓(含 e2e)零引用,真实 overlay API 在 editor/overlayApi.ts;删重复死份。tsc 干净 + vitest 77/77。见总览 §10 B2。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
64 lines
2.8 KiB
TypeScript
64 lines
2.8 KiB
TypeScript
// ============================================================================
|
||
// 页面 schema 获取 —— 双源(开发期静态 mock / 生产期后端接口)
|
||
// ----------------------------------------------------------------------------
|
||
// templateId → schema 映射:
|
||
// - 开发期(VITE_SCHEMA_SOURCE 缺省或 'mock'):读 public/schemas/<id>.json
|
||
// (内容是 eip4-poc 转换器对客户库真实模板的转换产物,已过官方 schema.json 校验闸)。
|
||
// - 生产期(VITE_SCHEMA_SOURCE='backend'):读后端 schema 接口(契约见下)。
|
||
//
|
||
// 生产期后端 schema 接口契约(本期为设计,后端 P5 落地):
|
||
// GET /api/page/schema/{templateId}
|
||
// 响应:200 直接返回 amis 页面 schema(JSON,顶层 type:'page'),
|
||
// 由后端在「校验闸」通过后下发(官方 schema.json 校验,见迁移手册 §8 双闸)。
|
||
// 404:模板不存在;503:转换器不可用。
|
||
// 鉴权:带 Bearer(由 http 拦截器注入)。
|
||
// ============================================================================
|
||
import { http } from './http';
|
||
|
||
const SOURCE = (import.meta.env.VITE_SCHEMA_SOURCE as string) || 'mock';
|
||
|
||
// 开发期 mock:templateId → public/schemas 文件名
|
||
const MOCK_MAP: Record<string, string> = {
|
||
'role-maintain': '/schemas/role-maintain.json',
|
||
'notice-archive': '/schemas/notice-archive.json',
|
||
'usergroup-manage': '/schemas/usergroup-manage.json',
|
||
// P4-5 改写后脚本挂回 onEvent 重放 e2e(真实 FULL_AUTO facade-only 脚本)
|
||
'welfare-settlement': '/schemas/welfare-settlement.json',
|
||
'office-collar': '/schemas/office-collar.json',
|
||
};
|
||
|
||
export interface PageMeta {
|
||
id: string;
|
||
title: string;
|
||
}
|
||
|
||
// 开发期可选页面清单(供页面入口展示导航)
|
||
export const MOCK_PAGES: PageMeta[] = [
|
||
{ id: 'usergroup-manage', title: '用户组管理(本地实体联调)' },
|
||
{ id: 'role-maintain', title: '角色维护(真实转换产物)' },
|
||
{ id: 'notice-archive', title: '通知管理归档(真实转换产物)' },
|
||
];
|
||
|
||
export async function fetchSchema(templateId: string): Promise<Record<string, unknown>> {
|
||
if (SOURCE === 'backend') {
|
||
const { data } = await http.get<Record<string, unknown>>(
|
||
`/api/page/schema/${encodeURIComponent(templateId)}`,
|
||
);
|
||
return data;
|
||
}
|
||
// 开发期静态 mock:有配置则走本地文件,否则 fallback 到后端接口(支持真实 UUID)
|
||
const path = MOCK_MAP[templateId];
|
||
if (path) {
|
||
const resp = await fetch(path);
|
||
if (!resp.ok) {
|
||
throw new Error(`加载 schema 失败:${resp.status}`);
|
||
}
|
||
return (await resp.json()) as Record<string, unknown>;
|
||
}
|
||
// mock 未配置 → fallback 到后端(开发期也可渲染真实 UUID 模板)
|
||
const { data } = await http.get<Record<string, unknown>>(
|
||
`/api/page/schema/${encodeURIComponent(templateId)}`,
|
||
);
|
||
return data;
|
||
}
|