import { fetchRoleBgList, unLinkRoleBgAccount, fetchRoleBgStaffListByRoleId } from '@/services/permission' import { DeleteOutlined } from '@ant-design/icons' import { PageContainer } from '@ant-design/pro-layout' import { Input, message, Popconfirm, Table, Tabs } from 'antd' import { useState } from 'react' import { useRequest } from '@umijs/max' import RoleLeftMenu, { RoleType } from './components/RoleLeftMenu' import PermTabs from './components/PermTabs' import type { ColumnsType } from 'antd/lib/table' import ConnectModal from './components/ConnectModal' const { TabPane } = Tabs const Role = () => { const [state, setState] = useState({ activeTab: '1', currentRoleID: null, roleType: '', roleStaff: [] }) const [menuRoles, setMenuRoles] = useState([]) const { run: tryGetRoleBgStaffList, loading: staffListLoading } = useRequest( (params: { roleID: string; search?: string }) => fetchRoleBgStaffListByRoleId({ pageNo: 1, pageSize: 214000, ...params }), { manual: true, onSuccess: result => { setState({ ...state, roleStaff: result.items }) } } ) const { run: tryUnLinkRoleBgAccount } = useRequest( (params: API.LinkAccountParams) => unLinkRoleBgAccount(params), { manual: true, onSuccess: async () => { message.success('移除成功') await tryGetRoleBgStaffList({ roleID: state.currentRoleID }) } } ) const onSelect = (currentRoleID: string, roleType: string) => { if (state.currentRoleID === currentRoleID) return setState({ ...state, currentRoleID, roleType }) tryGetRoleBgStaffList({ roleID: currentRoleID }) } const { run: tryFetchRoleBgListByMenu } = useRequest(fetchRoleBgList, { onSuccess: result => { setMenuRoles( result.map(item => ({ key: item.ID, title: item.name, roleType: item.roleType })) ) result?.length && onSelect?.(state.currentRoleID ?? result[0]?.ID, result[0]?.roleType) } }) const delRoleValidFn = (ID: string) => { if (state.roleStaff.length) { return message.warning('请先移除该角色下的所有用户') } tryDelRoleBg(ID) } const columns: ColumnsType = [ { title: '账号', dataIndex: 'account', width: '15%' }, { title: '姓名', dataIndex: 'name', width: '15%' }, { title: '业务主体', dataIndex: 'institutionID', width: '35%', render: (_, record) => record.institution?.name }, { title: '操作', dataIndex: 'operation', width: '10%', render: (_, record) => ![RoleType.SYSTEM].includes(state.roleType) && ( { tryUnLinkRoleBgAccount({ ID: state.currentRoleID, accountID: record.ID }) }}> ) } ] const wrapHeight = document.querySelector('.ant-pro-page-container-warp')?.clientHeight || 0 return (
tryFetchRoleBgListByMenu()} delRoleValidFn={delRoleValidFn} />
tryGetRoleBgStaffList({ roleID: state.currentRoleID, search: value })} /> {state.currentRoleID && state.roleType !== RoleType.SYSTEM && ( tryGetRoleBgStaffList({ roleID: state.currentRoleID })} /> )}
) }} defaultActiveKey="1" onChange={key => setState({ ...state, activeTab: key })}> loading={staffListLoading} columns={columns} scroll={{ y: document.body.clientHeight - (285 + wrapHeight) }} dataSource={state.roleStaff} rowKey={row => row.ID} />
) } export default Role