diff --git a/src/executor/tools/task/instance/history/index.tsx b/src/executor/tools/task/instance/history/index.tsx index bbc19635cb231ca260b168bfe6111bebf761fe62..4ea52c4e96cc6d294d7beaf63461ed214e71b5d3 100644 --- a/src/executor/tools/task/instance/history/index.tsx +++ b/src/executor/tools/task/instance/history/index.tsx @@ -38,6 +38,22 @@ interface AllTask extends schema.XWorkTask { task: IWorkTask; } +const globalState = { + isSendInfo: false, + listeners: new Set<(value: boolean) => void>(), + + set(value: any) { + this.isSendInfo = value; + this.listeners.forEach((listener) => listener(value)); + }, + + subscribe(listener: any) { + this.listeners.add(listener); + listener(this.isSendInfo); + return () => this.listeners.delete(listener); + }, +}; + export const ApprovalHistory: React.FC<{ current: IWorkTask; instance: schema.XWorkInstance; @@ -69,14 +85,21 @@ export const ApprovalHistory: React.FC<{ return _tasks; }, [current]); - let isSendInfo = false; + const [isSendInfo, setIsSendInfo] = useState(false); useEffect(() => { - const id = controller?.subscribe((type, flag_, _: any, tag: string) => { + setIsSendInfo(globalState.isSendInfo); + + const unsubscribe = globalState.subscribe((value: any) => { + setIsSendInfo(value); + }); + const commandId = controller?.subscribe((type, flag_, _: any, tag: string) => { if (type != 'preview' || flag_ != 'work') return; - isSendInfo = tag === '已发起'; + const newValue = tag === '已发起'; + globalState.set(newValue); }); return () => { - controller?.unsubscribe(id); + unsubscribe(); + command.unsubscribe(commandId); }; }, []);