import { useModel, useRequest } from 'umi' import { Delete, EveryUser } from '@icon-park/react' import ProForm, { ProFormCheckbox, ProFormDependency, ProFormSwitch } from '@ant-design/pro-form' import type { FormInstance } from 'antd' import { message, Table, Tabs, Popconfirm, Popover } from 'antd' import React, { useRef, useMemo, useState, useEffect } from 'react' import RoleMenu from './components/RoleMenu/roleMenu' import { fetchRoleStaffListByRoleId, updateRolePermission, getRolePermissions, deleteStaff } from '@/services/user/api' import type { ColumnsType } from 'antd/lib/table' import ConnectModal from './components/ConnectModal' import { formatPermission } from '@/utils/utils' const System = () => { const { TabPane } = Tabs const formRef = useRef(null) const { initialState } = useModel('@@initialState') const menuId = useMemo(() => { return initialState?.menuList?.find(item => item.name === '系统管理')?.id }, initialState.menuList) const [state, setState] = useState({ id: '', roleStaff: [], rolePermission: {}, activeKey: '' }) const onSelect = (id: string) => { setState({ ...state, id }) } const { run: tryGetRoleStaffList } = useRequest( (id: string) => fetchRoleStaffListByRoleId({ id }), { manual: true, onSuccess: result => { setState({ ...state, roleStaff: result }) } } ) const { run: tryGetRolePermissions } = useRequest((id: string) => getRolePermissions({ id }), { manual: true, onSuccess: (result: API.GetRolePermissionResultModel) => { const values = { ...formatPermission('init', result.permission) } setState({ ...state, rolePermission: values }) // formRef.current?.setFieldsValue({ ...values }) } }) const { run: tryDeleteStaff } = useRequest( (params: API.DeleteStaff) => { return deleteStaff(params) }, { manual: true, onSuccess: () => { message.success('移除员工成功') tryGetRoleStaffList(state.id) } } ) useEffect(() => { if (state.id) { tryGetRoleStaffList(state.id) tryGetRolePermissions(state.id) } if (state.activeKey === '2') { formRef.current?.setFieldsValue({ ...state.rolePermission }) } return () => { formRef.current?.resetFields() } }, [state.id, state.activeKey]) const columns: ColumnsType = [ { title: '用户', dataIndex: 'username', width: '15%' }, { title: '手机', dataIndex: 'phone', width: '20%' }, { title: '部门', dataIndex: 'departmentName', width: '20%' }, { title: '岗位', dataIndex: 'position', width: '15%' }, { title: '角色', dataIndex: 'age', width: '20%' }, { title: '操作', dataIndex: 'opreate', width: '20%', render: (_, record) => ( // console.log(record.staffId) <> {state.id && ( tryDeleteStaff({ id: state.id, staffId: record.staffId })}> )} ) } ] return (
{state.id && ( tryGetRoleStaffList(state.id)} /> )}
setState({ ...state, activeKey: key })}> dataSource={state.roleStaff} columns={columns} rowKey={row => row.staffId} />
{state.id && ( { const newValues = formatPermission('submit', values) await updateRolePermission({ permission: JSON.stringify(newValues), id: state.id }) message.success('设置成功') }}> {/* 后台首页 } /> */} 角色权限管理 } /> {({ showSystem }) => ( )} {/* 审批流程 } /> {({ showAudit }) => ( )} 业务参数 } /> {({ reset }) => ( )} */} )}
) } export default System