F2-7: 审批办理 UI 前端——ApprovalBar + trace 时间线 + e2e
- src/api/approval.ts:completeTask/delegateTask/fetchTrace API - src/components/ApprovalBar.tsx:办理动作条(同意/驳回/转办+意见输入; 流程轨迹抽屉 TraceTimeline 时间线;转办 Drawer 弹窗) - src/pages/TodoPage.tsx:行内展开 ApprovalBar,办理后刷新列表+回调 - e2e/approval.spec.ts:4 个场景(UI展示/complete链路/trace/delegate), 自起 E2E- 前缀流程实例,测后 psql 清理,4/4 通过 - docs/P1/F2-7审批UI报告.md:端点增补清单、e2e 证据、环境限制说明 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
53
src/api/approval.ts
Normal file
53
src/api/approval.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
// 审批办理 API —— complete(同意/驳回) / delegate(转办) / trace(轨迹)
|
||||
import { http } from './http';
|
||||
|
||||
export interface CompleteRequest {
|
||||
variables?: Record<string, unknown>;
|
||||
businessKey?: string;
|
||||
processInstanceId?: string;
|
||||
tableName?: string;
|
||||
}
|
||||
|
||||
export interface CompleteResult {
|
||||
completed: boolean;
|
||||
statusWritten: boolean;
|
||||
processEnded: boolean;
|
||||
}
|
||||
|
||||
export interface DelegateRequest {
|
||||
delegateUserId: string;
|
||||
}
|
||||
|
||||
export interface TraceNode {
|
||||
taskId?: string;
|
||||
taskName?: string;
|
||||
assignee?: string;
|
||||
assigneeName?: string;
|
||||
comment?: string;
|
||||
result?: string;
|
||||
startTime?: number;
|
||||
endTime?: number;
|
||||
current?: boolean;
|
||||
}
|
||||
|
||||
export async function completeTask(
|
||||
taskId: string,
|
||||
req: CompleteRequest,
|
||||
): Promise<CompleteResult> {
|
||||
const { data } = await http.post<CompleteResult>(`/api/task/${taskId}/complete`, req);
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function delegateTask(
|
||||
taskId: string,
|
||||
req: DelegateRequest,
|
||||
): Promise<void> {
|
||||
await http.post(`/api/task/${taskId}/delegate`, req);
|
||||
}
|
||||
|
||||
export async function fetchTrace(processInstanceId: string): Promise<TraceNode[]> {
|
||||
const { data } = await http.get<TraceNode[]>(
|
||||
`/api/flow/process/${processInstanceId}/trace`,
|
||||
);
|
||||
return Array.isArray(data) ? data : [];
|
||||
}
|
||||
309
src/components/ApprovalBar.tsx
Normal file
309
src/components/ApprovalBar.tsx
Normal file
@@ -0,0 +1,309 @@
|
||||
// ApprovalBar —— 办理动作条(同意/驳回/转办 + 审批意见 + 流程轨迹抽屉)
|
||||
// 布局参照原型 ApprovalDetail 操作条:底部固定条,意见输入区+三按钮+轨迹入口
|
||||
import { useState } from 'react';
|
||||
import { Drawer } from './ui/Dialog';
|
||||
import { toast } from './ui/Toast';
|
||||
import { completeTask, delegateTask, fetchTrace } from '../api/approval';
|
||||
import type { TraceNode } from '../api/approval';
|
||||
|
||||
export interface ApprovalBarProps {
|
||||
taskId: string;
|
||||
processInstanceId?: string;
|
||||
businessKey?: string;
|
||||
tableName?: string;
|
||||
/** 办理成功后回调(刷新待办列表/铃铛) */
|
||||
onCompleted?: () => void;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 流程轨迹时间线
|
||||
// ---------------------------------------------------------------------------
|
||||
function TraceTimeline({ nodes }: { nodes: TraceNode[] }) {
|
||||
if (nodes.length === 0) {
|
||||
return (
|
||||
<div style={{ color: 'var(--text-3)', padding: '24px 0', textAlign: 'center' }}>
|
||||
暂无轨迹记录
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 0 }}>
|
||||
{nodes.map((node, idx) => {
|
||||
const isLast = idx === nodes.length - 1;
|
||||
const resultMap: Record<string, { text: string; color: string }> = {
|
||||
agree: { text: '同意', color: 'var(--ok)' },
|
||||
approved: { text: '同意', color: 'var(--ok)' },
|
||||
reject: { text: '驳回', color: 'var(--err)' },
|
||||
rejected: { text: '驳回', color: 'var(--err)' },
|
||||
transfer: { text: '转办', color: 'var(--warn)' },
|
||||
complete: { text: '完成', color: 'var(--ok)' },
|
||||
};
|
||||
const res = node.result ? (resultMap[node.result.toLowerCase()] ?? { text: node.result, color: 'var(--text-2)' }) : null;
|
||||
const dotColor = node.current ? 'var(--brand)' : node.endTime ? 'var(--ok)' : 'var(--text-3)';
|
||||
|
||||
return (
|
||||
<div key={node.taskId ?? idx} style={{ display: 'flex', gap: 12 }}>
|
||||
{/* 时间线竖线 + 圆点 */}
|
||||
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', width: 20, flexShrink: 0 }}>
|
||||
<div
|
||||
style={{
|
||||
width: 12,
|
||||
height: 12,
|
||||
borderRadius: '50%',
|
||||
background: dotColor,
|
||||
border: node.current ? '2px solid var(--brand)' : '2px solid transparent',
|
||||
boxSizing: 'border-box',
|
||||
marginTop: 4,
|
||||
flexShrink: 0,
|
||||
}}
|
||||
/>
|
||||
{!isLast && (
|
||||
<div style={{ width: 2, flex: 1, background: 'var(--line)', minHeight: 24, margin: '2px 0' }} />
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 节点内容 */}
|
||||
<div style={{ paddingBottom: isLast ? 0 : 20, flex: 1, minWidth: 0 }}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' }}>
|
||||
<span style={{ fontWeight: 600, fontSize: 'var(--fs)' }}>
|
||||
{node.taskName || '(未命名节点)'}
|
||||
</span>
|
||||
{node.current && (
|
||||
<span className="tag tag-info" style={{ fontSize: 11 }}>当前</span>
|
||||
)}
|
||||
{res && (
|
||||
<span style={{ fontSize: 12, color: res.color, fontWeight: 500 }}>{res.text}</span>
|
||||
)}
|
||||
</div>
|
||||
<div style={{ fontSize: 'var(--fs-sm)', color: 'var(--text-2)', marginTop: 2 }}>
|
||||
{node.assigneeName || node.assignee || '—'}
|
||||
{node.startTime && (
|
||||
<span style={{ marginLeft: 8, color: 'var(--text-3)' }}>
|
||||
{new Date(node.startTime).toLocaleString('zh-CN', { hour12: false }).slice(0, 16)}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
{node.comment && (
|
||||
<div
|
||||
style={{
|
||||
marginTop: 4,
|
||||
padding: '4px 8px',
|
||||
background: 'var(--bg-2)',
|
||||
borderRadius: 'var(--radius)',
|
||||
fontSize: 'var(--fs-sm)',
|
||||
color: 'var(--text-1)',
|
||||
wordBreak: 'break-all',
|
||||
}}
|
||||
>
|
||||
{node.comment}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 转办弹窗内容
|
||||
// ---------------------------------------------------------------------------
|
||||
function DelegateForm({
|
||||
taskId,
|
||||
onSuccess,
|
||||
onCancel,
|
||||
}: {
|
||||
taskId: string;
|
||||
onSuccess: () => void;
|
||||
onCancel: () => void;
|
||||
}) {
|
||||
const [userId, setUserId] = useState('');
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
|
||||
const submit = async () => {
|
||||
if (!userId.trim()) {
|
||||
toast('请输入转办人账号', 'warn');
|
||||
return;
|
||||
}
|
||||
setSubmitting(true);
|
||||
try {
|
||||
await delegateTask(taskId, { delegateUserId: userId.trim() });
|
||||
toast('转办成功');
|
||||
onSuccess();
|
||||
} catch {
|
||||
toast('转办失败,请重试', 'err');
|
||||
} finally {
|
||||
setSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
|
||||
<label style={{ fontSize: 'var(--fs-sm)', color: 'var(--text-2)' }}>
|
||||
转办人账号(userId)
|
||||
</label>
|
||||
<input
|
||||
className="input"
|
||||
placeholder="请输入被转办人账号"
|
||||
value={userId}
|
||||
onChange={(e) => setUserId(e.target.value)}
|
||||
autoFocus
|
||||
/>
|
||||
<div style={{ display: 'flex', gap: 8, justifyContent: 'flex-end', marginTop: 4 }}>
|
||||
<button className="btn btn-sm" onClick={onCancel} disabled={submitting}>
|
||||
取消
|
||||
</button>
|
||||
<button className="btn btn-sm btn-primary" onClick={submit} disabled={submitting}>
|
||||
{submitting ? '提交中…' : '确认转办'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 主组件:ApprovalBar
|
||||
// ---------------------------------------------------------------------------
|
||||
export function ApprovalBar({
|
||||
taskId,
|
||||
processInstanceId,
|
||||
businessKey,
|
||||
tableName,
|
||||
onCompleted,
|
||||
}: ApprovalBarProps) {
|
||||
const [comment, setComment] = useState('');
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
const [showTrace, setShowTrace] = useState(false);
|
||||
const [showDelegate, setShowDelegate] = useState(false);
|
||||
const [traceNodes, setTraceNodes] = useState<TraceNode[]>([]);
|
||||
const [traceLoading, setTraceLoading] = useState(false);
|
||||
|
||||
const openTrace = async () => {
|
||||
setShowTrace(true);
|
||||
if (processInstanceId) {
|
||||
setTraceLoading(true);
|
||||
try {
|
||||
const nodes = await fetchTrace(processInstanceId);
|
||||
setTraceNodes(nodes);
|
||||
} catch {
|
||||
toast('轨迹加载失败', 'err');
|
||||
} finally {
|
||||
setTraceLoading(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const handleComplete = async (action: 'agree' | 'reject') => {
|
||||
setSubmitting(true);
|
||||
try {
|
||||
await completeTask(taskId, {
|
||||
variables: {
|
||||
approveResult: action,
|
||||
comment: comment.trim() || undefined,
|
||||
},
|
||||
processInstanceId,
|
||||
businessKey,
|
||||
tableName,
|
||||
});
|
||||
toast(action === 'agree' ? '已同意' : '已驳回');
|
||||
if (onCompleted) onCompleted();
|
||||
} catch {
|
||||
toast('办理失败,请重试', 'err');
|
||||
} finally {
|
||||
setSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* 办理条 */}
|
||||
<div
|
||||
data-testid="approval-bar"
|
||||
style={{
|
||||
borderTop: '1px solid var(--line)',
|
||||
padding: '12px 16px',
|
||||
background: 'var(--bg)',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
gap: 10,
|
||||
}}
|
||||
>
|
||||
{/* 审批意见输入 */}
|
||||
<textarea
|
||||
data-testid="approval-comment"
|
||||
className="input"
|
||||
style={{ width: '100%', minHeight: 64, resize: 'vertical', boxSizing: 'border-box' }}
|
||||
placeholder="审批意见(选填)"
|
||||
value={comment}
|
||||
onChange={(e) => setComment(e.target.value)}
|
||||
disabled={submitting}
|
||||
/>
|
||||
|
||||
{/* 操作按钮行 */}
|
||||
<div style={{ display: 'flex', gap: 8, alignItems: 'center' }}>
|
||||
<button
|
||||
data-testid="btn-agree"
|
||||
className="btn btn-primary"
|
||||
onClick={() => handleComplete('agree')}
|
||||
disabled={submitting}
|
||||
>
|
||||
{submitting ? '处理中…' : '同意'}
|
||||
</button>
|
||||
<button
|
||||
data-testid="btn-reject"
|
||||
className="btn"
|
||||
style={{ background: 'var(--err-soft, #fff5f5)', color: 'var(--err)', borderColor: 'var(--err)' }}
|
||||
onClick={() => handleComplete('reject')}
|
||||
disabled={submitting}
|
||||
>
|
||||
驳回
|
||||
</button>
|
||||
<button
|
||||
data-testid="btn-transfer"
|
||||
className="btn"
|
||||
onClick={() => setShowDelegate(true)}
|
||||
disabled={submitting}
|
||||
>
|
||||
转办
|
||||
</button>
|
||||
{processInstanceId && (
|
||||
<button
|
||||
data-testid="btn-trace"
|
||||
className="btn btn-text"
|
||||
style={{ marginLeft: 'auto' }}
|
||||
onClick={openTrace}
|
||||
>
|
||||
流程轨迹
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 流程轨迹抽屉 */}
|
||||
{showTrace && (
|
||||
<Drawer title="流程轨迹" width={400} onClose={() => setShowTrace(false)}>
|
||||
{traceLoading ? (
|
||||
<div style={{ color: 'var(--text-3)', padding: 16 }}>加载中…</div>
|
||||
) : (
|
||||
<TraceTimeline nodes={traceNodes} />
|
||||
)}
|
||||
</Drawer>
|
||||
)}
|
||||
|
||||
{/* 转办弹窗——用 Drawer 轻量实现 */}
|
||||
{showDelegate && (
|
||||
<Drawer title="转办" width={360} onClose={() => setShowDelegate(false)}>
|
||||
<DelegateForm
|
||||
taskId={taskId}
|
||||
onSuccess={() => {
|
||||
setShowDelegate(false);
|
||||
if (onCompleted) onCompleted();
|
||||
}}
|
||||
onCancel={() => setShowDelegate(false)}
|
||||
/>
|
||||
</Drawer>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -5,12 +5,13 @@
|
||||
// - 已办:GET /api/done,同样支持关键字筛选
|
||||
// - 批量操作:后端暂无批量端点,不做(不发明假按钮)
|
||||
// - pageUrl 字段:P4-6 已实现映射,优先使用;缺失时按 businessTable 推算
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { fetchTodo, type TodoItem } from '../api/todo';
|
||||
import { fetchDone, type DoneItem } from '../api/done';
|
||||
import { Pagination } from '../components/ui/Pagination';
|
||||
import { Icon } from '../components/ui/Icon';
|
||||
import { ApprovalBar } from '../components/ApprovalBar';
|
||||
|
||||
const PAGE_SIZE = 20;
|
||||
|
||||
@@ -29,7 +30,7 @@ function summarize(it: TodoItem | DoneItem): string {
|
||||
// ---------------------------------------------------------------------------
|
||||
// 待办列表
|
||||
// ---------------------------------------------------------------------------
|
||||
function TodoList() {
|
||||
function TodoList({ onRefresh }: { onRefresh?: () => void }) {
|
||||
const navigate = useNavigate();
|
||||
const [allItems, setAllItems] = useState<TodoItem[]>([]);
|
||||
const [unavailable, setUnavailable] = useState(false);
|
||||
@@ -38,8 +39,10 @@ function TodoList() {
|
||||
const [error, setError] = useState('');
|
||||
const [keyword, setKeyword] = useState('');
|
||||
const [page, setPage] = useState(1);
|
||||
// 当前展开办理的 taskId(null = 收起)
|
||||
const [expandedTaskId, setExpandedTaskId] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const load = useCallback(() => {
|
||||
let alive = true;
|
||||
setLoading(true);
|
||||
setError('');
|
||||
@@ -55,6 +58,10 @@ function TodoList() {
|
||||
return () => { alive = false; };
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
return load();
|
||||
}, [load]);
|
||||
|
||||
// 关键字本地过滤(taskName / businessTable 均参与)
|
||||
const filtered = keyword
|
||||
? allItems.filter(
|
||||
@@ -143,53 +150,81 @@ function TodoList() {
|
||||
</td>
|
||||
</tr>
|
||||
) : (
|
||||
pageItems.map((it, idx) => (
|
||||
<tr
|
||||
key={it.taskId ?? idx}
|
||||
style={{ cursor: 'pointer' }}
|
||||
onClick={() => openBusiness(it)}
|
||||
>
|
||||
<td>
|
||||
<span className="tag tag-info">
|
||||
{it.businessTable ? String(it.businessTable).slice(0, 8) : '待办'}
|
||||
</span>
|
||||
</td>
|
||||
<td style={{ maxWidth: 300 }}>
|
||||
<span
|
||||
style={{
|
||||
overflow: 'hidden',
|
||||
textOverflow: 'ellipsis',
|
||||
whiteSpace: 'nowrap',
|
||||
display: 'block',
|
||||
}}
|
||||
pageItems.map((it, idx) => {
|
||||
const taskId = it.taskId ?? String(idx);
|
||||
const isExpanded = expandedTaskId === taskId;
|
||||
return (
|
||||
<>
|
||||
<tr
|
||||
key={taskId}
|
||||
data-testid={`todo-row-${taskId}`}
|
||||
style={{ cursor: 'pointer' }}
|
||||
onClick={() => openBusiness(it)}
|
||||
>
|
||||
{it.taskName || '(无标题)'}
|
||||
</span>
|
||||
</td>
|
||||
<td
|
||||
style={{
|
||||
color: 'var(--text-2)',
|
||||
overflow: 'hidden',
|
||||
textOverflow: 'ellipsis',
|
||||
whiteSpace: 'nowrap',
|
||||
maxWidth: 200,
|
||||
}}
|
||||
>
|
||||
{summarize(it)}
|
||||
</td>
|
||||
<td className="muted">
|
||||
{it.createTime ? String(it.createTime).slice(0, 16) : '-'}
|
||||
</td>
|
||||
<td>
|
||||
<button
|
||||
className="btn btn-text"
|
||||
onClick={(e) => { e.stopPropagation(); openBusiness(it); }}
|
||||
>
|
||||
办理
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))
|
||||
<td>
|
||||
<span className="tag tag-info">
|
||||
{it.businessTable ? String(it.businessTable).slice(0, 8) : '待办'}
|
||||
</span>
|
||||
</td>
|
||||
<td style={{ maxWidth: 300 }}>
|
||||
<span
|
||||
style={{
|
||||
overflow: 'hidden',
|
||||
textOverflow: 'ellipsis',
|
||||
whiteSpace: 'nowrap',
|
||||
display: 'block',
|
||||
}}
|
||||
>
|
||||
{it.taskName || '(无标题)'}
|
||||
</span>
|
||||
</td>
|
||||
<td
|
||||
style={{
|
||||
color: 'var(--text-2)',
|
||||
overflow: 'hidden',
|
||||
textOverflow: 'ellipsis',
|
||||
whiteSpace: 'nowrap',
|
||||
maxWidth: 200,
|
||||
}}
|
||||
>
|
||||
{summarize(it)}
|
||||
</td>
|
||||
<td className="muted">
|
||||
{it.createTime ? String(it.createTime).slice(0, 16) : '-'}
|
||||
</td>
|
||||
<td>
|
||||
<button
|
||||
className="btn btn-text"
|
||||
data-testid={`btn-approve-${taskId}`}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
setExpandedTaskId(isExpanded ? null : taskId);
|
||||
}}
|
||||
>
|
||||
{isExpanded ? '收起' : '办理'}
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
{isExpanded && it.taskId && (
|
||||
<tr key={`${taskId}-bar`} data-testid={`approval-row-${taskId}`}>
|
||||
<td colSpan={5} style={{ padding: 0, background: 'var(--bg-2)' }}>
|
||||
<ApprovalBar
|
||||
taskId={it.taskId}
|
||||
processInstanceId={it.processInstanceId as string | undefined}
|
||||
businessKey={it.businessKey}
|
||||
tableName={it.businessTable as string | undefined}
|
||||
onCompleted={() => {
|
||||
setExpandedTaskId(null);
|
||||
load();
|
||||
if (onRefresh) onRefresh();
|
||||
}}
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
})
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -413,7 +448,7 @@ export function TodoPage() {
|
||||
</div>
|
||||
|
||||
{/* Tab 内容 */}
|
||||
{tab === 'todo' && <TodoList />}
|
||||
{tab === 'todo' && <TodoList onRefresh={() => setTab('todo')} />}
|
||||
{tab === 'done' && <DoneList />}
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user