From ef2e2c9beb43c5d23cda15117a8eb9360225a9d3 Mon Sep 17 00:00:00 2001 From: "bai.zixv" Date: Tue, 2 Jul 2024 17:54:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AE=A1=E6=89=B9,=20=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=88=B7=E6=96=B0=E6=9C=BA=E5=88=B6=E5=92=8C=E6=92=A4=E5=9B=9E?= =?UTF-8?q?=E5=90=8E=E6=9B=B4=E6=94=B9=E5=AD=90=E8=A1=A8=E6=A0=BC=E5=85=B3?= =?UTF-8?q?=E8=81=94=E5=AD=97=E6=AE=B5=20(#1260)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-on: https://git.daoyoucloud.com/daoyoucloud/tachybase/pulls/1260 Co-authored-by: bai.zixv Co-committed-by: bai.zixv --- .../approval-block/common/useHandleRefresh.ts | 19 +++++++++++++++ .../launch/VC.ViewActionLaunch.tsx | 21 +++++++++++++---- .../launch/VC.ViewActionLaunchContent.tsx | 5 ++-- .../launch/hooks/useDestroyAction.tsx | 11 +++++---- .../approval-block/launch/hooks/useSubmit.tsx | 23 +++++++++++-------- .../launch/hooks/useWithdrawAction.tsx | 15 +++++++----- .../approval-block/todos/hooks/useSubmit.tsx | 17 ++++++++------ .../src/server/features/approval/actions.ts | 17 +++++++++++++- .../src/server/features/approval/utils.ts | 14 +++++++++++ 9 files changed, 108 insertions(+), 34 deletions(-) create mode 100644 packages/plugins/@tachybase/plugin-workflow/src/client/features/approval/usage/approval-block/common/useHandleRefresh.ts create mode 100644 packages/plugins/@tachybase/plugin-workflow/src/server/features/approval/utils.ts 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; +}