feat(approval): ApprovalBar→ApprovalDrawer 抽屉重设计;e2e/artifacts 不入库
- 新增 ApprovalDrawer(业务表单+轨迹+动态按钮),删除旧 ApprovalBar - approval.ts 增审批上下文接口;Dialog/TodoPage 接线 - .gitignore 排除 e2e/artifacts 测试重跑产物(取消跟踪 72 张截图) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -51,3 +51,63 @@ export async function fetchTrace(processInstanceId: string): Promise<TraceNode[]
|
||||
);
|
||||
return Array.isArray(data) ? data : [];
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// WfTemplate 驱动审批 —— 动态按钮 + 业务表单 + 按 type 分派
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/** WfTemplate 解析出的审批按钮(label/type 随节点定制,不写死)。 */
|
||||
export interface ApprovalButton {
|
||||
id: string;
|
||||
label: string;
|
||||
/** approve | reject | reback | agent | assist | circulated */
|
||||
type: string;
|
||||
servicename?: string | null;
|
||||
}
|
||||
|
||||
/** GET /api/task/{id}/approval-meta 返回:审批界面的全部数据驱动元数据。 */
|
||||
export interface ApprovalMeta {
|
||||
found: boolean;
|
||||
taskId: string;
|
||||
taskName?: string | null;
|
||||
formKey?: string | null;
|
||||
buttons: ApprovalButton[];
|
||||
/** wftemplate=模板驱动 / default=无模板回退默认按钮 */
|
||||
buttonsSource: 'wftemplate' | 'default';
|
||||
loadScript?: string | null;
|
||||
showsend: boolean;
|
||||
businessKey?: string | null;
|
||||
businessTable?: string | null;
|
||||
/** 业务表友好中文名(sys_entity.name,如「施工方案审批」);展示用,避免显裸表名。 */
|
||||
businessTableName?: string | null;
|
||||
processInstanceId?: string | null;
|
||||
/** 业务单据 amis schema 模板 id(仅当 WfTemplate pageid 在 sys_page_schema 有 schema 时有值)。 */
|
||||
formTemplateId?: string | null;
|
||||
ended: boolean;
|
||||
suspended: boolean;
|
||||
}
|
||||
|
||||
/** POST /api/task/{id}/action 请求。 */
|
||||
export interface ApprovalActionRequest {
|
||||
actionType: string;
|
||||
/** WfTemplate 按钮 id:后端据此重解析该按钮的 servicename(自定义服务流)并执行。 */
|
||||
buttonId?: string;
|
||||
comment?: string;
|
||||
targetUserId?: string;
|
||||
businessKey?: string;
|
||||
processInstanceId?: string;
|
||||
tableName?: string;
|
||||
}
|
||||
|
||||
export async function fetchApprovalMeta(taskId: string): Promise<ApprovalMeta> {
|
||||
const { data } = await http.get<ApprovalMeta>(`/api/task/${taskId}/approval-meta`);
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function submitApprovalAction(
|
||||
taskId: string,
|
||||
req: ApprovalActionRequest,
|
||||
): Promise<Record<string, unknown>> {
|
||||
const { data } = await http.post<Record<string, unknown>>(`/api/task/${taskId}/action`, req);
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -1,309 +0,0 @@
|
||||
// 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>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
392
src/components/ApprovalDrawer.tsx
Normal file
392
src/components/ApprovalDrawer.tsx
Normal file
@@ -0,0 +1,392 @@
|
||||
// ApprovalDrawer —— 待办审批办理(右侧抽屉,WfTemplate 数据驱动)
|
||||
// ----------------------------------------------------------------------------
|
||||
// 重设计:点「办理」从右侧滑出抽屉,承载完整审批:
|
||||
// 上 = 业务单据(只读,统一 editform schema + 保真层 LOAD 流/实体数据,带中文标签)
|
||||
// 中 = 流程轨迹时间线
|
||||
// 下(footer)= 审批意见 + WfTemplate 动态按钮(label/type 随节点定制)
|
||||
// 数据驱动元数据来自 GET /api/task/{id}/approval-meta;办理走 POST /api/task/{id}/action(按 type 分派)。
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Drawer } from './ui/Dialog';
|
||||
import { toast } from './ui/Toast';
|
||||
import { AmisRenderer } from './AmisRenderer';
|
||||
import { http } from '../api/http';
|
||||
import { delegateTask, fetchTrace, fetchApprovalMeta, submitApprovalAction } from '../api/approval';
|
||||
import type { TraceNode, ApprovalMeta, ApprovalButton } from '../api/approval';
|
||||
|
||||
export interface ApprovalDrawerProps {
|
||||
taskId: string;
|
||||
taskName?: string;
|
||||
processInstanceId?: string;
|
||||
businessKey?: string;
|
||||
businessTable?: string;
|
||||
/** 业务摘要标题字段(无可渲染 schema 时的极简降级展示)。 */
|
||||
businessSummary?: Record<string, unknown>;
|
||||
onClose: () => void;
|
||||
/** 办理成功后回调(刷新待办列表/铃铛)。 */
|
||||
onCompleted: () => void;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 按钮 type → 视觉样式(颜色由语义定,label 仍用模板定制文案)
|
||||
// ---------------------------------------------------------------------------
|
||||
function buttonClass(type: string): { className: string; style?: React.CSSProperties } {
|
||||
switch (type) {
|
||||
case 'approve':
|
||||
return { className: 'btn btn-primary' };
|
||||
case 'reject':
|
||||
return {
|
||||
className: 'btn',
|
||||
style: { background: 'var(--err-soft, #fff5f5)', color: 'var(--err)', borderColor: 'var(--err)' },
|
||||
};
|
||||
case 'reback':
|
||||
return {
|
||||
className: 'btn',
|
||||
style: { background: 'var(--warn-soft, #fff8f0)', color: 'var(--warn)', borderColor: 'var(--warn)' },
|
||||
};
|
||||
default:
|
||||
return { className: 'btn' };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 把页面 amis schema 包成只读业务单据。
|
||||
* 数据源统一走网关 `GET /api/task/{taskId}/business-data`:后端按 WfTemplate `<load>` 服务流载入
|
||||
* (含子表、引用列 id→名,对齐老审批页),4s 超时硬上限防挂死、超时退化 loadPOJO。前端无需关心 load/entity 之分。
|
||||
* 返回 amis 单记录契约 {status:0,data:{...record}},表单字段(name=列名)直接绑定。
|
||||
*/
|
||||
function buildReadonlyForm(rawSchema: unknown, taskId: string): Record<string, unknown> | null {
|
||||
if (!rawSchema || typeof rawSchema !== 'object') return null;
|
||||
const obj = rawSchema as Record<string, unknown>;
|
||||
const inner = (obj.body && typeof obj.body === 'object' ? obj.body : obj) as Record<string, unknown>;
|
||||
return {
|
||||
type: 'service',
|
||||
api: `get:/api/task/${taskId}/business-data`,
|
||||
body: { ...inner, static: true, actions: [], submitText: '' },
|
||||
};
|
||||
}
|
||||
|
||||
/** 从动作接口错误里取后端友好消息(400/422 带 {msg}),否则给通用文案。 */
|
||||
function actionErrMsg(e: unknown, label: string): string {
|
||||
const resp = (e as { response?: { data?: { msg?: string } } })?.response;
|
||||
return resp?.data?.msg || `${label || '办理'}失败,请重试`;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 流程轨迹时间线
|
||||
// ---------------------------------------------------------------------------
|
||||
function TraceTimeline({ nodes }: { nodes: TraceNode[] }) {
|
||||
if (nodes.length === 0) {
|
||||
return (
|
||||
<div style={{ color: 'var(--text-3)', padding: '16px 0', textAlign: 'center', fontSize: 'var(--fs-sm)' }}>
|
||||
暂无轨迹记录
|
||||
</div>
|
||||
);
|
||||
}
|
||||
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)' },
|
||||
reback: { text: '退回', color: 'var(--warn)' },
|
||||
transfer: { text: '转办', color: 'var(--warn)' },
|
||||
complete: { text: '完成', color: 'var(--ok)' },
|
||||
};
|
||||
return (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 0 }}>
|
||||
{nodes.map((node, idx) => {
|
||||
const isLast = idx === nodes.length - 1;
|
||||
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: 20, margin: '2px 0' }} />}
|
||||
</div>
|
||||
<div style={{ paddingBottom: isLast ? 0 : 16, flex: 1, minWidth: 0 }}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' }}>
|
||||
<span style={{ fontWeight: 600, fontSize: 'var(--fs-sm)' }}>{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>
|
||||
);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 主组件:ApprovalDrawer
|
||||
// ---------------------------------------------------------------------------
|
||||
export function ApprovalDrawer({
|
||||
taskId,
|
||||
taskName,
|
||||
processInstanceId,
|
||||
businessKey,
|
||||
businessTable,
|
||||
businessSummary,
|
||||
onClose,
|
||||
onCompleted,
|
||||
}: ApprovalDrawerProps) {
|
||||
const [meta, setMeta] = useState<ApprovalMeta | null>(null);
|
||||
const [metaLoading, setMetaLoading] = useState(true);
|
||||
const [formSchema, setFormSchema] = useState<Record<string, unknown> | null>(null);
|
||||
const [formLoading, setFormLoading] = useState(false);
|
||||
const [comment, setComment] = useState('');
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
const [traceNodes, setTraceNodes] = useState<TraceNode[]>([]);
|
||||
const [traceLoading, setTraceLoading] = useState(false);
|
||||
const [showDelegate, setShowDelegate] = useState(false);
|
||||
|
||||
// 审批元数据(按钮/脚本/业务表单全来自 WfTemplate)
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
setMetaLoading(true);
|
||||
fetchApprovalMeta(taskId)
|
||||
.then((m) => alive && setMeta(m))
|
||||
.catch(() => alive && setMeta(null))
|
||||
.finally(() => alive && setMetaLoading(false));
|
||||
return () => { alive = false; };
|
||||
}, [taskId]);
|
||||
|
||||
// 流程轨迹
|
||||
useEffect(() => {
|
||||
if (!processInstanceId) return;
|
||||
let alive = true;
|
||||
setTraceLoading(true);
|
||||
fetchTrace(processInstanceId)
|
||||
.then((n) => alive && setTraceNodes(n))
|
||||
.catch(() => alive && setTraceNodes([]))
|
||||
.finally(() => alive && setTraceLoading(false));
|
||||
return () => { alive = false; };
|
||||
}, [processInstanceId]);
|
||||
|
||||
// 业务单据只读表单(统一 editform schema;数据走 /api/task/{id}/business-data 由后端载入)
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
const tpl = meta?.formTemplateId;
|
||||
if (tpl) {
|
||||
setFormLoading(true);
|
||||
http
|
||||
.get(`/api/page/schema/${tpl}`)
|
||||
.then((res) => {
|
||||
if (!alive) return;
|
||||
const raw = typeof res.data === 'string' ? JSON.parse(res.data) : res.data;
|
||||
setFormSchema(buildReadonlyForm(raw, taskId));
|
||||
})
|
||||
.catch(() => alive && setFormSchema(null))
|
||||
.finally(() => alive && setFormLoading(false));
|
||||
} else {
|
||||
setFormSchema(null);
|
||||
}
|
||||
return () => { alive = false; };
|
||||
}, [meta, taskId]);
|
||||
|
||||
const handleAction = async (btn: ApprovalButton) => {
|
||||
if (btn.type === 'agent') {
|
||||
setShowDelegate(true);
|
||||
return;
|
||||
}
|
||||
setSubmitting(true);
|
||||
try {
|
||||
await submitApprovalAction(taskId, {
|
||||
actionType: btn.type,
|
||||
buttonId: btn.id,
|
||||
comment: comment.trim() || undefined,
|
||||
businessKey,
|
||||
processInstanceId,
|
||||
tableName: meta?.businessTable ?? businessTable,
|
||||
});
|
||||
toast(`已${btn.label || '办理'}`);
|
||||
onCompleted();
|
||||
} catch (e) {
|
||||
toast(actionErrMsg(e, btn.label), 'err');
|
||||
} finally {
|
||||
setSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
const buttons = meta?.buttons ?? [];
|
||||
const hasSummary = businessSummary && Object.keys(businessSummary).length > 0;
|
||||
// 显示用:友好中文名(施工方案审批)优先;无则不显裸表名,只显「业务单据」
|
||||
const tableLabel = meta?.businessTableName ?? undefined;
|
||||
|
||||
const footer = (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 10, width: '100%' }}>
|
||||
<textarea
|
||||
data-testid="approval-comment"
|
||||
className="input"
|
||||
style={{ width: '100%', minHeight: 56, resize: 'vertical', boxSizing: 'border-box' }}
|
||||
placeholder="审批意见(选填)"
|
||||
value={comment}
|
||||
onChange={(e) => setComment(e.target.value)}
|
||||
disabled={submitting}
|
||||
/>
|
||||
<div style={{ display: 'flex', gap: 8, alignItems: 'center', flexWrap: 'wrap' }}>
|
||||
{metaLoading ? (
|
||||
<span style={{ color: 'var(--text-3)', fontSize: 'var(--fs-sm)' }}>加载审批动作…</span>
|
||||
) : (
|
||||
buttons.map((btn) => {
|
||||
const s = buttonClass(btn.type);
|
||||
return (
|
||||
<button
|
||||
key={btn.id}
|
||||
data-testid={`btn-action-${btn.type}`}
|
||||
className={s.className}
|
||||
style={s.style}
|
||||
onClick={() => handleAction(btn)}
|
||||
disabled={submitting}
|
||||
title={btn.servicename ? `服务流: ${btn.servicename}` : undefined}
|
||||
>
|
||||
{submitting ? '处理中…' : btn.label || btn.type}
|
||||
</button>
|
||||
);
|
||||
})
|
||||
)}
|
||||
{meta?.buttonsSource === 'default' && !metaLoading && (
|
||||
<span style={{ color: 'var(--warn)', fontSize: 11 }} title="该任务无 WfTemplate 或 formKey,回退默认按钮">
|
||||
默认按钮
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Drawer
|
||||
title={taskName || meta?.taskName || '审批办理'}
|
||||
/* 自适应宽度:表单大时给到更宽(最宽 1080px),小屏回落(最窄 600px) */
|
||||
width="clamp(600px, 58vw, 1080px)"
|
||||
onClose={onClose}
|
||||
foot={footer}
|
||||
>
|
||||
<div data-testid="approval-drawer" style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
|
||||
{/* 业务单据(只读) */}
|
||||
<section>
|
||||
<div
|
||||
style={{
|
||||
marginBottom: 8, fontSize: 'var(--fs-sm)', fontWeight: 600, color: 'var(--text-2)',
|
||||
}}
|
||||
>
|
||||
业务单据{tableLabel ? `(${tableLabel})` : ''}
|
||||
</div>
|
||||
<div style={{ border: '1px solid var(--line)', borderRadius: 'var(--radius)', overflow: 'hidden' }}>
|
||||
{formLoading || (metaLoading && !formSchema) ? (
|
||||
<div style={{ padding: 16, color: 'var(--text-3)', fontSize: 'var(--fs-sm)' }}>业务单据加载中…</div>
|
||||
) : formSchema ? (
|
||||
<div style={{ padding: 8 }}>
|
||||
<AmisRenderer schema={formSchema} />
|
||||
</div>
|
||||
) : hasSummary ? (
|
||||
// 极简降级:无可渲染 schema 时才用摘要键值(罕见)
|
||||
<div style={{ padding: '8px 10px', display: 'grid', gridTemplateColumns: 'auto 1fr', gap: '4px 12px' }}>
|
||||
{Object.entries(businessSummary!).map(([k, v]) => (
|
||||
<div key={k} style={{ display: 'contents' }}>
|
||||
<span style={{ color: 'var(--text-3)', fontSize: 'var(--fs-sm)' }}>{k}</span>
|
||||
<span style={{ fontSize: 'var(--fs-sm)', wordBreak: 'break-all' }}>{String(v ?? '-')}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<div style={{ padding: 16, color: 'var(--text-3)', fontSize: 'var(--fs-sm)' }}>
|
||||
无业务单据可展示
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* 流程轨迹 */}
|
||||
<section>
|
||||
<div style={{ fontSize: 'var(--fs-sm)', fontWeight: 600, color: 'var(--text-2)', marginBottom: 8 }}>
|
||||
流程轨迹
|
||||
</div>
|
||||
{traceLoading ? (
|
||||
<div style={{ color: 'var(--text-3)', fontSize: 'var(--fs-sm)', padding: '8px 0' }}>加载中…</div>
|
||||
) : (
|
||||
<TraceTimeline nodes={traceNodes} />
|
||||
)}
|
||||
</section>
|
||||
</div>
|
||||
</Drawer>
|
||||
|
||||
{/* 转办弹窗 */}
|
||||
{showDelegate && (
|
||||
<Drawer title="转办" width={360} onClose={() => setShowDelegate(false)}>
|
||||
<DelegateForm
|
||||
taskId={taskId}
|
||||
onSuccess={() => { setShowDelegate(false); onCompleted(); }}
|
||||
onCancel={() => setShowDelegate(false)}
|
||||
/>
|
||||
</Drawer>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -32,7 +32,8 @@ export function Dialog({ title, width = 560, onClose, children, foot }: DialogPr
|
||||
|
||||
interface DrawerProps {
|
||||
title: string;
|
||||
width?: number;
|
||||
/** 数字按 px;也可传 CSS 字符串(如 clamp(600px,60vw,1040px))做自适应宽度。 */
|
||||
width?: number | string;
|
||||
onClose: () => void;
|
||||
children: ReactNode;
|
||||
foot?: ReactNode;
|
||||
|
||||
@@ -11,7 +11,7 @@ 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';
|
||||
import { ApprovalDrawer } from '../components/ApprovalDrawer';
|
||||
|
||||
const PAGE_SIZE = 20;
|
||||
|
||||
@@ -39,8 +39,8 @@ function TodoList({ onRefresh }: { onRefresh?: () => void }) {
|
||||
const [error, setError] = useState('');
|
||||
const [keyword, setKeyword] = useState('');
|
||||
const [page, setPage] = useState(1);
|
||||
// 当前展开办理的 taskId(null = 收起)
|
||||
const [expandedTaskId, setExpandedTaskId] = useState<string | null>(null);
|
||||
// 当前办理的待办项(null = 抽屉关闭)
|
||||
const [activeItem, setActiveItem] = useState<TodoItem | null>(null);
|
||||
|
||||
const load = useCallback(() => {
|
||||
let alive = true;
|
||||
@@ -152,15 +152,13 @@ function TodoList({ onRefresh }: { onRefresh?: () => void }) {
|
||||
) : (
|
||||
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)}
|
||||
>
|
||||
<tr
|
||||
key={taskId}
|
||||
data-testid={`todo-row-${taskId}`}
|
||||
style={{ cursor: 'pointer' }}
|
||||
onClick={() => openBusiness(it)}
|
||||
>
|
||||
<td>
|
||||
<span className="tag tag-info">
|
||||
{it.businessTable ? String(it.businessTable).slice(0, 8) : '待办'}
|
||||
@@ -198,31 +196,13 @@ function TodoList({ onRefresh }: { onRefresh?: () => void }) {
|
||||
data-testid={`btn-approve-${taskId}`}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
setExpandedTaskId(isExpanded ? null : taskId);
|
||||
if (it.taskId) setActiveItem(it);
|
||||
}}
|
||||
>
|
||||
{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>
|
||||
)}
|
||||
</>
|
||||
</tr>
|
||||
);
|
||||
})
|
||||
)}
|
||||
@@ -234,6 +214,24 @@ function TodoList({ onRefresh }: { onRefresh?: () => void }) {
|
||||
{!loading && !unavailable && !error && filtered.length > PAGE_SIZE && (
|
||||
<Pagination total={filtered.length} page={safePage} pageSize={PAGE_SIZE} onPage={setPage} />
|
||||
)}
|
||||
|
||||
{/* 审批办理抽屉(WfTemplate 数据驱动:业务单据 + 轨迹 + 动态按钮) */}
|
||||
{activeItem?.taskId && (
|
||||
<ApprovalDrawer
|
||||
taskId={activeItem.taskId}
|
||||
taskName={activeItem.taskName as string | undefined}
|
||||
processInstanceId={activeItem.processInstanceId as string | undefined}
|
||||
businessKey={activeItem.businessKey}
|
||||
businessTable={activeItem.businessTable as string | undefined}
|
||||
businessSummary={activeItem.businessSummary}
|
||||
onClose={() => setActiveItem(null)}
|
||||
onCompleted={() => {
|
||||
setActiveItem(null);
|
||||
load();
|
||||
if (onRefresh) onRefresh();
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user