feat: P4-3 eip4-web 前端渲染宿主脚手架(amis 6.13.0 本地化/登录JWT/待办/双闸渲染闸)

- 脚手架:React 18 + Vite 5 + TS;amis 6.13.0 本地 SDK(public/sdk-local,不依赖 CDN,
  照 PoC amis-local.html 范式 amisRequire('amis/embed'))
- 登录页:POST /api/auth/login + JWT 存储(内存+localStorage 折中,XSS 权衡见 README/token.ts)
- 页面渲染 /page/:templateId:取转换后 schema 渲染;开发期静态 mock(public/schemas/ 放
  角色维护/通知管理归档/用户组管理 3 个真实转换产物,均过官方 schema.json 校验闸);
  生产期 schema 接口契约已设计(VITE_SCHEMA_SOURCE 切换)
- 待办页 /todo:GET /api/todo + 503 熔断降级展示
- amis fetcher 适配:复用宿主 axios 注入 Bearer,对接 /api/entity amis CRUD 格式
- axios 拦截器:Bearer 注入 + 401 清会话跳登录
- 联调验证(playwright 无头):登录跳转→渲染用户组(本地库 3 行)→角色维护(真实产物)→
  待办 503 降级→401 跳登录(prod 严格链 8090),5 张截图留 docs/
- 工程化:npm run build → dist/(应用 208KB/gzip 71KB + 本地 SDK 61MB,Nginx 可托管);
  README/报告/gitignore

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-06-11 16:13:17 +08:00
parent c51f37e228
commit b3486c093e
140 changed files with 88352 additions and 12 deletions

View File

@@ -0,0 +1,39 @@
// 页面渲染路由 /page/:templateId —— 取转换后 schema 交 amis 渲染
import { useEffect, useState } from 'react';
import { useParams } from 'react-router-dom';
import { fetchSchema } from '../api/schema';
import { AmisRenderer } from '../components/AmisRenderer';
export function PageRenderPage() {
const { templateId = '' } = useParams();
const [schema, setSchema] = useState<Record<string, unknown> | null>(null);
const [error, setError] = useState('');
useEffect(() => {
let alive = true;
setSchema(null);
setError('');
fetchSchema(templateId)
.then((s) => {
if (alive) setSchema(s);
})
.catch((e: Error) => {
if (alive) setError(e.message);
});
return () => {
alive = false;
};
}, [templateId]);
if (error) {
return <div style={{ padding: 24, color: '#d9534f' }}>加载页面失败:{error}</div>;
}
if (!schema) {
return <div style={{ padding: 24, color: '#888' }}>加载中…</div>;
}
return (
<div style={{ height: '100%' }} data-testid="amis-host">
<AmisRenderer schema={schema} />
</div>
);
}