fix(web): support approval history drawer

This commit is contained in:
2026-06-18 02:12:49 +08:00
parent 16393c183c
commit d03c2ba156
6 changed files with 114 additions and 19 deletions

View File

@@ -2,7 +2,7 @@ export const OPEN_APPROVAL_DRAWER_EVENT = 'eip4:open-approval-drawer';
export const APPROVAL_COMPLETED_EVENT = 'eip4:approval-completed';
export interface ApprovalDrawerRequest {
taskId: string;
taskId?: string;
taskName?: string;
processInstanceId?: string;
businessKey?: string;

View File

@@ -67,7 +67,43 @@ describe('registerApprovalAction', () => {
});
});
it('缺 taskId 时不派发事件', async () => {
it('缺 taskId 但有 businessKey 时仍派发只读历史审批事件', async () => {
let captured: RunCtx | null = null;
registerApprovalAction({
registerAction: (_type: string, action: RunCtx) => {
captured = action;
},
});
const seen: unknown[] = [];
const listener = (event: Event) => {
seen.push((event as CustomEvent).detail);
};
window.addEventListener(OPEN_APPROVAL_DRAWER_EVENT, listener);
try {
await captured!.run({
args: {
taskName: '审批详情',
businessKey: 'biz-1',
businessTable: 'PM_DEMO',
readOnly: true,
},
}, {}, {});
} finally {
window.removeEventListener(OPEN_APPROVAL_DRAWER_EVENT, listener);
}
expect(seen).toHaveLength(1);
expect(seen[0]).toEqual({
taskId: undefined,
taskName: '审批详情',
processInstanceId: undefined,
businessKey: 'biz-1',
businessTable: 'PM_DEMO',
businessSummary: undefined,
readOnly: true,
});
});
it('缺 taskId/businessKey/processInstanceId 时不派发事件', async () => {
let captured: RunCtx | null = null;
registerApprovalAction({
registerAction: (_type: string, action: RunCtx) => {

View File

@@ -57,14 +57,16 @@ export function registerApprovalAction(amisCore: AmisCore | undefined | null): b
async run(action: OpenApprovalActionArg, _renderer: AmisRenderer, _event: AmisEvent) {
const args = action?.args ?? {};
const taskId = asString(args.taskId);
if (!taskId) return;
const processInstanceId = asString(args.processInstanceId);
const businessKey = asString(args.businessKey);
if (!taskId && !processInstanceId && !businessKey) return;
const mode = asString(args.mode);
const detail: ApprovalDrawerRequest = {
taskId,
taskName: asString(args.taskName),
processInstanceId: asString(args.processInstanceId),
businessKey: asString(args.businessKey),
processInstanceId,
businessKey,
businessTable: asString(args.businessTable),
businessSummary: asRecord(args.businessSummary),
readOnly: asBoolean(args.readOnly) || asBoolean(args.readonly) || mode === 'read',