index.tsx 3.1 KB

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