fix(web): support approval history drawer
This commit is contained in:
@@ -10,11 +10,19 @@ 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 {
|
||||
approvalHistoryBusinessDataApi,
|
||||
delegateTask,
|
||||
fetchApprovalHistoryMeta,
|
||||
fetchApprovalMeta,
|
||||
fetchTrace,
|
||||
fetchTraceByBusiness,
|
||||
submitApprovalAction,
|
||||
} from '../api/approval';
|
||||
import type { TraceNode, ApprovalMeta, ApprovalButton } from '../api/approval';
|
||||
|
||||
export interface ApprovalDrawerProps {
|
||||
taskId: string;
|
||||
taskId?: string;
|
||||
taskName?: string;
|
||||
processInstanceId?: string;
|
||||
businessKey?: string;
|
||||
@@ -56,13 +64,13 @@ function buttonClass(type: string): { className: string; style?: React.CSSProper
|
||||
* (含子表、引用列 id→名,对齐老审批页),4s 超时硬上限防挂死、超时退化 loadPOJO。前端无需关心 load/entity 之分。
|
||||
* 返回 amis 单记录契约 {status:0,data:{...record}},表单字段(name=列名)直接绑定。
|
||||
*/
|
||||
function buildReadonlyForm(rawSchema: unknown, taskId: string): Record<string, unknown> | null {
|
||||
function buildReadonlyForm(rawSchema: unknown, dataApi: 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`,
|
||||
api: dataApi,
|
||||
body: { ...inner, static: true, actions: [], submitText: '' },
|
||||
};
|
||||
}
|
||||
@@ -210,6 +218,11 @@ export function ApprovalDrawer({
|
||||
const effectiveProcessInstanceId = processInstanceId ?? meta?.processInstanceId ?? undefined;
|
||||
const effectiveBusinessKey = businessKey ?? meta?.businessKey ?? undefined;
|
||||
const effectiveBusinessTable = businessTable ?? meta?.businessTable ?? undefined;
|
||||
const historyParams = {
|
||||
businessKey: effectiveBusinessKey,
|
||||
processInstanceId: effectiveProcessInstanceId,
|
||||
businessTable: effectiveBusinessTable,
|
||||
};
|
||||
|
||||
// 审批元数据(按钮/脚本/业务表单全来自 WfTemplate)
|
||||
useEffect(() => {
|
||||
@@ -218,24 +231,30 @@ export function ApprovalDrawer({
|
||||
setMeta(null);
|
||||
setFormSchema(null);
|
||||
setTraceNodes([]);
|
||||
fetchApprovalMeta(taskId)
|
||||
const loader = taskId
|
||||
? fetchApprovalMeta(taskId)
|
||||
: fetchApprovalHistoryMeta({ businessKey, processInstanceId, businessTable });
|
||||
loader
|
||||
.then((m) => alive && setMeta(m))
|
||||
.catch(() => alive && setMeta(null))
|
||||
.finally(() => alive && setMetaLoading(false));
|
||||
return () => { alive = false; };
|
||||
}, [taskId]);
|
||||
}, [taskId, businessKey, processInstanceId, businessTable]);
|
||||
|
||||
// 流程轨迹
|
||||
useEffect(() => {
|
||||
if (!effectiveProcessInstanceId) return;
|
||||
if (!effectiveProcessInstanceId && !effectiveBusinessKey) return;
|
||||
let alive = true;
|
||||
setTraceLoading(true);
|
||||
fetchTrace(effectiveProcessInstanceId)
|
||||
const loader = effectiveProcessInstanceId
|
||||
? fetchTrace(effectiveProcessInstanceId)
|
||||
: fetchTraceByBusiness(effectiveBusinessKey!);
|
||||
loader
|
||||
.then((n) => alive && setTraceNodes(n))
|
||||
.catch(() => alive && setTraceNodes([]))
|
||||
.finally(() => alive && setTraceLoading(false));
|
||||
return () => { alive = false; };
|
||||
}, [effectiveProcessInstanceId]);
|
||||
}, [effectiveProcessInstanceId, effectiveBusinessKey]);
|
||||
|
||||
// 业务单据只读表单(统一 editform schema;数据走 /api/task/{id}/business-data 由后端载入)
|
||||
useEffect(() => {
|
||||
@@ -243,12 +262,15 @@ export function ApprovalDrawer({
|
||||
const tpl = meta?.formTemplateId;
|
||||
if (tpl) {
|
||||
setFormLoading(true);
|
||||
const dataApi = taskId
|
||||
? `get:/api/task/${taskId}/business-data`
|
||||
: approvalHistoryBusinessDataApi(historyParams);
|
||||
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));
|
||||
setFormSchema(buildReadonlyForm(raw, dataApi));
|
||||
})
|
||||
.catch(() => alive && setFormSchema(null))
|
||||
.finally(() => alive && setFormLoading(false));
|
||||
@@ -256,9 +278,13 @@ export function ApprovalDrawer({
|
||||
setFormSchema(null);
|
||||
}
|
||||
return () => { alive = false; };
|
||||
}, [meta, taskId]);
|
||||
}, [meta, taskId, effectiveBusinessKey, effectiveProcessInstanceId, effectiveBusinessTable]);
|
||||
|
||||
const handleAction = async (btn: ApprovalButton) => {
|
||||
if (!taskId) {
|
||||
toast('缺少任务ID,无法办理', 'warn');
|
||||
return;
|
||||
}
|
||||
if (btn.type === 'agent') {
|
||||
setShowDelegate(true);
|
||||
return;
|
||||
@@ -387,7 +413,7 @@ export function ApprovalDrawer({
|
||||
</Drawer>
|
||||
|
||||
{/* 转办弹窗 */}
|
||||
{showDelegate && (
|
||||
{showDelegate && taskId && (
|
||||
<Drawer title="转办" width={360} onClose={() => setShowDelegate(false)}>
|
||||
<DelegateForm
|
||||
taskId={taskId}
|
||||
|
||||
Reference in New Issue
Block a user