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:
parent
462f4e0760
commit
4c2b6362e1
@ -18,6 +18,7 @@ import '../../style/style.css';
|
|||||||
import { MobileProvider } from '@tachybase/plugin-mobile-client/client';
|
import { MobileProvider } from '@tachybase/plugin-mobile-client/client';
|
||||||
|
|
||||||
import { APPROVAL_ACTION_STATUS } from '../../constants';
|
import { APPROVAL_ACTION_STATUS } from '../../constants';
|
||||||
|
import { useActionResubmit } from '../hook/useActionResubmit';
|
||||||
import { useCreateSubmit } from '../hook/useCreateSubmit';
|
import { useCreateSubmit } from '../hook/useCreateSubmit';
|
||||||
|
|
||||||
export const ViewActionInitiationsContent = () => {
|
export const ViewActionInitiationsContent = () => {
|
||||||
@ -94,10 +95,11 @@ export const ViewActionInitiationsContent = () => {
|
|||||||
schema={schema}
|
schema={schema}
|
||||||
components={{
|
components={{
|
||||||
RemoteSchemaComponent: RemoteSchemaComponent,
|
RemoteSchemaComponent: RemoteSchemaComponent,
|
||||||
CollectionProvider_deprecated: CollectionProvider_deprecated,
|
CollectionProvider_deprecated,
|
||||||
ApplyActionStatusProvider: ContextInitiationsApprovalStatusProvider,
|
ApplyActionStatusProvider: ContextInitiationsApprovalStatusProvider,
|
||||||
ActionBarProvider,
|
ActionBarProvider,
|
||||||
WithdrawActionProvider: WithdrawActionProvider,
|
WithdrawActionProvider: WithdrawActionProvider,
|
||||||
|
ProviderActionResubmit: () => null,
|
||||||
MobileProvider,
|
MobileProvider,
|
||||||
}}
|
}}
|
||||||
scope={{
|
scope={{
|
||||||
@ -112,10 +114,6 @@ export const ViewActionInitiationsContent = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export function useActionResubmit() {
|
|
||||||
return { run() {} };
|
|
||||||
}
|
|
||||||
|
|
||||||
export function WithdrawActionProvider() {
|
export function WithdrawActionProvider() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@ import { MobileProvider } from '@tachybase/plugin-mobile-client/client';
|
|||||||
|
|
||||||
import { useActionResubmit } from '../hook/useActionResubmit';
|
import { useActionResubmit } from '../hook/useActionResubmit';
|
||||||
import { ProviderActionResubmit } from '../provider/ActionResubmit.provider';
|
import { ProviderActionResubmit } from '../provider/ActionResubmit.provider';
|
||||||
|
import { ResubmitProvider } from '../provider/Resubmit.provider';
|
||||||
|
|
||||||
export const ViewActionUserInitiationsContent = () => {
|
export const ViewActionUserInitiationsContent = () => {
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
@ -89,6 +90,7 @@ export const ViewActionUserInitiationsContent = () => {
|
|||||||
{'审批'}
|
{'审批'}
|
||||||
</NavBar>
|
</NavBar>
|
||||||
<ContextApprovalExecution.Provider value={recordData}>
|
<ContextApprovalExecution.Provider value={recordData}>
|
||||||
|
<ResubmitProvider>
|
||||||
<div className="approvalContext">
|
<div className="approvalContext">
|
||||||
{Object.keys(recordData).length && !noDate ? (
|
{Object.keys(recordData).length && !noDate ? (
|
||||||
<ContextApprovalExecution.Provider value={recordData}>
|
<ContextApprovalExecution.Provider value={recordData}>
|
||||||
@ -101,6 +103,7 @@ export const ViewActionUserInitiationsContent = () => {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
</ResubmitProvider>
|
||||||
</ContextApprovalExecution.Provider>
|
</ContextApprovalExecution.Provider>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -1,71 +1,12 @@
|
|||||||
import { useAPIClient } from '@tachybase/client';
|
import { useResubmit } from '../provider/Resubmit.provider';
|
||||||
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';
|
|
||||||
|
|
||||||
// 重新发起
|
// 重新发起
|
||||||
export function useActionResubmit() {
|
export function useActionResubmit() {
|
||||||
const field = useField();
|
const { setResubmit } = useResubmit();
|
||||||
const api = useAPIClient();
|
|
||||||
const { approval } = useContextApprovalExecution();
|
|
||||||
const { workflow } = approval;
|
|
||||||
const navigate = useNavigate();
|
|
||||||
return {
|
return {
|
||||||
async run() {
|
async run() {
|
||||||
try {
|
setResubmit(true);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -2,21 +2,27 @@ import { joinCollectionName, useAPIClient, useBlockRequestContext, useCollection
|
|||||||
import { useField, useForm } from '@tachybase/schema';
|
import { useField, useForm } from '@tachybase/schema';
|
||||||
|
|
||||||
import { Toast } from 'antd-mobile';
|
import { Toast } from 'antd-mobile';
|
||||||
|
import _ from 'lodash';
|
||||||
import { useNavigate, useParams } from 'react-router-dom';
|
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() {
|
export function useCreateSubmit() {
|
||||||
const from = useForm();
|
const from = useForm();
|
||||||
const field = useField();
|
const field = useField();
|
||||||
const collection = useCollection_deprecated();
|
const collection = useCollection_deprecated();
|
||||||
const contextWe = APPROVAL_ACTION_STATUS.SUBMITTED;
|
const status = useContextApprovalStatus();
|
||||||
const apiClient = useAPIClient();
|
const apiClient = useAPIClient();
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
|
const { isResubmit } = useResubmit();
|
||||||
const { id: workflowId } = params;
|
const { id: workflowId } = params;
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const { approval } = useContextApprovalExecution();
|
||||||
|
const { workflow } = approval || {};
|
||||||
return {
|
return {
|
||||||
async run() {
|
async run(args) {
|
||||||
try {
|
try {
|
||||||
from.submit();
|
from.submit();
|
||||||
field.data = field.data || {};
|
field.data = field.data || {};
|
||||||
@ -26,8 +32,8 @@ export function useCreateSubmit() {
|
|||||||
values: {
|
values: {
|
||||||
collectionName: joinCollectionName(collection.dataSource, collection.name),
|
collectionName: joinCollectionName(collection.dataSource, collection.name),
|
||||||
data: from.values,
|
data: from.values,
|
||||||
status: contextWe,
|
status: typeof args?.approvalStatus !== 'undefined' ? args?.approvalStatus : status,
|
||||||
workflowId: workflowId,
|
workflowId: isResubmit ? workflow.id : workflowId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
|
@ -7,6 +7,8 @@ import { useNavigate } from 'react-router-dom';
|
|||||||
|
|
||||||
import { useContextApprovalExecution } from '../../context/ApprovalExecution';
|
import { useContextApprovalExecution } from '../../context/ApprovalExecution';
|
||||||
import { useContextApprovalStatus } from '../provider/ApplyActionStatus';
|
import { useContextApprovalStatus } from '../provider/ApplyActionStatus';
|
||||||
|
import { useResubmit } from '../provider/Resubmit.provider';
|
||||||
|
import { useCreateSubmit } from './useCreateSubmit';
|
||||||
|
|
||||||
export function useUpdateSubmit() {
|
export function useUpdateSubmit() {
|
||||||
const form = useForm();
|
const form = useForm();
|
||||||
@ -17,8 +19,13 @@ export function useUpdateSubmit() {
|
|||||||
const contextApprovalStatus = useContextApprovalStatus();
|
const contextApprovalStatus = useContextApprovalStatus();
|
||||||
const apiClient = useAPIClient();
|
const apiClient = useAPIClient();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const { isResubmit } = useResubmit();
|
||||||
|
const { run: create } = useCreateSubmit();
|
||||||
return {
|
return {
|
||||||
async run() {
|
async run() {
|
||||||
|
if (isResubmit) {
|
||||||
|
return await create({ approvalStatus: contextApprovalStatus });
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
form.submit();
|
form.submit();
|
||||||
_.set(field, ['data', 'loading'], true);
|
_.set(field, ['data', 'loading'], true);
|
||||||
|
@ -10,14 +10,8 @@ export function ActionBarProvider(props) {
|
|||||||
|
|
||||||
const isSameId = data.data.id === createdById;
|
const isSameId = data.data.id === createdById;
|
||||||
const isSameExcutionId = latestExecutionId === id;
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,17 +1,19 @@
|
|||||||
import { useCurrentUserContext } from '@tachybase/client';
|
import { useCurrentUserContext } from '@tachybase/client';
|
||||||
|
|
||||||
|
import { APPROVAL_ACTION_STATUS } from '../../constants';
|
||||||
import { useContextApprovalExecution } from '../../context/ApprovalExecution';
|
import { useContextApprovalExecution } from '../../context/ApprovalExecution';
|
||||||
|
import { useResubmit } from './Resubmit.provider';
|
||||||
|
|
||||||
export function ProviderActionResubmit(props) {
|
export function ProviderActionResubmit(props) {
|
||||||
const { data } = useCurrentUserContext();
|
const { data } = useCurrentUserContext();
|
||||||
const { approval } = useContextApprovalExecution();
|
const { approval } = useContextApprovalExecution();
|
||||||
|
const { isResubmit } = useResubmit();
|
||||||
const { status, createdById } = approval;
|
const { status, createdById } = approval;
|
||||||
|
|
||||||
const isSameId = data.data.id === createdById;
|
const isSameId = data.data.id === createdById;
|
||||||
// const isEnabledWithdraw = workflow.enabled && workflow.config.withdrawable;
|
const isDraft = status === APPROVAL_ACTION_STATUS.DRAFT;
|
||||||
// const isNotDraft = status !== APPROVAL_STATUS.DRAFT;
|
const isReturned = status === APPROVAL_ACTION_STATUS.RETURNED;
|
||||||
|
if (isSameId && !isResubmit && !isDraft && !isReturned) {
|
||||||
if (isSameId) {
|
|
||||||
return props.children;
|
return props.children;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import { useFlowContext } from '@tachybase/plugin-workflow/client';
|
|||||||
|
|
||||||
import { APPROVAL_ACTION_STATUS } from '../../constants';
|
import { APPROVAL_ACTION_STATUS } from '../../constants';
|
||||||
import { useContextApprovalExecution } from '../../context/ApprovalExecution';
|
import { useContextApprovalExecution } from '../../context/ApprovalExecution';
|
||||||
|
import { useResubmit } from './Resubmit.provider';
|
||||||
|
|
||||||
const ContextApprovalStatus = createContext(APPROVAL_ACTION_STATUS.SUBMITTED);
|
const ContextApprovalStatus = createContext(APPROVAL_ACTION_STATUS.SUBMITTED);
|
||||||
|
|
||||||
@ -16,15 +17,20 @@ export function ApplyActionStatusProvider(props) {
|
|||||||
const { approval } = useContextApprovalExecution();
|
const { approval } = useContextApprovalExecution();
|
||||||
const { status, createdById, workflow } = approval;
|
const { status, createdById, workflow } = approval;
|
||||||
const { data } = useCurrentUserContext();
|
const { data } = useCurrentUserContext();
|
||||||
|
const { isResubmit } = useResubmit();
|
||||||
const isSameId = data.data.id === createdById;
|
const isSameId = data.data.id === createdById;
|
||||||
const isEnbled = workflow.enabled;
|
const isEnabled = workflow.enabled;
|
||||||
const isStatusDid = [
|
const isStatusDid = [
|
||||||
APPROVAL_ACTION_STATUS.DRAFT,
|
APPROVAL_ACTION_STATUS.DRAFT,
|
||||||
APPROVAL_ACTION_STATUS.RETURNED,
|
APPROVAL_ACTION_STATUS.RETURNED,
|
||||||
APPROVAL_ACTION_STATUS.RESUBMIT,
|
APPROVAL_ACTION_STATUS.RESUBMIT,
|
||||||
].includes(status);
|
].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>;
|
return <ContextApprovalStatus.Provider value={value}>{children}</ContextApprovalStatus.Provider>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
};
|
@ -32,7 +32,7 @@ export function useCreateSubmit() {
|
|||||||
await apiClient.resource('approvals').create({
|
await apiClient.resource('approvals').create({
|
||||||
values: {
|
values: {
|
||||||
collectionName: joinCollectionName(collection.dataSource, collection.name),
|
collectionName: joinCollectionName(collection.dataSource, collection.name),
|
||||||
data: _.omit(from.values, [collection.getPrimaryKey()]),
|
data: from.values,
|
||||||
status: typeof args?.approvalStatus !== 'undefined' ? args?.approvalStatus : status,
|
status: typeof args?.approvalStatus !== 'undefined' ? args?.approvalStatus : status,
|
||||||
workflowId: workflow.id,
|
workflowId: workflow.id,
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user