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:
112
src/pages/LoginPage.tsx
Normal file
112
src/pages/LoginPage.tsx
Normal file
@@ -0,0 +1,112 @@
|
||||
// 登录页:POST /api/auth/login → 存 JWT → 跳转
|
||||
import { type FormEvent, useState } from 'react';
|
||||
import { useLocation, useNavigate } from 'react-router-dom';
|
||||
import { login, toProfile } from '../api/auth';
|
||||
import { setSession } from '../auth/token';
|
||||
|
||||
export function LoginPage() {
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
const from = (location.state as { from?: string })?.from || '/page/usergroup-manage';
|
||||
|
||||
const [account, setAccount] = useState('alice');
|
||||
const [password, setPassword] = useState('123456');
|
||||
const [error, setError] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const onSubmit = async (e: FormEvent) => {
|
||||
e.preventDefault();
|
||||
setError('');
|
||||
setLoading(true);
|
||||
try {
|
||||
const resp = await login(account.trim(), password);
|
||||
if (!resp.success || !resp.token) {
|
||||
setError(resp.msg || '登录失败');
|
||||
return;
|
||||
}
|
||||
setSession(resp.token, toProfile(resp));
|
||||
navigate(from, { replace: true });
|
||||
} catch (err) {
|
||||
const status = (err as { response?: { status?: number } }).response?.status;
|
||||
setError(status === 401 ? '账号或密码错误' : '登录请求失败,请检查后端服务');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
height: '100%',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
background: '#eef1f4',
|
||||
}}
|
||||
>
|
||||
<form
|
||||
onSubmit={onSubmit}
|
||||
style={{
|
||||
width: 340,
|
||||
padding: 32,
|
||||
background: '#fff',
|
||||
borderRadius: 8,
|
||||
boxShadow: '0 4px 24px rgba(0,0,0,0.08)',
|
||||
}}
|
||||
>
|
||||
<h2 style={{ margin: '0 0 8px', color: '#1f2d3d' }}>EIP4 登录</h2>
|
||||
<p style={{ margin: '0 0 24px', color: '#888', fontSize: 13 }}>渲染宿主 · amis 6.13.0 本地化</p>
|
||||
|
||||
<label style={{ display: 'block', fontSize: 13, color: '#555', marginBottom: 6 }}>账号</label>
|
||||
<input
|
||||
value={account}
|
||||
onChange={(e) => setAccount(e.target.value)}
|
||||
autoComplete="username"
|
||||
style={inputStyle}
|
||||
/>
|
||||
|
||||
<label style={{ display: 'block', fontSize: 13, color: '#555', margin: '16px 0 6px' }}>密码</label>
|
||||
<input
|
||||
type="password"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
autoComplete="current-password"
|
||||
style={inputStyle}
|
||||
/>
|
||||
|
||||
{error && (
|
||||
<div style={{ color: '#d9534f', fontSize: 13, marginTop: 12 }} role="alert">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<button type="submit" disabled={loading} style={buttonStyle(loading)}>
|
||||
{loading ? '登录中…' : '登录'}
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const inputStyle: React.CSSProperties = {
|
||||
width: '100%',
|
||||
boxSizing: 'border-box',
|
||||
padding: '9px 12px',
|
||||
border: '1px solid #d4d7dc',
|
||||
borderRadius: 4,
|
||||
fontSize: 14,
|
||||
};
|
||||
|
||||
function buttonStyle(loading: boolean): React.CSSProperties {
|
||||
return {
|
||||
width: '100%',
|
||||
marginTop: 24,
|
||||
padding: '10px 0',
|
||||
background: loading ? '#7aa7e0' : '#2468f2',
|
||||
color: '#fff',
|
||||
border: 'none',
|
||||
borderRadius: 4,
|
||||
fontSize: 15,
|
||||
cursor: loading ? 'not-allowed' : 'pointer',
|
||||
};
|
||||
}
|
||||
39
src/pages/PageRenderPage.tsx
Normal file
39
src/pages/PageRenderPage.tsx
Normal 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>
|
||||
);
|
||||
}
|
||||
114
src/pages/TodoPage.tsx
Normal file
114
src/pages/TodoPage.tsx
Normal file
@@ -0,0 +1,114 @@
|
||||
// 待办列表页 /todo —— 调 /api/todo,列表 + 点击进对应业务页占位
|
||||
// flowable-service 不起时网关 503,本页降级展示提示(不崩)。
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { fetchTodo, type TodoItem } from '../api/todo';
|
||||
|
||||
export function TodoPage() {
|
||||
const navigate = useNavigate();
|
||||
const [items, setItems] = useState<TodoItem[]>([]);
|
||||
const [unavailable, setUnavailable] = useState(false);
|
||||
const [message, setMessage] = useState('');
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
fetchTodo()
|
||||
.then((r) => {
|
||||
if (!alive) return;
|
||||
setItems(r.items);
|
||||
setUnavailable(r.unavailable);
|
||||
setMessage(r.message || '');
|
||||
})
|
||||
.catch((e: Error) => alive && setError(e.message))
|
||||
.finally(() => alive && setLoading(false));
|
||||
return () => {
|
||||
alive = false;
|
||||
};
|
||||
}, []);
|
||||
|
||||
const openBusiness = (item: TodoItem) => {
|
||||
// 占位:按业务表跳对应业务页(本期无 表→templateId 映射表,跳通用占位并带参)
|
||||
const tpl = item.businessTable ? String(item.businessTable).toLowerCase() : 'usergroup-manage';
|
||||
navigate(`/page/${tpl}`, { state: { businessKey: item.businessKey } });
|
||||
};
|
||||
|
||||
return (
|
||||
<div style={{ padding: 24 }}>
|
||||
<h2 style={{ marginTop: 0, color: '#1f2d3d' }}>我的待办</h2>
|
||||
|
||||
{loading && <div style={{ color: '#888' }}>加载中…</div>}
|
||||
|
||||
{!loading && unavailable && (
|
||||
<div
|
||||
data-testid="todo-degraded"
|
||||
style={{
|
||||
padding: 16,
|
||||
background: '#fff7e6',
|
||||
border: '1px solid #ffd591',
|
||||
borderRadius: 6,
|
||||
color: '#ad6800',
|
||||
}}
|
||||
>
|
||||
⚠ 工作流引擎暂不可达(网关 503 熔断降级):{message || '请稍后重试'}
|
||||
<div style={{ fontSize: 12, marginTop: 6, color: '#b08600' }}>
|
||||
单体侧待办聚合依赖 flowable-service;引擎宕机时本页降级,不影响其他页面。
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!loading && error && <div style={{ color: '#d9534f' }}>请求失败:{error}</div>}
|
||||
|
||||
{!loading && !unavailable && !error && items.length === 0 && (
|
||||
<div style={{ color: '#888' }}>暂无待办。</div>
|
||||
)}
|
||||
|
||||
{!loading && items.length > 0 && (
|
||||
<table style={{ width: '100%', borderCollapse: 'collapse', background: '#fff' }}>
|
||||
<thead>
|
||||
<tr style={{ background: '#fafafa', textAlign: 'left' }}>
|
||||
<th style={thStyle}>任务名</th>
|
||||
<th style={thStyle}>业务摘要</th>
|
||||
<th style={thStyle}>业务表</th>
|
||||
<th style={thStyle}>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{items.map((it, idx) => (
|
||||
<tr key={it.taskId || idx} style={{ borderTop: '1px solid #f0f0f0' }}>
|
||||
<td style={tdStyle}>{it.taskName || '-'}</td>
|
||||
<td style={tdStyle}>{summarize(it)}</td>
|
||||
<td style={tdStyle}>{it.businessTable || <span style={{ color: '#bbb' }}>(无映射)</span>}</td>
|
||||
<td style={tdStyle}>
|
||||
<button onClick={() => openBusiness(it)} style={linkBtnStyle}>
|
||||
打开
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function summarize(it: TodoItem): string {
|
||||
const s = it.businessSummary;
|
||||
if (s && typeof s === 'object') {
|
||||
const vals = Object.values(s).filter((v) => v != null && v !== '');
|
||||
if (vals.length) return vals.slice(0, 2).map(String).join(' / ');
|
||||
}
|
||||
return it.businessKey ? `businessKey:${it.businessKey}` : '-';
|
||||
}
|
||||
|
||||
const thStyle: React.CSSProperties = { padding: '10px 12px', fontSize: 13, color: '#555' };
|
||||
const tdStyle: React.CSSProperties = { padding: '10px 12px', fontSize: 13, color: '#333' };
|
||||
const linkBtnStyle: React.CSSProperties = {
|
||||
background: 'transparent',
|
||||
border: 'none',
|
||||
color: '#2468f2',
|
||||
cursor: 'pointer',
|
||||
fontSize: 13,
|
||||
};
|
||||
Reference in New Issue
Block a user