fix: plugin-approval, trigger data (#861)

Reviewed-on: daoyoucloud/tachybase#861
Co-authored-by: bai.zixv <bai.zixv@foxmail.com>
Co-committed-by: bai.zixv <bai.zixv@foxmail.com>
This commit is contained in:
bai.zixv 2024-04-26 15:41:54 +08:00 committed by sealday
parent d05ea72fb7
commit 748cfc56bc
7 changed files with 72 additions and 56 deletions

View File

@ -1,5 +1,6 @@
import { useCollectionManager_deprecated, useCompile } from '@nocobase/client';
import { SchemaInitializerItemType, useCollectionManager_deprecated, useCompile } from '@nocobase/client';
import {
CollectionBlockInitializer,
RadioWithTooltip,
Trigger,
getCollectionFieldOptions,
@ -7,7 +8,7 @@ import {
} from '@nocobase/plugin-workflow/client';
import { useForm } from '@nocobase/schema';
import { SchemaConfigButton } from './VC.ConfigButton';
import { NAMESPACE, usePluginTranslation } from '../../locale';
import { NAMESPACE, tval, usePluginTranslation } from '../../locale';
import { LauncherInterface } from './launcher-interface/VC.LauncherInterface';
// 工作流节点-审批触发器节点
@ -143,4 +144,20 @@ export class ApprovalTrigger extends Trigger {
getCollectionFields,
});
}
useInitializers(config): SchemaInitializerItemType | null {
if (!config.collection) {
return null;
}
return {
name: 'triggerData',
type: 'item',
key: 'triggerData',
title: tval('Trigger data'),
Component: CollectionBlockInitializer,
collection: config.collection,
dataPath: '$context.data',
};
}
}

View File

@ -20,30 +20,31 @@ export function useSubmit() {
const { workflow } = useFlowContext();
return {
run() {
return () => {
try {
from.submit(), (field.data = field.data || {});
field.data.loading = true;
apiClient.resource('approvals').create({
values: {
collectionName: joinCollectionName(collection.dataSource, collection.name),
data: from.values,
status: contextWe,
workflowId: workflow.id,
},
});
setVisible(false);
from.reset();
field.data.loading = false;
const service = __parent.service;
if (service) {
service.refresh();
}
} catch (h) {
field.data && (field.data.loading = false);
async run() {
try {
from.submit();
field.data = field.data || {};
field.data.loading = true;
await apiClient.resource('approvals').create({
values: {
collectionName: joinCollectionName(collection.dataSource, collection.name),
data: from.values,
status: contextWe,
workflowId: workflow.id,
},
});
setVisible(false);
from.reset();
field.data.loading = false;
const service = __parent.service;
if (service) {
service.refresh();
}
};
} catch (h) {
field.data && (field.data.loading = false);
}
},
};
}

View File

@ -9,12 +9,12 @@ export function useDestroyAction() {
const approval = useApproval();
const apiClient = useAPIClient();
const run = () => {
return () => {
return {
async run() {
try {
_.set(field, ['data', 'loading'], true);
apiClient.resource('approvals').destroy({
await apiClient.resource('approvals').destroy({
filterByTk: approval.id,
});
@ -23,9 +23,6 @@ export function useDestroyAction() {
} catch (err) {
_.set(field, ['data', 'loading'], false);
}
};
};
return {
run,
},
};
}

View File

@ -14,8 +14,8 @@ export function useSubmit() {
const contextApprovalStatus = useContextApprovalStatus();
const apiClient = useAPIClient();
const run = () => {
return () => {
return {
async run() {
try {
from.submit();
@ -36,10 +36,6 @@ export function useSubmit() {
} catch (m) {
_.set(field, ['data', 'loading'], false);
}
};
};
return {
run,
},
};
}

View File

@ -2,29 +2,32 @@ import { useAPIClient, useActionContext } from '@nocobase/client';
import { useField } from '@nocobase/schema';
import { useApproval } from '../../../approval-common/Pd.ApprovalData';
// 撤回
export function useWithdrawAction() {
const field = useField();
const { setVisible, setSubmitted } = useActionContext() as any;
const approval = useApproval();
const api = useAPIClient();
return {
run() {
return async () => {
try {
field.data = field.data ?? {};
field.data.loading = true;
await api.resource('approvals').withdraw({
filterByTk: approval.id,
});
setSubmitted(true);
setVisible(false);
async run() {
try {
field.data = field.data ?? {};
field.data.loading = true;
await api.resource('approvals').withdraw({
filterByTk: approval.id,
});
setVisible(false);
setSubmitted(true);
field.data.loading = false;
} catch (v) {
if (field.data) {
field.data.loading = false;
} catch (v) {
if (field.data) {
field.data.loading = false;
}
}
};
}
},
};
}

View File

@ -60,5 +60,6 @@
"Could run different branch based on result.": "Could run different branch based on result.",
"End on reject": "End on reject",
"If checked, the workflow will be terminated after rejection branch processed.": "If checked, the workflow will be terminated after rejection branch processed.",
"Disabled": "Disabled"
"Disabled": "Disabled",
"Trigger data": "Trigger data"
}

View File

@ -75,5 +75,6 @@
"End the workflow after rejection branch": "否决后终止流程",
"When checked, the workflow will terminate when the rejection branch ends.": "勾选后,否决分支结束后工作流将终止。",
"Disabled": "已失效",
"Submission may be withdrawn, please try refresh the list.": "提交可能已被撤回,请尝试刷新列表。"
"Submission may be withdrawn, please try refresh the list.": "提交可能已被撤回,请尝试刷新列表。",
"Trigger data": "触发器数据"
}