diff --git a/packages/plugins/@tachybase/plugin-workflow/src/client/features/approval/usage/approval-block/common/useHandleRefresh.ts b/packages/plugins/@tachybase/plugin-workflow/src/client/features/approval/usage/approval-block/common/useHandleRefresh.ts
new file mode 100644
index 000000000..d5b387e0e
--- /dev/null
+++ b/packages/plugins/@tachybase/plugin-workflow/src/client/features/approval/usage/approval-block/common/useHandleRefresh.ts
@@ -0,0 +1,19 @@
+import { useActionContext, useAPIClient, useTableBlockContext } from '@tachybase/client';
+
+// NOTE: 用于处理关闭弹窗, 和刷新外边显示的表格
+export function useHandleRefresh(delay = 500) {
+ const { service } = useTableBlockContext();
+ const { setVisible, setSubmitted } = useActionContext() as any;
+
+ const refreshTable = () => {
+ setVisible(false);
+ setSubmitted?.(true);
+ setTimeout(() => {
+ service.refresh();
+ }, delay);
+ };
+
+ return {
+ refreshTable,
+ };
+}
diff --git a/packages/plugins/@tachybase/plugin-workflow/src/client/features/approval/usage/approval-block/launch/VC.ViewActionLaunch.tsx b/packages/plugins/@tachybase/plugin-workflow/src/client/features/approval/usage/approval-block/launch/VC.ViewActionLaunch.tsx
index 67570c548..7b4d59350 100644
--- a/packages/plugins/@tachybase/plugin-workflow/src/client/features/approval/usage/approval-block/launch/VC.ViewActionLaunch.tsx
+++ b/packages/plugins/@tachybase/plugin-workflow/src/client/features/approval/usage/approval-block/launch/VC.ViewActionLaunch.tsx
@@ -22,11 +22,24 @@ export const ViewActionLaunch = ({ popoverComponent = 'Action.Drawer', popoverCo
drawer: {
type: 'void',
'x-component': popoverComponent,
- 'x-component-props': { className: 'nb-action-popup', ...popoverComponentProps },
+ 'x-component-props': {
+ className: 'nb-action-popup',
+ ...popoverComponentProps,
+ },
properties: {
- content: Object.assign({ type: 'void' }, record.approvalId ? {} : { 'x-decorator': 'RecordDecorator' }, {
- 'x-component': 'ViewActionContent',
- }),
+ content: Object.assign(
+ {
+ type: 'void',
+ },
+ record.approvalId
+ ? {}
+ : {
+ 'x-decorator': 'RecordDecorator',
+ },
+ {
+ 'x-component': 'ViewActionContent',
+ },
+ ),
},
},
},
diff --git a/packages/plugins/@tachybase/plugin-workflow/src/client/features/approval/usage/approval-block/launch/VC.ViewActionLaunchContent.tsx b/packages/plugins/@tachybase/plugin-workflow/src/client/features/approval/usage/approval-block/launch/VC.ViewActionLaunchContent.tsx
index e6d724936..f08927540 100644
--- a/packages/plugins/@tachybase/plugin-workflow/src/client/features/approval/usage/approval-block/launch/VC.ViewActionLaunchContent.tsx
+++ b/packages/plugins/@tachybase/plugin-workflow/src/client/features/approval/usage/approval-block/launch/VC.ViewActionLaunchContent.tsx
@@ -58,8 +58,6 @@ export const ViewActionLaunchContent = () => {
) as any;
// @ts-ignore
const approvalData = data?.data;
- const { approval, execution, ...approvalValue } = approvalData || {};
- const { workflow } = approval || {};
if (loading) {
return ;
@@ -69,6 +67,9 @@ export const ViewActionLaunchContent = () => {
return ;
}
+ const { approval, execution, ...approvalValue } = approvalData || {};
+ const { workflow } = approval || {};
+
return (
{
try {
if (form.values.status) {
return;
}
+
await form.submit();
field.data = field.data ?? {};
field.data.loading = true;
- setVisible(false);
+
await api.resource('approvalRecords').submit({
filterByTk: approvalExecutions.id,
values: { ...form.values, status },
});
+
field.data.loading = false;
await form.reset();
- // refreshAction?.();
- setSubmitted?.(true);
+
+ refreshTable();
} catch (error) {
console.error(error);
field.data && (field.data.loading = false);
diff --git a/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/actions.ts b/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/actions.ts
index 6e68b9a42..de313e6de 100644
--- a/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/actions.ts
+++ b/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/actions.ts
@@ -4,6 +4,7 @@ import { parseCollectionName } from '@tachybase/data-source-manager';
import { EXECUTION_STATUS, JOB_STATUS, PluginWorkflow } from '../..';
import { APPROVAL_ACTION_STATUS, APPROVAL_STATUS } from './constants';
import { getSummary } from './tools';
+import { getAssociationName, jsonParse } from './utils';
const workflows = {
async listApprovalFlows(context, next) {
@@ -71,13 +72,27 @@ const approvals = {
return actions.create(context, next);
},
async update(context, next) {
- const { collectionName, data, status } = context.action.params.values ?? {};
+ const { collectionName, data, status, schemaFormId } = context.action.params.values ?? {};
+
const [dataSourceName, cName] = parseCollectionName(collectionName);
const dataSource = context.app.dataSourceManager.dataSources.get(dataSourceName);
const collection = dataSource.collectionManager.getCollection(cName);
+
+ /** 以下为,处理子表单子表格等关联字段的更新逻辑 */
+ const schemaOfForm = await context.db.getRepository('uiSchemas').getJsonSchema(schemaFormId);
+ const itemsOfSchema = await jsonParse(`**["x-component-props".mode]`, schemaOfForm);
+ const fieldAssociationName = itemsOfSchema
+ .filter((item) => {
+ return ['Nester', 'SubTable', 'PopoverNester'].includes(item?.['x-component-props']?.mode);
+ })
+ .map((item) => getAssociationName(item['x-collection-field']));
+ const updateAssociationValues = [...new Set(fieldAssociationName)];
+ /** 以上为,处理子表单子表格等关联字段的更新逻辑 */
+
const [target] = await collection.repository.update({
filterByTk: data[collection.filterTargetKey],
values: data,
+ updateAssociationValues,
});
context.action.mergeParams({
values: {
diff --git a/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/utils.ts b/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/utils.ts
new file mode 100644
index 000000000..16f5a8660
--- /dev/null
+++ b/packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/utils.ts
@@ -0,0 +1,14 @@
+import jsonata from 'jsonata';
+
+export function getAssociationName(str) {
+ const lastIndex = str.lastIndexOf('.');
+ if (lastIndex !== -1) {
+ return str.substring(lastIndex + 1);
+ }
+ return str;
+}
+
+export function jsonParse(expression, scope) {
+ const result = jsonata(expression).evaluate(scope);
+ return result;
+}