index.tsx 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. import { useModel, useRequest } from 'umi'
  2. import Icon from '@/components/IconPark'
  3. import ProForm, { ProFormCheckbox, ProFormDependency, ProFormSwitch } from '@ant-design/pro-form'
  4. import type { FormInstance } from 'antd'
  5. import { message, Table, Tabs } from 'antd'
  6. import React, { useRef, useMemo, useState, useEffect } from 'react'
  7. import RoleMenu from './components/RoleMenu/roleMenu'
  8. import {
  9. fetchRoleStaffListByRoleId,
  10. updateRolePermission,
  11. getRolePermissions
  12. } from '@/services/user/api'
  13. import type { ColumnsType } from 'antd/lib/table'
  14. import ConnectModal from './components/ConnectModal'
  15. import { formatPermission } from '@/utils/utils'
  16. const System = () => {
  17. const { TabPane } = Tabs
  18. const formRef = useRef<FormInstance>(null)
  19. const columns: ColumnsType<API.RoleStaffListItem> = [
  20. {
  21. title: '用户',
  22. dataIndex: 'username',
  23. width: '15%'
  24. },
  25. {
  26. title: '手机',
  27. dataIndex: 'phone',
  28. width: '20%'
  29. },
  30. {
  31. title: '部门',
  32. dataIndex: 'departmentName',
  33. width: '20%'
  34. },
  35. {
  36. title: '岗位',
  37. dataIndex: 'position',
  38. width: '15%'
  39. },
  40. {
  41. title: '角色',
  42. dataIndex: 'age',
  43. width: '20%'
  44. },
  45. {
  46. title: '操作',
  47. dataIndex: 'opreate',
  48. width: '20%',
  49. render: () => (
  50. <span className="hover:text-hex-e7026e">
  51. <Icon type="delete" fill="#fd3995" />
  52. </span>
  53. )
  54. }
  55. ]
  56. const { initialState } = useModel('@@initialState')
  57. const menuId = useMemo(() => {
  58. return initialState?.menuList?.find(item => item.name === '系统管理')?.id
  59. }, initialState.menuList)
  60. const [state, setState] = useState({
  61. id: '',
  62. roleStaff: [],
  63. rolePermission: {}
  64. })
  65. const onSelect = (id: string) => {
  66. setState({ ...state, id })
  67. }
  68. const { run: tryGetRoleStaffList } = useRequest(
  69. (id: string) => fetchRoleStaffListByRoleId({ id }),
  70. {
  71. manual: true,
  72. onSuccess: result => {
  73. setState({ ...state, roleStaff: result })
  74. }
  75. }
  76. )
  77. const { run: tryGetRolePermissions } = useRequest((id: string) => getRolePermissions({ id }), {
  78. manual: true,
  79. onSuccess: (result: API.GetRolePermissionResultModel) => {
  80. const values = { ...formatPermission('init', result.permission) }
  81. formRef.current?.setFieldsValue({ ...values })
  82. }
  83. })
  84. useEffect(() => {
  85. if (state.id) {
  86. tryGetRoleStaffList(state.id)
  87. tryGetRolePermissions(state.id)
  88. }
  89. return () => {
  90. formRef.current?.resetFields()
  91. }
  92. }, [state.id])
  93. return (
  94. <div className="h-full w-full flex flex-row">
  95. <RoleMenu menuId={menuId} onSelect={onSelect} />
  96. <div className="w-max-3/4">
  97. <div className="ml-8 bg-white p-4 shadow-md shadow-hex-3e2c5a relative">
  98. <div className="absolute right-4 top-4 z-100">
  99. {state.id && (
  100. <ConnectModal
  101. title="关联员工"
  102. dataId={state.id}
  103. onSelect={() => tryGetRoleStaffList(state.id)}
  104. />
  105. )}
  106. </div>
  107. <Tabs defaultActiveKey="1" type="card">
  108. <TabPane tab="员工列表" key="1">
  109. <Table<API.RoleStaffListItem>
  110. dataSource={state.roleStaff}
  111. columns={columns}
  112. rowKey={row => row.staffId}
  113. />
  114. </TabPane>
  115. <TabPane tab="角色权限" key="2">
  116. {state.id && (
  117. <ProForm
  118. layout="horizontal"
  119. formRef={formRef}
  120. onFinish={async values => {
  121. const newValues = formatPermission('submit', values)
  122. await updateRolePermission({
  123. permission: JSON.stringify(newValues),
  124. id: state.id
  125. })
  126. message.success('设置成功')
  127. }}>
  128. {/* <ProFormSwitch
  129. name="showHome"
  130. label={
  131. <span className="flex items-center">
  132. <Icon type="home" className="mr-1" className="flex items-baseline mr-1" />
  133. 后台首页
  134. </span>
  135. }
  136. /> */}
  137. <ProFormSwitch
  138. name="showSystem"
  139. label={
  140. <span className="flex items-center">
  141. <Icon
  142. type="every-user"
  143. className="mr-1"
  144. className="flex items-baseline mr-1"
  145. />
  146. 角色权限管理
  147. </span>
  148. }
  149. />
  150. <ProFormDependency name={['showSystem']}>
  151. {({ showSystem }) => (
  152. <ProFormCheckbox.Group
  153. wrapperCol={{ offset: 1 }}
  154. // initialValue={}
  155. name="system"
  156. options={[
  157. { value: 'system', label: '系统管理', disabled: !showSystem },
  158. { value: 'customer', label: '客户', disabled: !showSystem }
  159. // { value: '3', label: '产品', disabled: !showAuth },
  160. // { value: '4', label: '开票合同', disabled: !showAuth },
  161. // { value: '5', label: '考勤', disabled: !showAuth },
  162. // { value: '6', label: '人资', disabled: !showAuth },
  163. // { value: '7', label: '财务费用', disabled: !showAuth }
  164. ]}
  165. />
  166. )}
  167. </ProFormDependency>
  168. {/* <ProFormSwitch
  169. name="showAudit"
  170. label={
  171. <span className="flex items-center">
  172. <Icon
  173. type="inspection"
  174. className="mr-1"
  175. className="flex items-baseline mr-1"
  176. />
  177. 审批流程
  178. </span>
  179. }
  180. />
  181. <ProFormDependency name={['showAudit']}>
  182. {({ showAudit }) => (
  183. <ProFormCheckbox.Group
  184. wrapperCol={{ offset: 1 }}
  185. name="audit"
  186. options={[
  187. { value: '1', label: '流程角色', disabled: !showAudit },
  188. { value: '2', label: '开票合同', disabled: !showAudit },
  189. { value: '3', label: '财务费用', disabled: !showAudit },
  190. { value: '4', label: '人资管理', disabled: !showAudit },
  191. { value: '5', label: '考勤', disabled: !showAudit }
  192. ]}
  193. />
  194. )}
  195. </ProFormDependency>
  196. <ProFormSwitch
  197. name="reset"
  198. label={
  199. <span className="flex items-center">
  200. <Icon
  201. type="association"
  202. className="mr-1"
  203. className="flex items-baseline mr-1"
  204. />
  205. 业务参数
  206. </span>
  207. }
  208. />
  209. <ProFormDependency name={['reset']}>
  210. {({ reset }) => (
  211. <ProFormCheckbox.Group
  212. wrapperCol={{ offset: 1 }}
  213. name="audit"
  214. options={[
  215. { value: '1', label: '客户', disabled: !reset },
  216. { value: '2', label: '产品', disabled: !reset }
  217. ]}
  218. />
  219. )}
  220. </ProFormDependency> */}
  221. </ProForm>
  222. )}
  223. </TabPane>
  224. </Tabs>
  225. </div>
  226. </div>
  227. </div>
  228. )
  229. }
  230. export default System