feat: loop notify (#1138)

Reviewed-on: daoyoucloud/tachybase#1138
This commit is contained in:
sealday 2024-06-06 16:17:04 +08:00
parent 76f5e1c640
commit 1c1a11b3d0
4 changed files with 28 additions and 5 deletions

View File

@ -38,7 +38,7 @@ export const useNoticeManager = () => {
return useContext(NoticeManagerContext); return useContext(NoticeManagerContext);
}; };
export const useNoticeSub = (name: string, handler: () => void) => { export const useNoticeSub = (name: string, handler: (...args: any) => void) => {
const { manager } = useNoticeManager(); const { manager } = useNoticeManager();
useEffect(() => { useEffect(() => {
manager.emitter.on(name, handler); manager.emitter.on(name, handler);

View File

@ -15,6 +15,7 @@ import {
import { SchemaExpressionScopeContext, useField, useFieldSchema } from '@tachybase/schema'; import { SchemaExpressionScopeContext, useField, useFieldSchema } from '@tachybase/schema';
import { App } from 'antd'; import { App } from 'antd';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom'; import { useNavigate } from 'react-router-dom';
import { lang } from '../../../locale'; import { lang } from '../../../locale';
@ -25,11 +26,12 @@ export const usePropsAPIRegular = () => {
const expressionScope = useContext(SchemaExpressionScopeContext); const expressionScope = useContext(SchemaExpressionScopeContext);
const tableBlockContext = useTableBlockContext(); const tableBlockContext = useTableBlockContext();
const { rowKey } = tableBlockContext; const { rowKey } = tableBlockContext;
const { t } = useTranslation();
const navigate = useNavigate(); const navigate = useNavigate();
const compile = useCompile(); const compile = useCompile();
const actionField: any = useField(); const actionField: any = useField();
const { modal } = App.useApp(); const { modal, notification } = App.useApp();
const variables = useVariables(); const variables = useVariables();
const record = useRecord(); const record = useRecord();
const { name, getField } = useCollection_deprecated(); const { name, getField } = useCollection_deprecated();
@ -43,8 +45,19 @@ export const usePropsAPIRegular = () => {
manual: true, manual: true,
}, },
); );
useNoticeSub('workflow:regular', () => { useNoticeSub('workflow:regular', (event) => {
service.refresh(); if (event.msg === 'start') {
notification.info({ key: 'workflow:regular', message: t('working'), description: t('starting') });
} else if (event.msg === 'progress') {
notification.info({
key: 'workflow:regular',
message: t('working'),
description: t('process') + `${event.current} / ${event.total}`,
});
} else if (event.msg === 'done') {
notification.info({ key: 'workflow:regular', message: t('working'), description: t('done') });
service.refresh();
}
}); });
return { return {

View File

@ -149,6 +149,10 @@ export class APIRegularTrigger extends Trigger {
for (const event of asyncGroup) { for (const event of asyncGroup) {
this.workflow.trigger(event[0], event[1]); this.workflow.trigger(event[0], event[1]);
} }
this.workflow.noticeManager.notify('workflow:regular', {
msg: 'start',
});
} }
on(workflow: WorkflowModel): void {} on(workflow: WorkflowModel): void {}

View File

@ -1,4 +1,4 @@
import { Processor, Instruction, JOB_STATUS, FlowNodeModel, JobModel } from '../..'; import { FlowNodeModel, Instruction, JOB_STATUS, JobModel, Processor } from '../..';
function getTargetLength(target) { function getTargetLength(target) {
let length = 0; let length = 0;
@ -93,6 +93,12 @@ export default class extends Instruction {
length, length,
}; };
this.workflow.noticeManager.notify('workflow:regular', {
msg: 'progress',
current: index,
total: length,
});
return result; return result;
} }
} }