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 { import {
CollectionBlockInitializer,
RadioWithTooltip, RadioWithTooltip,
Trigger, Trigger,
getCollectionFieldOptions, getCollectionFieldOptions,
@ -7,7 +8,7 @@ import {
} from '@nocobase/plugin-workflow/client'; } from '@nocobase/plugin-workflow/client';
import { useForm } from '@nocobase/schema'; import { useForm } from '@nocobase/schema';
import { SchemaConfigButton } from './VC.ConfigButton'; import { SchemaConfigButton } from './VC.ConfigButton';
import { NAMESPACE, usePluginTranslation } from '../../locale'; import { NAMESPACE, tval, usePluginTranslation } from '../../locale';
import { LauncherInterface } from './launcher-interface/VC.LauncherInterface'; import { LauncherInterface } from './launcher-interface/VC.LauncherInterface';
// 工作流节点-审批触发器节点 // 工作流节点-审批触发器节点
@ -143,4 +144,20 @@ export class ApprovalTrigger extends Trigger {
getCollectionFields, 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(); const { workflow } = useFlowContext();
return { return {
run() { async run() {
return () => { try {
try { from.submit();
from.submit(), (field.data = field.data || {}); field.data = field.data || {};
field.data.loading = true; field.data.loading = true;
apiClient.resource('approvals').create({
values: { await apiClient.resource('approvals').create({
collectionName: joinCollectionName(collection.dataSource, collection.name), values: {
data: from.values, collectionName: joinCollectionName(collection.dataSource, collection.name),
status: contextWe, data: from.values,
workflowId: workflow.id, status: contextWe,
}, workflowId: workflow.id,
}); },
setVisible(false); });
from.reset();
field.data.loading = false; setVisible(false);
const service = __parent.service; from.reset();
if (service) { field.data.loading = false;
service.refresh(); const service = __parent.service;
} if (service) {
} catch (h) { service.refresh();
field.data && (field.data.loading = false);
} }
}; } catch (h) {
field.data && (field.data.loading = false);
}
}, },
}; };
} }

View File

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

View File

@ -14,8 +14,8 @@ export function useSubmit() {
const contextApprovalStatus = useContextApprovalStatus(); const contextApprovalStatus = useContextApprovalStatus();
const apiClient = useAPIClient(); const apiClient = useAPIClient();
const run = () => { return {
return () => { async run() {
try { try {
from.submit(); from.submit();
@ -36,10 +36,6 @@ export function useSubmit() {
} catch (m) { } catch (m) {
_.set(field, ['data', 'loading'], false); _.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 { useField } from '@nocobase/schema';
import { useApproval } from '../../../approval-common/Pd.ApprovalData'; import { useApproval } from '../../../approval-common/Pd.ApprovalData';
// 撤回
export function useWithdrawAction() { export function useWithdrawAction() {
const field = useField(); const field = useField();
const { setVisible, setSubmitted } = useActionContext() as any; const { setVisible, setSubmitted } = useActionContext() as any;
const approval = useApproval(); const approval = useApproval();
const api = useAPIClient(); const api = useAPIClient();
return { return {
run() { async run() {
return async () => { try {
try { field.data = field.data ?? {};
field.data = field.data ?? {}; field.data.loading = true;
field.data.loading = true;
await api.resource('approvals').withdraw({ await api.resource('approvals').withdraw({
filterByTk: approval.id, filterByTk: approval.id,
}); });
setSubmitted(true);
setVisible(false); setVisible(false);
setSubmitted(true);
field.data.loading = false;
} catch (v) {
if (field.data) {
field.data.loading = false; 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.", "Could run different branch based on result.": "Could run different branch based on result.",
"End on reject": "End on reject", "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.", "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": "否决后终止流程", "End the workflow after rejection branch": "否决后终止流程",
"When checked, the workflow will terminate when the rejection branch ends.": "勾选后,否决分支结束后工作流将终止。", "When checked, the workflow will terminate when the rejection branch ends.": "勾选后,否决分支结束后工作流将终止。",
"Disabled": "已失效", "Disabled": "已失效",
"Submission may be withdrawn, please try refresh the list.": "提交可能已被撤回,请尝试刷新列表。" "Submission may be withdrawn, please try refresh the list.": "提交可能已被撤回,请尝试刷新列表。",
"Trigger data": "触发器数据"
} }