index.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import {
  2. fetchRoleListByMenu,
  3. fetchRoleListByRoleId,
  4. UnLinkRoleAccountItem
  5. } from '@/services/permission'
  6. import { DeleteOutlined } from '@ant-design/icons'
  7. import { PageContainer } from '@ant-design/pro-layout'
  8. import { message, Popconfirm, Table, Tabs } from 'antd'
  9. import type { ColumnsType } from 'antd/lib/table'
  10. import React, { useEffect, useState } from 'react'
  11. import { useRequest } from 'umi'
  12. import ConnectModal from './components/ConnectModal'
  13. import RoleLeftMenu from './components/RoleLeftMenu'
  14. import SetPermission from './components/SetPermission'
  15. const Role = () => {
  16. const [state, setState] = useState({
  17. ID: '',
  18. roleStaff: [],
  19. activeKey: ''
  20. })
  21. const [menuRoles, setMenuRoles] = useState<API.MenuRoleItem[]>([])
  22. const onSelect = (ID: string) => {
  23. setState({ ...state, ID })
  24. }
  25. const { TabPane } = Tabs
  26. // const { run: tryFetchRoleListByMenu } = useRequest(() => fetchRoleListByMenu(), {
  27. // manual: true,
  28. // onSuccess: result => {
  29. // setMenuRoles(result)
  30. // // setState({ ...state, ID: result[0]['ID'] })
  31. // }
  32. // })
  33. const { run: tryGetRoleStaffList } = useRequest(
  34. (roleID: string) => fetchRoleListByRoleId({ roleID }),
  35. {
  36. manual: true,
  37. onSuccess: result => {
  38. setState({ ...state, roleStaff: result.items })
  39. }
  40. }
  41. )
  42. const { run: tryUnLinkRoleAccount } = useRequest(
  43. (params: API.LinkAccountItem) => UnLinkRoleAccountItem(params),
  44. {
  45. manual: true,
  46. onSuccess: async () => {
  47. message.success('移除成功')
  48. await tryGetRoleStaffList(state.ID)
  49. }
  50. }
  51. )
  52. useEffect(() => {
  53. // tryFetchRoleListByMenu()
  54. if (state.ID) {
  55. tryGetRoleStaffList(state.ID)
  56. }
  57. }, [state.ID])
  58. const columns: ColumnsType<API.MenuByRoleIdItem> = [
  59. {
  60. title: '账号',
  61. dataIndex: 'account',
  62. width: '15%'
  63. },
  64. {
  65. title: '姓名',
  66. dataIndex: 'name',
  67. width: '15%'
  68. },
  69. {
  70. title: '企事业名称',
  71. dataIndex: 'institutionID',
  72. width: '35%',
  73. render: (_, record) => record.institution.name
  74. },
  75. {
  76. title: '操作',
  77. dataIndex: 'operation',
  78. width: '10%',
  79. render: (_, record) => (
  80. <Popconfirm
  81. title="确定移除吗?"
  82. okText="确定"
  83. cancelText="取消"
  84. onConfirm={() => tryUnLinkRoleAccount({ ID: state.ID, accountID: record.ID })}>
  85. <span className="text-hex-fd3995 cursor-pointer hover:text-hex-e7026e">
  86. <DeleteOutlined />
  87. </span>
  88. </Popconfirm>
  89. )
  90. }
  91. ]
  92. return (
  93. <PageContainer title={false}>
  94. <div className="h-full w-full flex flex-row">
  95. <RoleLeftMenu onSelect={onSelect}></RoleLeftMenu>
  96. <div className="w-6/7 ml-8 bg-white p-4 rounded-20px relative">
  97. <div className="absolute right-4 top-4 z-100">
  98. {state.ID && (
  99. <ConnectModal dataId={state.ID} onReload={() => tryGetRoleStaffList(state.ID)} />
  100. )}
  101. </div>
  102. <div>
  103. <Tabs>
  104. <TabPane tab="用户列表" key="1">
  105. <Table<API.MenuByRoleIdItem>
  106. columns={columns}
  107. dataSource={state.roleStaff}
  108. rowKey={row => row.id}
  109. />
  110. </TabPane>
  111. <TabPane tab="功能权限" key="2">
  112. <SetPermission activeKey={state.activeKey} />
  113. </TabPane>
  114. </Tabs>
  115. </div>
  116. </div>
  117. </div>
  118. </PageContainer>
  119. )
  120. }
  121. export default Role