fix(approval): wire workflow task drawer actions
This commit is contained in:
@@ -9,8 +9,10 @@
|
||||
// 此处替换为自定义 fetcher,统一注入 Bearer(由 http 拦截器完成)并复用宿主 axios,
|
||||
// 后端 /api/entity 已是 amis CRUD 格式 {status,msg,data:{items,total}},无需再适配响应。
|
||||
// ============================================================================
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { http } from '../api/http';
|
||||
import { APPROVAL_COMPLETED_EVENT } from '../amis/approvalActionEvents';
|
||||
import { registerApprovalAction } from '../amis/registerApprovalAction';
|
||||
import { registerReplayAction } from '../amis/registerReplayAction';
|
||||
import { getProfile } from '../auth/token';
|
||||
|
||||
@@ -31,6 +33,13 @@ interface AmisFetcherOptions {
|
||||
export function AmisRenderer({ schema }: AmisRendererProps) {
|
||||
const rootRef = useRef<HTMLDivElement>(null);
|
||||
const instanceRef = useRef<{ unmount?: () => void } | null>(null);
|
||||
const [reloadSeq, setReloadSeq] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
const reload = () => setReloadSeq((n) => n + 1);
|
||||
window.addEventListener(APPROVAL_COMPLETED_EVENT, reload);
|
||||
return () => window.removeEventListener(APPROVAL_COMPLETED_EVENT, reload);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!rootRef.current || typeof amisRequire !== 'function') return;
|
||||
@@ -44,6 +53,11 @@ export function AmisRenderer({ schema }: AmisRendererProps) {
|
||||
} catch {
|
||||
// amis-core 未暴露 registerAction 时静默降级(onEvent 重放不可用,不阻断渲染)
|
||||
}
|
||||
try {
|
||||
registerApprovalAction(amisRequire('amis'));
|
||||
} catch {
|
||||
// amis-core 未暴露 registerAction 时静默降级(审批抽屉入口不可用,不阻断渲染)
|
||||
}
|
||||
|
||||
// 自定义 fetcher:复用宿主 axios(已带 Bearer 注入 + 401 跳登录拦截)
|
||||
const fetcher = (options: AmisFetcherOptions) => {
|
||||
@@ -89,7 +103,7 @@ export function AmisRenderer({ schema }: AmisRendererProps) {
|
||||
instanceRef.current?.unmount?.();
|
||||
instanceRef.current = null;
|
||||
};
|
||||
}, [schema]);
|
||||
}, [schema, reloadSeq]);
|
||||
|
||||
return <div ref={rootRef} style={{ height: '100%' }} />;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ export interface ApprovalDrawerProps {
|
||||
businessTable?: string;
|
||||
/** 业务摘要标题字段(无可渲染 schema 时的极简降级展示)。 */
|
||||
businessSummary?: Record<string, unknown>;
|
||||
/** 已办/历史任务查看:只展示业务单据与轨迹,不暴露办理动作。 */
|
||||
readOnly?: boolean;
|
||||
onClose: () => void;
|
||||
/** 办理成功后回调(刷新待办列表/铃铛)。 */
|
||||
onCompleted: () => void;
|
||||
@@ -192,6 +194,7 @@ export function ApprovalDrawer({
|
||||
businessKey,
|
||||
businessTable,
|
||||
businessSummary,
|
||||
readOnly = false,
|
||||
onClose,
|
||||
onCompleted,
|
||||
}: ApprovalDrawerProps) {
|
||||
@@ -204,11 +207,17 @@ export function ApprovalDrawer({
|
||||
const [traceNodes, setTraceNodes] = useState<TraceNode[]>([]);
|
||||
const [traceLoading, setTraceLoading] = useState(false);
|
||||
const [showDelegate, setShowDelegate] = useState(false);
|
||||
const effectiveProcessInstanceId = processInstanceId ?? meta?.processInstanceId ?? undefined;
|
||||
const effectiveBusinessKey = businessKey ?? meta?.businessKey ?? undefined;
|
||||
const effectiveBusinessTable = businessTable ?? meta?.businessTable ?? undefined;
|
||||
|
||||
// 审批元数据(按钮/脚本/业务表单全来自 WfTemplate)
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
setMetaLoading(true);
|
||||
setMeta(null);
|
||||
setFormSchema(null);
|
||||
setTraceNodes([]);
|
||||
fetchApprovalMeta(taskId)
|
||||
.then((m) => alive && setMeta(m))
|
||||
.catch(() => alive && setMeta(null))
|
||||
@@ -218,15 +227,15 @@ export function ApprovalDrawer({
|
||||
|
||||
// 流程轨迹
|
||||
useEffect(() => {
|
||||
if (!processInstanceId) return;
|
||||
if (!effectiveProcessInstanceId) return;
|
||||
let alive = true;
|
||||
setTraceLoading(true);
|
||||
fetchTrace(processInstanceId)
|
||||
fetchTrace(effectiveProcessInstanceId)
|
||||
.then((n) => alive && setTraceNodes(n))
|
||||
.catch(() => alive && setTraceNodes([]))
|
||||
.finally(() => alive && setTraceLoading(false));
|
||||
return () => { alive = false; };
|
||||
}, [processInstanceId]);
|
||||
}, [effectiveProcessInstanceId]);
|
||||
|
||||
// 业务单据只读表单(统一 editform schema;数据走 /api/task/{id}/business-data 由后端载入)
|
||||
useEffect(() => {
|
||||
@@ -260,9 +269,9 @@ export function ApprovalDrawer({
|
||||
actionType: btn.type,
|
||||
buttonId: btn.id,
|
||||
comment: comment.trim() || undefined,
|
||||
businessKey,
|
||||
processInstanceId,
|
||||
tableName: meta?.businessTable ?? businessTable,
|
||||
businessKey: effectiveBusinessKey,
|
||||
processInstanceId: effectiveProcessInstanceId,
|
||||
tableName: effectiveBusinessTable,
|
||||
});
|
||||
toast(`已${btn.label || '办理'}`);
|
||||
onCompleted();
|
||||
@@ -278,7 +287,7 @@ export function ApprovalDrawer({
|
||||
// 显示用:友好中文名(施工方案审批)优先;无则不显裸表名,只显「业务单据」
|
||||
const tableLabel = meta?.businessTableName ?? undefined;
|
||||
|
||||
const footer = (
|
||||
const footer = readOnly ? undefined : (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 10, width: '100%' }}>
|
||||
<textarea
|
||||
data-testid="approval-comment"
|
||||
@@ -322,7 +331,7 @@ export function ApprovalDrawer({
|
||||
return (
|
||||
<>
|
||||
<Drawer
|
||||
title={taskName || meta?.taskName || '审批办理'}
|
||||
title={taskName || meta?.taskName || (readOnly ? '审批详情' : '审批办理')}
|
||||
/* 自适应宽度:表单大时给到更宽(最宽 1080px),小屏回落(最窄 600px) */
|
||||
width="clamp(600px, 58vw, 1080px)"
|
||||
onClose={onClose}
|
||||
|
||||
Reference in New Issue
Block a user