index.tsx 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. import AnimateContent from '@/components/AnimateContent'
  2. import consts from '@/utils/consts'
  3. import { PageContainer } from '@ant-design/pro-layout'
  4. import ProTable from '@ant-design/pro-table'
  5. import { message } from 'antd'
  6. import { useRef, useState } from 'react'
  7. import { useRequest } from 'umi'
  8. import { getApprovalList, publishApproval, saveApproval } from '@/services/api/project'
  9. import type { ActionType } from '@ant-design/pro-table'
  10. import ApprovalDetail from './Detail'
  11. import { ModalForm, ProFormText } from '@ant-design/pro-form'
  12. import type { ProFormInstance } from '@ant-design/pro-form'
  13. export enum PublishType {
  14. FAIL = '0',
  15. SUCCESS = '1'
  16. }
  17. const FlowList = () => {
  18. const tRef = useRef<ActionType>(null)
  19. const formRef = useRef<ProFormInstance>(null)
  20. const [state, setState] = useState({
  21. params: {},
  22. visible: false,
  23. modalType: 'add',
  24. modalVisible: false,
  25. current: {
  26. ID: null,
  27. name: null,
  28. readPretty: false
  29. }
  30. })
  31. // const { run: tryDel } = useRequest(delApproval, {
  32. // manual: true,
  33. // onSuccess: () => {
  34. // tRef.current?.reload()
  35. // }
  36. // })
  37. // const { run: tryAdd } = useRequest(addApproval, {
  38. // manual: true,
  39. // onSuccess: () => {
  40. // tRef.current?.reload()
  41. // }
  42. // })
  43. const { run: tryPublish } = useRequest(publishApproval, {
  44. manual: true,
  45. onSuccess() {
  46. message.success('')
  47. tRef.current?.reload()
  48. }
  49. })
  50. const { run: tryUpdate } = useRequest(saveApproval, {
  51. manual: true,
  52. onSuccess: () => {
  53. tRef.current?.reload()
  54. }
  55. })
  56. const columns = [
  57. {
  58. dataIndex: 'name',
  59. title: '项目名称',
  60. onHeaderCell: () => ({ style: { textAlign: 'center' } })
  61. },
  62. {
  63. dataIndex: 'approval',
  64. title: '流程名称',
  65. onHeaderCell: () => ({ style: { textAlign: 'center' } }),
  66. renderText: (_, record) => (
  67. <span
  68. className="text-primary hover:cursor-pointer hover:text-blue-600"
  69. onClick={() => {
  70. setState({
  71. ...state,
  72. visible: true,
  73. current: record.approval
  74. })
  75. }}>
  76. {record.approval?.name}
  77. </span>
  78. )
  79. },
  80. {
  81. dataIndex: 'publish',
  82. title: '流程状态',
  83. valueEnum: {
  84. [PublishType.SUCCESS]: {
  85. text: '已发布',
  86. status: 'Success'
  87. },
  88. [PublishType.FAIL]: {
  89. text: '未发布',
  90. statis: 'Default'
  91. }
  92. }
  93. },
  94. {
  95. dataIndex: 'opreate',
  96. title: '操作',
  97. onHeaderCell: () => ({ style: { textAlign: 'center' } }),
  98. align: 'center',
  99. render: (_, record) => (
  100. <div className="divide-x divide-bg-gray-400 ">
  101. <span
  102. className="pr-2 text-primary cursor-pointer hover:text-hex-967bbd"
  103. onClick={() => {
  104. setState({ ...state, modalType: 'update', modalVisible: true })
  105. setTimeout(() => {
  106. formRef.current?.setFieldsValue({ ID: record.ID, name: record.approval?.name })
  107. }, 80)
  108. }}>
  109. 编辑流程名称
  110. </span>
  111. <span
  112. className="px-2 text-primary hover:cursor-pointer hover:text-blue-600"
  113. onClick={() =>
  114. setState({
  115. ...state,
  116. visible: true,
  117. current: { ...record.approval, readPretty: true }
  118. })
  119. }>
  120. 查看流程图
  121. </span>
  122. <span
  123. className={[
  124. 'pl-2',
  125. record.publish ? 'text-gray-500' : 'text-primary cursor-pointer'
  126. ].join(' ')}
  127. onClick={() => !record.publish && tryPublish({ ID: record.approval.ID })}>
  128. 发布
  129. </span>
  130. {/* <Popconfirm
  131. title={`确认删除${record.name}吗?`}
  132. okText="确认"
  133. cancelText="取消"
  134. onConfirm={() => tryDel({ ID: record.ID })}>
  135. <span className="text-red-500 pl-2 cursor-pointer hover:text-red-600">删除</span>
  136. </Popconfirm> */}
  137. </div>
  138. )
  139. }
  140. ]
  141. return (
  142. <PageContainer title={false}>
  143. <ProTable
  144. columns={columns}
  145. rowKey="ID"
  146. actionRef={tRef}
  147. params={state.params}
  148. scroll={{ y: document.body.clientHeight - 313 }}
  149. request={async (params, filters, sorter) => {
  150. const {
  151. code = -1,
  152. data: { items, total }
  153. } = await getApprovalList({ ...params, ...filters, ...sorter })
  154. return {
  155. success: code === consts.RET_CODE.SUCCESS,
  156. data: items,
  157. total
  158. }
  159. }}
  160. search={false}
  161. toolbar={{
  162. search: {
  163. onSearch: value => setState({ ...state, params: { ...state.params, search: value } })
  164. },
  165. actions: [
  166. // <Button
  167. // type="primary"
  168. // onClick={() => setState({ ...state, modalType: 'add', modalVisible: true })}
  169. // key="add_flow_btn">
  170. // 新建流程
  171. // </Button>
  172. ]
  173. }}
  174. />
  175. <AnimateContent
  176. title={state.current.name}
  177. visible={state.visible}
  178. onVisibleChange={visible => setState({ ...state, visible })}>
  179. <ApprovalDetail
  180. {...state.current}
  181. onVisibleChange={visible => setState({ ...state, visible })}
  182. />
  183. </AnimateContent>
  184. <ModalForm
  185. visible={state.modalVisible}
  186. isKeyPressSubmit
  187. modalProps={{
  188. width: '30%'
  189. }}
  190. onVisibleChange={visible => setState({ ...state, modalVisible: visible })}
  191. title={`${state.modalType === 'add' ? '新建' : '编辑'}审批流程`}
  192. formRef={formRef}
  193. onFinish={async values => {
  194. try {
  195. if (state.modalType === 'add') {
  196. await tryAdd(values)
  197. } else {
  198. await tryUpdate(values)
  199. }
  200. message.success(`${state.modalType === 'add' ? '新增' : '编辑'}成功`)
  201. tRef.current?.reload()
  202. return true
  203. } catch (error) {
  204. message.error(error)
  205. return false
  206. }
  207. }}>
  208. <ProFormText name="ID" label="名称" hidden />
  209. <ProFormText name="name" label="名称" rules={[{ required: true }]} />
  210. </ModalForm>
  211. </PageContainer>
  212. )
  213. }
  214. export default FlowList