From 4c2b6362e1e4eb031ff489f45e8f8241acabfcba Mon Sep 17 00:00:00 2001 From: wjh Date: Tue, 9 Jul 2024 15:08:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E6=89=8B=E6=9C=BA?= =?UTF-8?q?=E7=AB=AF=E5=AE=A1=E6=89=B9=E5=86=8D=E5=8F=91=E8=B5=B7=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=20(#1295)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: sealday Reviewed-on: https://git.daoyoucloud.com/daoyoucloud/tachybase/pulls/1295 Co-authored-by: wjh Co-committed-by: wjh --- .../ViewActionInitiationsContent.tsx | 8 +-- .../ViewActionUserInitiationsContent.tsx | 27 ++++---- .../initiations/hook/useActionResubmit.ts | 67 ++----------------- .../initiations/hook/useCreateSubmit.tsx | 16 +++-- .../initiations/hook/useUpadteSubmit.tsx | 7 ++ .../initiations/provider/ActionBar.tsx | 8 +-- .../provider/ActionResubmit.provider.tsx | 10 +-- .../provider/ApplyActionStatus.tsx | 10 ++- .../provider/Resubmit.provider.tsx | 17 +++++ .../launch/apply-button/hooks/useSubmit.tsx | 2 +- 10 files changed, 73 insertions(+), 99 deletions(-) create mode 100644 packages/plugins/@hera/plugin-approval-mobile/src/client/approval/initiations/provider/Resubmit.provider.tsx diff --git a/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/initiations/component/ViewActionInitiationsContent.tsx b/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/initiations/component/ViewActionInitiationsContent.tsx index 45ac449c2..e762f60af 100644 --- a/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/initiations/component/ViewActionInitiationsContent.tsx +++ b/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/initiations/component/ViewActionInitiationsContent.tsx @@ -18,6 +18,7 @@ import '../../style/style.css'; import { MobileProvider } from '@tachybase/plugin-mobile-client/client'; import { APPROVAL_ACTION_STATUS } from '../../constants'; +import { useActionResubmit } from '../hook/useActionResubmit'; import { useCreateSubmit } from '../hook/useCreateSubmit'; export const ViewActionInitiationsContent = () => { @@ -94,10 +95,11 @@ export const ViewActionInitiationsContent = () => { schema={schema} components={{ RemoteSchemaComponent: RemoteSchemaComponent, - CollectionProvider_deprecated: CollectionProvider_deprecated, + CollectionProvider_deprecated, ApplyActionStatusProvider: ContextInitiationsApprovalStatusProvider, ActionBarProvider, WithdrawActionProvider: WithdrawActionProvider, + ProviderActionResubmit: () => null, MobileProvider, }} scope={{ @@ -112,10 +114,6 @@ export const ViewActionInitiationsContent = () => { ); }; -export function useActionResubmit() { - return { run() {} }; -} - export function WithdrawActionProvider() { return null; } diff --git a/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/initiations/component/ViewActionUserInitiationsContent.tsx b/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/initiations/component/ViewActionUserInitiationsContent.tsx index 8fc70ce4f..2c38b35d7 100644 --- a/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/initiations/component/ViewActionUserInitiationsContent.tsx +++ b/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/initiations/component/ViewActionUserInitiationsContent.tsx @@ -30,6 +30,7 @@ import { MobileProvider } from '@tachybase/plugin-mobile-client/client'; import { useActionResubmit } from '../hook/useActionResubmit'; import { ProviderActionResubmit } from '../provider/ActionResubmit.provider'; +import { ResubmitProvider } from '../provider/Resubmit.provider'; export const ViewActionUserInitiationsContent = () => { const params = useParams(); @@ -89,18 +90,20 @@ export const ViewActionUserInitiationsContent = () => { {'审批'} -
- {Object.keys(recordData).length && !noDate ? ( - - {UserInitiationsComponent(workflow?.config.applyForm)} - - ) : ( -
- - -
- )} -
+ +
+ {Object.keys(recordData).length && !noDate ? ( + + {UserInitiationsComponent(workflow?.config.applyForm)} + + ) : ( +
+ + +
+ )} +
+
); diff --git a/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/initiations/hook/useActionResubmit.ts b/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/initiations/hook/useActionResubmit.ts index 8a5fea67e..5fdaf412f 100644 --- a/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/initiations/hook/useActionResubmit.ts +++ b/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/initiations/hook/useActionResubmit.ts @@ -1,71 +1,12 @@ -import { useAPIClient } from '@tachybase/client'; -import { useFlowContext } from '@tachybase/plugin-workflow/client'; -import { useField } from '@tachybase/schema'; - -import { Toast } from 'antd-mobile'; -import _ from 'lodash'; -import { useNavigate } from 'react-router-dom'; - -import { APPROVAL_ACTION_STATUS, APPROVAL_STATUS } from '../../constants'; -import { useContextApprovalExecution } from '../../context/ApprovalExecution'; +import { useResubmit } from '../provider/Resubmit.provider'; // 重新发起 export function useActionResubmit() { - const field = useField(); - const api = useAPIClient(); - const { approval } = useContextApprovalExecution(); - const { workflow } = approval; - const navigate = useNavigate(); + const { setResubmit } = useResubmit(); + return { async run() { - try { - field.data = field.data ?? {}; - - field.data.loading = true; - - const appendsConfigs = [...workflow.config.appends]; - const summaryConfigs = [...workflow.config.summary]; - const appends = _.intersection(appendsConfigs, summaryConfigs); - - const { data: approvalData } = await api.resource('approvals').get({ - filterByTk: approval.id, - }); - - const { collectionName, data, workflowId } = approvalData.data; - - const newData = _.omit(data, ['id', 'createdAt', 'updatedAt', 'createdBy', 'updatedBy']); - - api - .resource('approvals') - .reSubmit({ - values: { - collectionName: collectionName, - data: newData, - status: APPROVAL_ACTION_STATUS.RESUBMIT, - workflowId: workflowId, - collectionAppends: appends, - }, - }) - .then((res) => { - if (res?.data?.data) { - Toast.show({ - icon: 'success', - content: '申请成功', - }); - setTimeout(() => { - navigate(-1); - }, 1000); - } - }) - .catch(() => { - return; - }); - field.data.loading = false; - } catch (v) { - if (field.data) { - field.data.loading = false; - } - } + setResubmit(true); }, }; } diff --git a/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/initiations/hook/useCreateSubmit.tsx b/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/initiations/hook/useCreateSubmit.tsx index f70350e93..3ad12cb89 100644 --- a/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/initiations/hook/useCreateSubmit.tsx +++ b/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/initiations/hook/useCreateSubmit.tsx @@ -2,21 +2,27 @@ import { joinCollectionName, useAPIClient, useBlockRequestContext, useCollection import { useField, useForm } from '@tachybase/schema'; import { Toast } from 'antd-mobile'; +import _ from 'lodash'; import { useNavigate, useParams } from 'react-router-dom'; -import { APPROVAL_ACTION_STATUS } from '../../constants'; +import { useContextApprovalExecution } from '../../context/ApprovalExecution'; +import { useContextApprovalStatus } from '../component/ViewActionInitiationsContent'; +import { useResubmit } from '../provider/Resubmit.provider'; export function useCreateSubmit() { const from = useForm(); const field = useField(); const collection = useCollection_deprecated(); - const contextWe = APPROVAL_ACTION_STATUS.SUBMITTED; + const status = useContextApprovalStatus(); const apiClient = useAPIClient(); const params = useParams(); + const { isResubmit } = useResubmit(); const { id: workflowId } = params; const navigate = useNavigate(); + const { approval } = useContextApprovalExecution(); + const { workflow } = approval || {}; return { - async run() { + async run(args) { try { from.submit(); field.data = field.data || {}; @@ -26,8 +32,8 @@ export function useCreateSubmit() { values: { collectionName: joinCollectionName(collection.dataSource, collection.name), data: from.values, - status: contextWe, - workflowId: workflowId, + status: typeof args?.approvalStatus !== 'undefined' ? args?.approvalStatus : status, + workflowId: isResubmit ? workflow.id : workflowId, }, }); if (res.status === 200) { diff --git a/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/initiations/hook/useUpadteSubmit.tsx b/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/initiations/hook/useUpadteSubmit.tsx index 07cf5d73b..91a2f3724 100644 --- a/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/initiations/hook/useUpadteSubmit.tsx +++ b/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/initiations/hook/useUpadteSubmit.tsx @@ -7,6 +7,8 @@ import { useNavigate } from 'react-router-dom'; import { useContextApprovalExecution } from '../../context/ApprovalExecution'; import { useContextApprovalStatus } from '../provider/ApplyActionStatus'; +import { useResubmit } from '../provider/Resubmit.provider'; +import { useCreateSubmit } from './useCreateSubmit'; export function useUpdateSubmit() { const form = useForm(); @@ -17,8 +19,13 @@ export function useUpdateSubmit() { const contextApprovalStatus = useContextApprovalStatus(); const apiClient = useAPIClient(); const navigate = useNavigate(); + const { isResubmit } = useResubmit(); + const { run: create } = useCreateSubmit(); return { async run() { + if (isResubmit) { + return await create({ approvalStatus: contextApprovalStatus }); + } try { form.submit(); _.set(field, ['data', 'loading'], true); diff --git a/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/initiations/provider/ActionBar.tsx b/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/initiations/provider/ActionBar.tsx index e8fac0882..0a7555198 100644 --- a/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/initiations/provider/ActionBar.tsx +++ b/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/initiations/provider/ActionBar.tsx @@ -10,14 +10,8 @@ export function ActionBarProvider(props) { const isSameId = data.data.id === createdById; const isSameExcutionId = latestExecutionId === id; - const isExcutionDid = [ - APPROVAL_ACTION_STATUS.DRAFT, - APPROVAL_ACTION_STATUS.RETURNED, - APPROVAL_ACTION_STATUS.SUBMITTED, - APPROVAL_ACTION_STATUS.RESUBMIT, - ].includes(status); - if (!isSameId || !isSameExcutionId || !isExcutionDid) { + if (!isSameId || !isSameExcutionId) { return null; } diff --git a/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/initiations/provider/ActionResubmit.provider.tsx b/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/initiations/provider/ActionResubmit.provider.tsx index 351d0085e..4b36cd8eb 100644 --- a/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/initiations/provider/ActionResubmit.provider.tsx +++ b/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/initiations/provider/ActionResubmit.provider.tsx @@ -1,17 +1,19 @@ import { useCurrentUserContext } from '@tachybase/client'; +import { APPROVAL_ACTION_STATUS } from '../../constants'; import { useContextApprovalExecution } from '../../context/ApprovalExecution'; +import { useResubmit } from './Resubmit.provider'; export function ProviderActionResubmit(props) { const { data } = useCurrentUserContext(); const { approval } = useContextApprovalExecution(); + const { isResubmit } = useResubmit(); const { status, createdById } = approval; const isSameId = data.data.id === createdById; - // const isEnabledWithdraw = workflow.enabled && workflow.config.withdrawable; - // const isNotDraft = status !== APPROVAL_STATUS.DRAFT; - - if (isSameId) { + const isDraft = status === APPROVAL_ACTION_STATUS.DRAFT; + const isReturned = status === APPROVAL_ACTION_STATUS.RETURNED; + if (isSameId && !isResubmit && !isDraft && !isReturned) { return props.children; } diff --git a/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/initiations/provider/ApplyActionStatus.tsx b/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/initiations/provider/ApplyActionStatus.tsx index 85dc733d3..7753244b7 100644 --- a/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/initiations/provider/ApplyActionStatus.tsx +++ b/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/initiations/provider/ApplyActionStatus.tsx @@ -4,6 +4,7 @@ import { useFlowContext } from '@tachybase/plugin-workflow/client'; import { APPROVAL_ACTION_STATUS } from '../../constants'; import { useContextApprovalExecution } from '../../context/ApprovalExecution'; +import { useResubmit } from './Resubmit.provider'; const ContextApprovalStatus = createContext(APPROVAL_ACTION_STATUS.SUBMITTED); @@ -16,15 +17,20 @@ export function ApplyActionStatusProvider(props) { const { approval } = useContextApprovalExecution(); const { status, createdById, workflow } = approval; const { data } = useCurrentUserContext(); + const { isResubmit } = useResubmit(); const isSameId = data.data.id === createdById; - const isEnbled = workflow.enabled; + const isEnabled = workflow.enabled; const isStatusDid = [ APPROVAL_ACTION_STATUS.DRAFT, APPROVAL_ACTION_STATUS.RETURNED, APPROVAL_ACTION_STATUS.RESUBMIT, ].includes(status); - if (isSameId && isEnbled && isStatusDid) { + if (value === APPROVAL_ACTION_STATUS.DRAFT && status === APPROVAL_ACTION_STATUS.DRAFT) { + return null; + } + + if ((isSameId && isEnabled && isStatusDid) || (isSameId && isEnabled && isResubmit)) { return {children}; } diff --git a/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/initiations/provider/Resubmit.provider.tsx b/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/initiations/provider/Resubmit.provider.tsx new file mode 100644 index 000000000..efc75635b --- /dev/null +++ b/packages/plugins/@hera/plugin-approval-mobile/src/client/approval/initiations/provider/Resubmit.provider.tsx @@ -0,0 +1,17 @@ +import React, { useContext, useState } from 'react'; + +interface ResubmitProps { + isResubmit?: boolean; + setResubmit?: any; +} + +const ResubmitContext = React.createContext({}); + +export const ResubmitProvider = ({ children }) => { + const [isResubmit, setResubmit] = useState(false); + return {children}; +}; + +export const useResubmit = () => { + return useContext(ResubmitContext); +}; diff --git a/packages/plugins/@tachybase/plugin-workflow/src/client/features/approval/usage/approval-block/launch/apply-button/hooks/useSubmit.tsx b/packages/plugins/@tachybase/plugin-workflow/src/client/features/approval/usage/approval-block/launch/apply-button/hooks/useSubmit.tsx index fb92f0513..2d31ef109 100644 --- a/packages/plugins/@tachybase/plugin-workflow/src/client/features/approval/usage/approval-block/launch/apply-button/hooks/useSubmit.tsx +++ b/packages/plugins/@tachybase/plugin-workflow/src/client/features/approval/usage/approval-block/launch/apply-button/hooks/useSubmit.tsx @@ -32,7 +32,7 @@ export function useCreateSubmit() { await apiClient.resource('approvals').create({ values: { collectionName: joinCollectionName(collection.dataSource, collection.name), - data: _.omit(from.values, [collection.getPrimaryKey()]), + data: from.values, status: typeof args?.approvalStatus !== 'undefined' ? args?.approvalStatus : status, workflowId: workflow.id, },