fix: 修改手机端审批再发起功能 (#1295)

Co-authored-by: sealday <zhanglin@daoyoucloud.com>
Reviewed-on: daoyoucloud/tachybase#1295
Co-authored-by: wjh <wwwjh0710@163.com>
Co-committed-by: wjh <wwwjh0710@163.com>
This commit is contained in:
wjh 2024-07-09 15:08:35 +08:00 committed by sealday
parent 462f4e0760
commit 4c2b6362e1
10 changed files with 73 additions and 99 deletions

View File

@ -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;
}

View File

@ -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 = () => {
{'审批'}
</NavBar>
<ContextApprovalExecution.Provider value={recordData}>
<div className="approvalContext">
{Object.keys(recordData).length && !noDate ? (
<ContextApprovalExecution.Provider value={recordData}>
{UserInitiationsComponent(workflow?.config.applyForm)}
</ContextApprovalExecution.Provider>
) : (
<div>
<Skeleton.Title animated />
<Skeleton.Paragraph lineCount={5} animated />
</div>
)}
</div>
<ResubmitProvider>
<div className="approvalContext">
{Object.keys(recordData).length && !noDate ? (
<ContextApprovalExecution.Provider value={recordData}>
{UserInitiationsComponent(workflow?.config.applyForm)}
</ContextApprovalExecution.Provider>
) : (
<div>
<Skeleton.Title animated />
<Skeleton.Paragraph lineCount={5} animated />
</div>
)}
</div>
</ResubmitProvider>
</ContextApprovalExecution.Provider>
</div>
);

View File

@ -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);
},
};
}

View File

@ -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) {

View File

@ -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);

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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 <ContextApprovalStatus.Provider value={value}>{children}</ContextApprovalStatus.Provider>;
}

View File

@ -0,0 +1,17 @@
import React, { useContext, useState } from 'react';
interface ResubmitProps {
isResubmit?: boolean;
setResubmit?: any;
}
const ResubmitContext = React.createContext<ResubmitProps>({});
export const ResubmitProvider = ({ children }) => {
const [isResubmit, setResubmit] = useState(false);
return <ResubmitContext.Provider value={{ isResubmit, setResubmit }}>{children}</ResubmitContext.Provider>;
};
export const useResubmit = () => {
return useContext(ResubmitContext);
};

View File

@ -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,
},