index.tsx 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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 className="text-primary ">
  68. {record.stickyTop ? (
  69. <span className="w-30px text-center rounded-lg border border-hex-0089ff bg-hex-e9f5ff px-1">
  70. </span>
  71. ) : null}
  72. <span
  73. className="ml-2 hover:cursor-pointer hover:text-blue-600"
  74. onClick={() => {
  75. setState({
  76. ...state,
  77. visible: true,
  78. current: { dataID: record.ID, name: record.name, readPretty: true }
  79. })
  80. }}>
  81. {record.name}
  82. </span>
  83. </span>
  84. )
  85. },
  86. // {
  87. // dataIndex: 'publish',
  88. // title: '流程状态',
  89. // onHeaderCell: () => ({ style: { textAlign: 'center' } }),
  90. // valueEnum: {
  91. // [PublishType.SUCCESS]: {
  92. // text: '已发布',
  93. // status: 'Success'
  94. // },
  95. // [PublishType.FAIL]: {
  96. // text: '未发布',
  97. // statis: 'Default'
  98. // }
  99. // }
  100. // },
  101. {
  102. dataIndex: 'opreate',
  103. title: '操作',
  104. onHeaderCell: () => ({ style: { textAlign: 'center' } }),
  105. align: 'center',
  106. render: (_, record) => (
  107. <div className="divide-x divide-bg-gray-400">
  108. <span
  109. className="pr-2 text-primary cursor-pointer hover:text-hex-967bbd"
  110. onClick={() => {
  111. setState({
  112. ...state,
  113. modalType: ApprovalModalType.UPDATE,
  114. modalVisible: true,
  115. current: { dataID: record.ID, name: record.name }
  116. })
  117. }}>
  118. 编辑名称
  119. </span>
  120. <span
  121. className="px-2 text-primary cursor-pointer hover:text-hex-967bbd"
  122. onClick={() => {
  123. setState({
  124. ...state,
  125. visible: true,
  126. current: { dataID: record.ID, name: record.name }
  127. })
  128. }}>
  129. 配置流程
  130. </span>
  131. <Popconfirm
  132. title="是否删除此流程模板?"
  133. okText="确定"
  134. cancelText="取消"
  135. onConfirm={() => tryDel({ ID: record.ID })}>
  136. <span className={classNames('text-red-500 pl-2 cursor-pointer hover:text-red-600', {})}>
  137. 删除
  138. </span>
  139. </Popconfirm>
  140. </div>
  141. )
  142. }
  143. ]
  144. return (
  145. <PageContainer title={false}>
  146. <ProTable
  147. columns={columns}
  148. rowKey="ID"
  149. actionRef={tRef}
  150. params={state.params}
  151. scroll={{ y: document.body.clientHeight - 313 }}
  152. request={async (params, filters, sorter) => {
  153. const {
  154. code = -1,
  155. data: { items, total }
  156. } = await getApprovalList({ ...params, ...filters, ...sorter })
  157. return {
  158. success: code === consts.RET_CODE.SUCCESS,
  159. data: items,
  160. total
  161. }
  162. }}
  163. search={false}
  164. toolbar={{
  165. search: {
  166. onSearch: value => setState({ ...state, params: { ...state.params, search: value } })
  167. },
  168. actions: [
  169. <Button
  170. type="primary"
  171. onClick={() =>
  172. setState({ ...state, modalType: ApprovalModalType.ADD, modalVisible: true })
  173. }
  174. key="add_flow_btn">
  175. 新建流程
  176. </Button>
  177. ]
  178. }}
  179. />
  180. <AnimateContent
  181. title={state.current.name}
  182. visible={state.visible}
  183. onVisibleChange={visible => setState({ ...state, visible })}>
  184. <ApprovalDetail
  185. {...state.current}
  186. onVisibleChange={visible => setState({ ...state, visible })}
  187. />
  188. </AnimateContent>
  189. <ModalForm
  190. visible={state.modalVisible}
  191. isKeyPressSubmit
  192. layout="horizontal"
  193. modalProps={{
  194. width: '30%'
  195. }}
  196. onVisibleChange={visible => setState({ ...state, modalVisible: visible })}
  197. title={`${state.modalType === ApprovalModalType.ADD ? '新建' : '编辑'}审批流程`}
  198. formRef={formRef}
  199. onFinish={async values => {
  200. try {
  201. if (state.modalType === ApprovalModalType.ADD) {
  202. await tryAdd(values)
  203. } else {
  204. await tryUpdate({ ...values, ID: state.current.dataID })
  205. }
  206. message.success(`${state.modalType === ApprovalModalType.ADD ? '新增' : '编辑'}成功`)
  207. tRef.current?.reload()
  208. return true
  209. } catch (error) {
  210. message.error(error)
  211. return false
  212. }
  213. }}>
  214. <ProFormText name="name" label="名称" rules={[{ required: true }]} />
  215. </ModalForm>
  216. </PageContainer>
  217. )
  218. }
  219. export default FlowList