import React, { useState, useRef, useEffect } from 'react'; import { useIntl, FormattedMessage, useAccess, history, useParams } from '@umijs/max'; import { Button, Modal, message } from 'antd'; import { ActionType, PageContainer, ProColumns, ProTable } from '@ant-design/pro-components'; import { PlusOutlined, DeleteOutlined, ExclamationCircleOutlined, RollbackOutlined } from '@ant-design/icons'; import { authUserSelectAll, authUserCancel, authUserCancelAll, allocatedUserList, unallocatedUserList } from '@/services/system/role'; import { getDictValueEnum } from '@/services/system/dict'; import DictTag from '@/components/DictTag'; import UserSelectorModal from './components/UserSelectorModal'; import { HttpResult } from '@/enums/httpEnum'; /** * 删除节点 * * @param selectedRows */ const cancelAuthUserAll = async (roleId: string, selectedRows: API.System.User[]) => { const hide = message.loading('正在取消授权'); if (!selectedRows) return true; try { const userIds = selectedRows.map((row) => row.userId).join(','); const resp = await authUserCancelAll({roleId, userIds}); hide(); if (resp.code === 200) { message.success('取消授权成功,即将刷新'); } else { message.error(resp.msg); } return true; } catch (error) { hide(); message.error('取消授权失败,请重试'); return false; } }; const cancelAuthUser = async (roleId: string, userId: number) => { const hide = message.loading('正在取消授权'); try { const resp = await authUserCancel({ userId, roleId }); hide(); if (resp.code === 200) { message.success('取消授权成功,即将刷新'); } else { message.error(resp.msg); } return true; } catch (error) { hide(); message.error('取消授权失败,请重试'); return false; } }; const AuthUserTableList: React.FC = () => { const [modalVisible, setModalVisible] = useState(false); const actionRef = useRef(); const [selectedRows, setSelectedRows] = useState([]); const [statusOptions, setStatusOptions] = useState([]); const access = useAccess(); /** 国际化配置 */ const intl = useIntl(); const params = useParams(); if (params.id === undefined) { history.back(); } const roleId = params.id || '0'; useEffect(() => { getDictValueEnum('sys_normal_disable').then((data) => { setStatusOptions(data); }); }, []); const columns: ProColumns[] = [ { title: , dataIndex: 'deptId', valueType: 'text', }, { title: , dataIndex: 'userName', valueType: 'text', }, { title: , dataIndex: 'nickName', valueType: 'text', }, { title: , dataIndex: 'phonenumber', valueType: 'text', }, { title: , dataIndex: 'createTime', valueType: 'dateRange', render: (_, record) => { return ({record.createTime.toString()} ); }, hideInSearch: true, }, { title: , dataIndex: 'status', valueType: 'select', valueEnum: statusOptions, render: (_, record) => { return (); }, }, { title: , dataIndex: 'option', width: '60px', valueType: 'option', render: (_, record) => [ , ], }, ]; return (
headerTitle={intl.formatMessage({ id: 'pages.searchTable.title', defaultMessage: '信息', })} actionRef={actionRef} rowKey="userId" key="userList" search={{ labelWidth: 120, }} toolBarRender={() => [ , , , ]} request={(params) => allocatedUserList({ ...params, roleId } as API.System.RoleListParams).then((res) => { const result = { data: res.rows, total: res.total, success: true, }; return result; }) } columns={columns} rowSelection={{ onChange: (_, selectedRows) => { setSelectedRows(selectedRows); }, }} />
{ const userIds = values.join(","); if (userIds === "") { message.warning("请选择要分配的用户"); return; } authUserSelectAll({ roleId: roleId, userIds: userIds }).then(resp => { if (resp.code === HttpResult.SUCCESS) { message.success('更新成功!'); if (actionRef.current) { actionRef.current.reload(); } } else { message.warning(resp.msg); } }) setModalVisible(false); }} onCancel={() => { setModalVisible(false); }} params={{roleId}} request={(params) => unallocatedUserList({ ...params } as API.System.RoleListParams).then((res) => { const result = { data: res.rows, total: res.rows.length, success: true, }; return result; }) } />
); }; export default AuthUserTableList;