diff --git a/src/api/workflow/instance/index.ts b/src/api/workflow/instance/index.ts index 78dab38f..504de38d 100644 --- a/src/api/workflow/instance/index.ts +++ b/src/api/workflow/instance/index.ts @@ -76,9 +76,10 @@ export function updateVariable(data: { instanceId?: string | number; key?: strin }); } -export function flowHisTaskList(businessId: string | number) { +export function flowHisTaskList(ids: { businessId?: string | number; instanceId?: string | number }) { return request>({ - url: `/workflow/instance/flowHisTaskList/${businessId}?t=${Math.random()}`, - method: 'get' + url: '/workflow/instance/flowHisTaskList', + method: 'get', + params: ids }); } diff --git a/src/api/workflow/workflowCommon/index.ts b/src/api/workflow/workflowCommon/index.ts index bdd57d30..8654fdf7 100644 --- a/src/api/workflow/workflowCommon/index.ts +++ b/src/api/workflow/workflowCommon/index.ts @@ -3,12 +3,14 @@ import { normalizePath } from '@/utils/ruoyi'; import type { RouterJumpVO } from './types'; export function routerJump(routerJump: RouterJumpVO) { + const query = new URLSearchParams({ + type: routerJump.type, + taskId: String(routerJump.taskId) + }); + if (routerJump.businessId) query.set('id', routerJump.businessId); + if (routerJump.instanceId != null) query.set('instanceId', String(routerJump.instanceId)); history.push( - `${normalizePath(routerJump.formPath || '/workflow/leaveEdit/index')}?${new URLSearchParams({ - id: routerJump.businessId, - type: routerJump.type, - taskId: String(routerJump.taskId) - }).toString()}` + `${normalizePath(routerJump.formPath || '/workflow/leaveEdit/index')}?${query.toString()}` ); } diff --git a/src/api/workflow/workflowCommon/types.ts b/src/api/workflow/workflowCommon/types.ts index ec9007ce..34cb4ef2 100644 --- a/src/api/workflow/workflowCommon/types.ts +++ b/src/api/workflow/workflowCommon/types.ts @@ -1,5 +1,6 @@ export interface RouterJumpVO { businessId: string; + instanceId?: string | number; taskId: string | number; type: string; formCustom: string; diff --git a/src/components/workflow/ApprovalButton.tsx b/src/components/workflow/ApprovalButton.tsx index 8cc1fd97..64e99d24 100644 --- a/src/components/workflow/ApprovalButton.tsx +++ b/src/components/workflow/ApprovalButton.tsx @@ -7,6 +7,8 @@ interface ApprovalButtonProps { status?: string; pageType: ApprovalPageType; id?: string | number; + businessId?: string | number; + instanceId?: string | number; buttonLoading?: boolean; onSubmitDraft: () => void; onSubmit: () => void; @@ -19,6 +21,8 @@ export default function ApprovalButton({ status, pageType, id, + businessId, + instanceId, buttonLoading = false, onSubmitDraft, onSubmit, @@ -29,7 +33,7 @@ export default function ApprovalButton({ const submitButtonShow = pageType === 'add' || (pageType === 'update' && !!status && ['draft', 'cancel', 'back'].includes(status)); const approvalButtonShow = pageType === 'approval' && status === 'waiting'; - const approvalRecordShow = !!id && status !== 'draft'; + const approvalRecordShow = !!(id || businessId || instanceId) && status !== 'draft'; return (
diff --git a/src/components/workflow/ApprovalRecord.tsx b/src/components/workflow/ApprovalRecord.tsx index a2d1ded3..e18b0af9 100644 --- a/src/components/workflow/ApprovalRecord.tsx +++ b/src/components/workflow/ApprovalRecord.tsx @@ -15,18 +15,19 @@ import UserNameDisplay from './UserNameDisplay'; interface ApprovalRecordProps { businessId?: string | number; + instanceId?: string | number; open: boolean; onOpenChange: (open: boolean) => void; width?: string | number; } -export default function ApprovalRecord({ businessId, open, onOpenChange, width = '80%' }: ApprovalRecordProps) { +export default function ApprovalRecord({ businessId, instanceId, open, onOpenChange, width = '80%' }: ApprovalRecordProps) { const dicts = useDict('wf_task_status'); const [recordList, setRecordList] = useState([]); - const [instanceId, setInstanceId] = useState(); + const [recordInstanceId, setRecordInstanceId] = useState(); const { loading, runAsync: loadRecords } = useRequest( - async (nextBusinessId: string | number) => { - const res = await flowHisTaskList(nextBusinessId); + async (ids: { businessId?: string | number; instanceId?: string | number }) => { + const res = await flowHisTaskList(ids); const rows = res.data?.list || []; const nextRows = await Promise.all( rows.map(async row => { @@ -47,17 +48,17 @@ export default function ApprovalRecord({ businessId, open, onOpenChange, width = manual: true, onSuccess: data => { setRecordList(data.rows); - setInstanceId(data.instanceId); + setRecordInstanceId(data.instanceId); } } ); // 打开时清空旧数据并加载 打开弹窗同步外部状态属于合理场景 - const resetAndLoad = useCallback(async (nextBusinessId?: string | number) => { + const resetAndLoad = useCallback(async (nextBusinessId?: string | number, nextInstanceId?: string | number) => { setRecordList([]); - setInstanceId(undefined); - if (nextBusinessId) { - await loadRecords(nextBusinessId); + setRecordInstanceId(undefined); + if (nextBusinessId || nextInstanceId) { + await loadRecords({ businessId: nextBusinessId, instanceId: nextInstanceId }); } }, [loadRecords]); @@ -65,8 +66,8 @@ export default function ApprovalRecord({ businessId, open, onOpenChange, width = if (!open) return; // 打开弹窗时同步清空旧数据属于与外部状态对齐的合理场景 // oxlint-disable-next-line react/set-state-in-effect - void resetAndLoad(businessId); - }, [businessId, open, resetAndLoad]); + void resetAndLoad(businessId, instanceId); + }, [businessId, instanceId, open, resetAndLoad]); const downloadAttachment = async (row: OssVO) => { const blob = await downloadOss(row.ossId); @@ -153,7 +154,7 @@ export default function ApprovalRecord({ businessId, open, onOpenChange, width = label: '流程图', children: ( - + ) }, diff --git a/src/pages/workflow/leave/leaveEdit.tsx b/src/pages/workflow/leave/leaveEdit.tsx index b3af864b..f25cb600 100644 --- a/src/pages/workflow/leave/leaveEdit.tsx +++ b/src/pages/workflow/leave/leaveEdit.tsx @@ -38,6 +38,7 @@ export default function WorkflowLeaveEditPage() { const query = useMemo(() => new URLSearchParams(location.search), [location.search]); const pageType = (query.get('type') || 'add') as PageType; const id = query.get('id'); + const instanceId = query.get('instanceId') || undefined; const taskId = query.get('taskId') || ''; const readonly = pageType === 'view'; const [flowCode, setFlowCode] = useState(''); @@ -117,7 +118,7 @@ export default function WorkflowLeaveEditPage() { }; const openApprovalRecord = () => { - if (!formId) return; + if (!id && !formId && !instanceId) return; openRecordModal(); }; @@ -182,6 +183,8 @@ export default function WorkflowLeaveEditPage() { status={formStatus} pageType={pageType} id={formId} + businessId={id || undefined} + instanceId={instanceId} buttonLoading={submitLoading} onSubmitDraft={() => saveLeave()} onSubmit={submitFlow} @@ -233,7 +236,7 @@ export default function WorkflowLeaveEditPage() { onSubmitted={finishWorkflowAction} /> - + ); } diff --git a/src/pages/workflow/processInstance/index.tsx b/src/pages/workflow/processInstance/index.tsx index ca760faa..3c6d6b8b 100644 --- a/src/pages/workflow/processInstance/index.tsx +++ b/src/pages/workflow/processInstance/index.tsx @@ -51,6 +51,7 @@ function requestInstanceList(tab: InstanceTab, query: FlowInstanceQuery): Promis function openBusinessForm(row: FlowInstanceVO) { workflowCommon.routerJump({ businessId: row.businessId, + instanceId: row.id, taskId: row.id, type: 'view', formCustom: row.formCustom || 'N',