feat: pc端发起审批模块 (#1316)
Reviewed-on: daoyoucloud/tachybase#1316 Co-authored-by: wjh <wwwjh0710@163.com> Co-committed-by: wjh <wwwjh0710@163.com>
This commit is contained in:
parent
d026303395
commit
41b8d00223
@ -7,6 +7,7 @@ import { TableOutlined } from '@ant-design/icons';
|
||||
import { NAMESPACE } from '../../locale';
|
||||
import { ApprovalBlockProvider } from './ApprovalBlock.provider';
|
||||
import { ApprovalBlockLaunch } from './launch/VC.ApprovalBlockLaunch';
|
||||
import { ApprovalBlockLaunchApplication } from './launch/VC.ApprovalBlockLaunchApplication';
|
||||
import { ApprovalBlockTodos } from './todos/VC.ApprovalBlockTodos';
|
||||
|
||||
export class SCApprovalBlock extends Plugin {
|
||||
@ -14,6 +15,7 @@ export class SCApprovalBlock extends Plugin {
|
||||
this.app.addComponents({
|
||||
'ApprovalBlock.Decorator': ApprovalBlockProvider,
|
||||
'ApprovalBlock.Launch': ApprovalBlockLaunch,
|
||||
'ApprovalBlock.Launch.Application': ApprovalBlockLaunchApplication,
|
||||
'ApprovalBlock.Todos': ApprovalBlockTodos,
|
||||
});
|
||||
}
|
||||
@ -21,14 +23,28 @@ export class SCApprovalBlock extends Plugin {
|
||||
|
||||
const schemaItems = [
|
||||
{
|
||||
type: 'item',
|
||||
type: 'itemGroup',
|
||||
name: 'Launch',
|
||||
title: `{{t("Launch", { ns: "${NAMESPACE}" })}}`,
|
||||
'x-component': 'ApprovalBlock.Launch',
|
||||
collection: 'approvals',
|
||||
params: {
|
||||
appends: ['createdBy.nickname', 'workflow.title', 'workflow.enabled'],
|
||||
except: ['data'],
|
||||
},
|
||||
children: [
|
||||
{
|
||||
type: 'item',
|
||||
title: `{{t("Launch", { ns: "${NAMESPACE}" })}}`,
|
||||
'x-component': 'ApprovalBlock.Launch.Application',
|
||||
collection: 'workflows',
|
||||
action: 'list',
|
||||
},
|
||||
{
|
||||
type: 'item',
|
||||
title: `{{t("MyLaunch", { ns: "${NAMESPACE}" })}}`,
|
||||
'x-component': 'ApprovalBlock.Launch',
|
||||
collection: 'approvals',
|
||||
params: {
|
||||
appends: ['createdBy.nickname', 'workflow.title', 'workflow.enabled'],
|
||||
except: ['data'],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: 'item',
|
||||
@ -56,7 +72,7 @@ const schemaItems = [
|
||||
|
||||
const getSchemaInsert = ({ item }) => {
|
||||
const id = uid();
|
||||
const { collection, params, ['x-component']: xcomponent } = item;
|
||||
const { collection, params, ['x-component']: xcomponent, action } = item;
|
||||
return {
|
||||
type: 'void',
|
||||
name: id,
|
||||
@ -66,7 +82,7 @@ const getSchemaInsert = ({ item }) => {
|
||||
'x-decorator-props': {
|
||||
collection,
|
||||
params,
|
||||
action: 'listCentralized',
|
||||
action: action || 'listCentralized',
|
||||
},
|
||||
'x-component': 'CardItem',
|
||||
properties: {
|
||||
|
@ -0,0 +1,161 @@
|
||||
import React, { useCallback, useContext, useEffect, useState } from 'react';
|
||||
import {
|
||||
ActionContextProvider,
|
||||
CollectionProvider_deprecated,
|
||||
css,
|
||||
parseCollectionName,
|
||||
RemoteSchemaComponent,
|
||||
SchemaComponent,
|
||||
SchemaComponentContext,
|
||||
useRequest,
|
||||
} from '@tachybase/client';
|
||||
import { useFieldSchema } from '@tachybase/schema';
|
||||
|
||||
import { Button, Col, Row } from 'antd';
|
||||
|
||||
import { FlowContextProvider } from '../common/FlowContext.provider';
|
||||
import { useCreateSubmit } from './apply-button/hooks/useSubmit';
|
||||
import { ActionBarProvider } from './apply-button/Pd.ActionBar';
|
||||
import { ApplyActionStatusProvider } from './apply-button/Pd.ActionStatus';
|
||||
import { useActionResubmit } from './hooks/useActionResubmit';
|
||||
import { useWithdrawAction } from './hooks/useWithdrawAction';
|
||||
import { WithdrawActionProvider } from './Pd.WithdrawAction';
|
||||
|
||||
// 审批-发起: 申请区块
|
||||
export const ApprovalBlockLaunchApplication = (props) => {
|
||||
const fieldSchema = useFieldSchema();
|
||||
const decorator = fieldSchema?.parent?.['x-decorator-props'];
|
||||
const [options, setOptions] = useState([]);
|
||||
const [visible, setVisible] = useState(false);
|
||||
const [schema, setSchema] = useState(null);
|
||||
const context = useContext(SchemaComponentContext);
|
||||
const { run } = useRequest(
|
||||
{
|
||||
resource: decorator?.collection,
|
||||
action: decorator?.action,
|
||||
params: { pageSize: 99999, filter: { ...decorator?.params?.filter } },
|
||||
},
|
||||
{
|
||||
manual: true,
|
||||
onSuccess(res) {
|
||||
const result = {
|
||||
items: [],
|
||||
data: [],
|
||||
};
|
||||
res.data?.forEach((item, index) => {
|
||||
if ((index + 1) % 4 === 0) {
|
||||
result.items.push(item);
|
||||
result.data.push(result.items);
|
||||
result.items = [];
|
||||
} else {
|
||||
result.items.push(item);
|
||||
}
|
||||
if (index + 1 === res.data.length) {
|
||||
result.data.push(result.items);
|
||||
}
|
||||
});
|
||||
setOptions(result.data);
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
run();
|
||||
}, []);
|
||||
|
||||
const onClick = useCallback(
|
||||
(targetItems) => {
|
||||
const { applyForm } = targetItems?.config ?? {};
|
||||
const [dataSource, name] = parseCollectionName(targetItems.config.collection);
|
||||
|
||||
setSchema({
|
||||
type: 'void',
|
||||
properties: {
|
||||
[`drawer-${targetItems.id}`]: {
|
||||
type: 'void',
|
||||
title: targetItems.title,
|
||||
'x-decorator': 'FlowContextProvider',
|
||||
'x-decorator-props': {
|
||||
workflow: targetItems,
|
||||
},
|
||||
'x-component': 'Action.Drawer',
|
||||
'x-component-props': {
|
||||
className: css`
|
||||
.ant-drawer-body {
|
||||
background: var(--tb-box-bg);
|
||||
}
|
||||
`,
|
||||
},
|
||||
properties: {
|
||||
[applyForm]: {
|
||||
type: 'void',
|
||||
'x-decorator': 'CollectionProvider_deprecated',
|
||||
'x-decorator-props': {
|
||||
name,
|
||||
dataSource,
|
||||
},
|
||||
'x-component': 'RemoteSchemaComponent',
|
||||
'x-component-props': {
|
||||
uid: applyForm,
|
||||
noForm: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
setVisible(true);
|
||||
},
|
||||
[options],
|
||||
);
|
||||
|
||||
return (
|
||||
<ActionContextProvider value={{ visible, setVisible }}>
|
||||
{options?.map((data, index) => {
|
||||
return (
|
||||
<Row key={index}>
|
||||
{data?.map((item, index) => {
|
||||
return (
|
||||
<Col span={6} key={index}>
|
||||
<Button
|
||||
style={{
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
border: '1px solid #f3f3f3',
|
||||
textAlign: 'center',
|
||||
padding: '20px 10px',
|
||||
}}
|
||||
onClick={() => {
|
||||
onClick(item);
|
||||
}}
|
||||
>
|
||||
{item.title.replace('审批流:', '')}
|
||||
</Button>
|
||||
</Col>
|
||||
);
|
||||
})}
|
||||
</Row>
|
||||
);
|
||||
})}
|
||||
<SchemaComponentContext.Provider value={{ ...context, designable: false }}>
|
||||
<SchemaComponent
|
||||
schema={schema}
|
||||
components={{
|
||||
RemoteSchemaComponent,
|
||||
CollectionProvider_deprecated,
|
||||
FlowContextProvider,
|
||||
ApplyActionStatusProvider,
|
||||
ActionBarProvider,
|
||||
ProviderActionResubmit: () => null,
|
||||
WithdrawActionProvider,
|
||||
}}
|
||||
scope={{
|
||||
useSubmit: useCreateSubmit,
|
||||
useWithdrawAction,
|
||||
useActionResubmit,
|
||||
}}
|
||||
/>
|
||||
</SchemaComponentContext.Provider>
|
||||
</ActionContextProvider>
|
||||
);
|
||||
};
|
@ -277,5 +277,6 @@
|
||||
"concat": "concat",
|
||||
"ms": "ms",
|
||||
"Resubmit": "Resubmit",
|
||||
"Are you sure you want to resubmit it?": "Are you sure you want to resubmit it?"
|
||||
"Are you sure you want to resubmit it?": "Are you sure you want to resubmit it?",
|
||||
"MyLaunch":"MyLaunch"
|
||||
}
|
||||
|
@ -358,5 +358,6 @@
|
||||
"concat": "连接",
|
||||
"ms": "毫秒",
|
||||
"Resubmit": "重新发起",
|
||||
"Are you sure you want to resubmit it?": "是否确定重新发起?"
|
||||
"Are you sure you want to resubmit it?": "是否确定重新发起?",
|
||||
"MyLaunch":"我的发起"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user