|
@@ -1,19 +1,47 @@
|
|
|
import AnimateContent from '@/components/AnimateContent'
|
|
|
-import { getApprovalList } from '@/services/api/project'
|
|
|
import consts from '@/utils/consts'
|
|
|
import { PageContainer } from '@ant-design/pro-layout'
|
|
|
import ProTable from '@ant-design/pro-table'
|
|
|
-import { Button } from 'antd'
|
|
|
-import { useState } from 'react'
|
|
|
+import { Button, message, Popconfirm } from 'antd'
|
|
|
+import { useRef, useState } from 'react'
|
|
|
+import { useRequest } from 'umi'
|
|
|
+import { delApproval, getApprovalList, addApproval, updateApproval } from '@/services/api/project'
|
|
|
+import type { ActionType } from '@ant-design/pro-table'
|
|
|
+
|
|
|
import ApprovalDetail from './Detail'
|
|
|
+import { ModalForm, ProFormText } from '@ant-design/pro-form'
|
|
|
+import type { ProFormInstance } from '@ant-design/pro-form'
|
|
|
const FlowList = () => {
|
|
|
+ const tRef = useRef<ActionType>(null)
|
|
|
+ const formRef = useRef<ProFormInstance>(null)
|
|
|
const [state, setState] = useState({
|
|
|
params: {},
|
|
|
visible: false,
|
|
|
+ modalType: 'add',
|
|
|
+ modalVisible: false,
|
|
|
current: {
|
|
|
id: null
|
|
|
}
|
|
|
})
|
|
|
+
|
|
|
+ const { run: tryDel } = useRequest(delApproval, {
|
|
|
+ manual: true,
|
|
|
+ onSuccess: () => {
|
|
|
+ tRef.current?.reload()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ const { run: tryAdd } = useRequest(addApproval, {
|
|
|
+ manual: true,
|
|
|
+ onSuccess: () => {
|
|
|
+ tRef.current?.reload()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ const { run: tryUpdate } = useRequest(updateApproval, {
|
|
|
+ manual: true,
|
|
|
+ onSuccess: () => {
|
|
|
+ tRef.current?.reload()
|
|
|
+ }
|
|
|
+ })
|
|
|
const columns = [
|
|
|
{
|
|
|
dataIndex: 'name',
|
|
@@ -30,12 +58,33 @@ const FlowList = () => {
|
|
|
<span
|
|
|
className="pr-2 text-primary cursor-pointer hover:text-hex-967bbd"
|
|
|
onClick={() => {
|
|
|
- setState({ ...state, visible: true, current: { ...state.current, id: record.ID } })
|
|
|
+ setState({ ...state, modalType: 'update', modalVisible: true })
|
|
|
+ formRef.current?.setFieldsValue({ ID: record.ID, name: record.name })
|
|
|
}}>
|
|
|
编辑
|
|
|
</span>
|
|
|
- <span className="px-2 text-primary cursor-pointer hover:text-hex-967bbd">设置审批人</span>
|
|
|
- <span className="text-hex-F5222D pl-2 cursor-pointer hover:text-hex-967bbd">删除</span>
|
|
|
+ <span
|
|
|
+ className="px-2 text-primary cursor-pointer hover:text-hex-967bbd"
|
|
|
+ onClick={() => {
|
|
|
+ setState({
|
|
|
+ ...state,
|
|
|
+ visible: true,
|
|
|
+ current: {
|
|
|
+ id: record.ID,
|
|
|
+ flowProcess: record.flowProcess,
|
|
|
+ flowProcessData: record.flowProcessData
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }}>
|
|
|
+ 设置审批人
|
|
|
+ </span>
|
|
|
+ <Popconfirm
|
|
|
+ title={`确认删除${record.name}吗?`}
|
|
|
+ okText="确认"
|
|
|
+ cancelText="取消"
|
|
|
+ onConfirm={() => tryDel({ ID: record.ID })}>
|
|
|
+ <span className="text-hex-F5222D pl-2 cursor-pointer hover:text-hex-967bbd">删除</span>
|
|
|
+ </Popconfirm>
|
|
|
</div>
|
|
|
)
|
|
|
}
|
|
@@ -45,6 +94,7 @@ const FlowList = () => {
|
|
|
<ProTable
|
|
|
columns={columns}
|
|
|
rowKey="ID"
|
|
|
+ actionRef={tRef}
|
|
|
params={state.params}
|
|
|
request={async (params, filters, sorter) => {
|
|
|
const {
|
|
@@ -65,7 +115,7 @@ const FlowList = () => {
|
|
|
actions: [
|
|
|
<Button
|
|
|
type="primary"
|
|
|
- onClick={() => setState({ ...state, visible: true })}
|
|
|
+ onClick={() => setState({ ...state, modalType: 'add', modalVisible: true })}
|
|
|
key="add_flow_btn">
|
|
|
新建流程
|
|
|
</Button>
|
|
@@ -75,8 +125,33 @@ const FlowList = () => {
|
|
|
<AnimateContent
|
|
|
visible={state.visible}
|
|
|
onVisibleChange={visible => setState({ ...state, visible })}>
|
|
|
- <ApprovalDetail {...state.current}></ApprovalDetail>
|
|
|
+ <ApprovalDetail
|
|
|
+ data={state.current}
|
|
|
+ onVisibleChange={visible => setState({ ...state, visible })}
|
|
|
+ />
|
|
|
</AnimateContent>
|
|
|
+ <ModalForm
|
|
|
+ visible={state.modalVisible}
|
|
|
+ onVisibleChange={visible => setState({ ...state, modalVisible: visible })}
|
|
|
+ title={`${state.modalType === 'add' ? '新建' : '更新'}审批流程`}
|
|
|
+ formRef={formRef}
|
|
|
+ onFinish={async values => {
|
|
|
+ try {
|
|
|
+ if (state.modalType === 'add') {
|
|
|
+ await tryAdd(values)
|
|
|
+ } else {
|
|
|
+ await tryUpdate(values)
|
|
|
+ }
|
|
|
+ message.success(`${state.modalType === 'add' ? '新增' : '更新'}成功`)
|
|
|
+ return true
|
|
|
+ } catch (error) {
|
|
|
+ message.error(error)
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }}>
|
|
|
+ <ProFormText name="ID" label="名称" hidden />
|
|
|
+ <ProFormText name="name" label="名称" />
|
|
|
+ </ModalForm>
|
|
|
</PageContainer>
|
|
|
)
|
|
|
}
|