index.tsx 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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 { Button, message, Popconfirm } from 'antd'
  6. import { useRef, useState } from 'react'
  7. import { useRequest } from 'umi'
  8. import { addApproval, delApproval, getApprovalList, saveApproval } from '@/services/api/project'
  9. import type { ActionType, ProColumnType } 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. import classNames from 'classnames'
  14. // export enum PublishType {
  15. // FAIL = '0',
  16. // SUCCESS = '1'
  17. // }
  18. export enum ApprovalModalType {
  19. ADD,
  20. UPDATE
  21. }
  22. const FlowList = () => {
  23. const tRef = useRef<ActionType>(null)
  24. const formRef = useRef<ProFormInstance>(null)
  25. const [state, setState] = useState({
  26. params: {},
  27. visible: false,
  28. modalType: 'add',
  29. modalVisible: false,
  30. current: {
  31. dataID: null,
  32. name: null,
  33. readPretty: false
  34. }
  35. })
  36. const { run: tryDel } = useRequest(delApproval, {
  37. manual: true,
  38. onSuccess: () => {
  39. tRef.current?.reload()
  40. }
  41. })
  42. const { run: tryAdd } = useRequest(addApproval, {
  43. manual: true,
  44. onSuccess: () => {
  45. tRef.current?.reload()
  46. }
  47. })
  48. // const { run: tryPublish } = useRequest(publishApproval, {
  49. // manual: true,
  50. // onSuccess() {
  51. // message.success('')
  52. // tRef.current?.reload()
  53. // }
  54. // })
  55. const { run: tryUpdate } = useRequest(saveApproval, {
  56. manual: true,
  57. onSuccess: () => {
  58. tRef.current?.reload()
  59. }
  60. })
  61. const columns: ProColumnType = [
  62. {
  63. dataIndex: 'name',
  64. title: '模板名称',
  65. onHeaderCell: () => ({ style: { textAlign: 'center' } }),
  66. render: (_, 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: { dataID: record.ID, name: record.name, readPretty: true }
  74. })
  75. tRef
  76. }}>
  77. {record.stickyTop ? (
  78. <span className="w-30px text-center rounded-md border border-hex-0089ff bg-hex-e9f5ff px-1">
  79. </span>
  80. ) : null}
  81. <span className="ml-1 ">{record.name}</span>
  82. </span>
  83. )
  84. },
  85. // {
  86. // dataIndex: 'publish',
  87. // title: '流程状态',
  88. // onHeaderCell: () => ({ style: { textAlign: 'center' } }),
  89. // valueEnum: {
  90. // [PublishType.SUCCESS]: {
  91. // text: '已发布',
  92. // status: 'Success'
  93. // },
  94. // [PublishType.FAIL]: {
  95. // text: '未发布',
  96. // statis: 'Default'
  97. // }
  98. // }
  99. // },
  100. {
  101. dataIndex: 'opreate',
  102. title: '操作',
  103. onHeaderCell: () => ({ style: { textAlign: 'center' } }),
  104. align: 'center',
  105. render: (_, record) => (
  106. <div className="divide-x divide-bg-gray-400">
  107. <span
  108. className="pr-2 text-primary cursor-pointer hover:text-hex-967bbd"
  109. onClick={() => {
  110. setState({
  111. ...state,
  112. modalType: ApprovalModalType.UPDATE,
  113. modalVisible: true,
  114. current: { dataID: record.ID, name: record.name }
  115. })
  116. setTimeout(() => {
  117. formRef.current?.setFieldsValue({ name: record.name })
  118. }, 80)
  119. }}>
  120. 编辑名称
  121. </span>
  122. <span
  123. className="px-2 text-primary cursor-pointer hover:text-hex-967bbd"
  124. onClick={() => {
  125. setState({
  126. ...state,
  127. visible: true,
  128. current: { dataID: record.ID, name: record.name }
  129. })
  130. }}>
  131. 配置流程
  132. </span>
  133. <Popconfirm
  134. disabled={record?.canDel}
  135. title="是否删除此流程模板?"
  136. okText="确定"
  137. cancelText="取消"
  138. onConfirm={() => tryDel({ ID: record.ID })}>
  139. <span
  140. className={classNames(
  141. 'pl-2',
  142. record?.canDel ? 'text-gray-500' : 'text-red-500 cursor-pointer hover:text-red-600'
  143. )}>
  144. 删除
  145. </span>
  146. </Popconfirm>
  147. </div>
  148. )
  149. }
  150. ]
  151. return (
  152. <PageContainer title={false}>
  153. <ProTable
  154. columns={columns}
  155. rowKey="ID"
  156. actionRef={tRef}
  157. params={state.params}
  158. scroll={{ y: document.body.clientHeight - 313 }}
  159. request={async (params, filters, sorter) => {
  160. const {
  161. code = -1,
  162. data: { items, total }
  163. } = await getApprovalList({ ...params, ...filters, ...sorter })
  164. return {
  165. success: code === consts.RET_CODE.SUCCESS,
  166. data: items,
  167. total
  168. }
  169. }}
  170. search={false}
  171. toolbar={{
  172. search: {
  173. onSearch: value => setState({ ...state, params: { ...state.params, search: value } }),
  174. style: { width: '250px' },
  175. placeholder: '请输入流程名称'
  176. },
  177. actions: [
  178. <Button
  179. type="primary"
  180. onClick={() => {
  181. setState({
  182. ...state,
  183. modalType: ApprovalModalType.ADD,
  184. modalVisible: true
  185. })
  186. }}
  187. key="add_flow_btn">
  188. 新建流程
  189. </Button>
  190. ]
  191. }}
  192. />
  193. <AnimateContent
  194. title={state.current.name}
  195. visible={state.visible}
  196. onVisibleChange={visible => setState({ ...state, visible })}>
  197. <ApprovalDetail
  198. {...state.current}
  199. onVisibleChange={visible => setState({ ...state, visible })}
  200. />
  201. </AnimateContent>
  202. <ModalForm
  203. visible={state.modalVisible}
  204. isKeyPressSubmit
  205. layout="horizontal"
  206. modalProps={{
  207. width: '30%'
  208. }}
  209. onVisibleChange={visible => {
  210. setState({ ...state, modalVisible: visible })
  211. setTimeout(() => {
  212. if (!visible) formRef.current?.resetFields()
  213. }, 80)
  214. }}
  215. title={`${state.modalType === ApprovalModalType.ADD ? '新建' : '编辑'}审批流程`}
  216. formRef={formRef}
  217. onFinish={async values => {
  218. try {
  219. if (state.modalType === ApprovalModalType.ADD) {
  220. await tryAdd(values)
  221. } else {
  222. await tryUpdate({ ...values, ID: state.current.dataID })
  223. }
  224. message.success(`${state.modalType === ApprovalModalType.ADD ? '新增' : '编辑'}成功`)
  225. tRef.current?.reload()
  226. return true
  227. } catch (error) {
  228. message.error(error)
  229. return false
  230. }
  231. }}>
  232. <ProFormText
  233. name="name"
  234. label="名称"
  235. rules={[{ required: true, message: '请输入流程名称' }]}
  236. />
  237. </ModalForm>
  238. </PageContainer>
  239. )
  240. }
  241. export default FlowList