import { ProColumns, ActionType } from '@ant-design/pro-table'; import { useRequest } from 'ahooks'; import { Button, Modal, Space, Switch, Tag, message } from 'antd'; import React, { useRef, useState } from 'react'; import Truly from '../../components/Truly'; import { OPTIONS } from '../../constants'; import { getDocSelections, getMenuSelections, getRoleSelections, } from '../../services'; import { isTrue } from '../../utils/auth'; import EditForm from './EditForm'; import PasswordForm from './Password'; import RoleForm from './RoleForm'; import AuthForm from './AuthForm'; import BaseTable from '../../components/BaseTable'; import { UserFields, delApi, unlockApi, changeStatusApi, getListApi, } from './services'; import { sessionStore } from '../../utils/store'; const User: React.FC = () => { const appId: string = sessionStore.get('current-appId'); const { data: docList } = useRequest(getDocSelections); const { data: roleList } = useRequest(getRoleSelections); const { data: menuList } = useRequest(() => getMenuSelections(appId)); const [selectRows, setSelectRows] = useState([]); const actionRef = useRef(); const onDelete = (record: UserFields) => { Modal.confirm({ title: '操作提示', content: `是否确认删除用户名称为"${record.userName}"的数据项?`, maskClosable: true, onOk: async () => { await delApi(record.userId); actionRef.current?.reload(); }, okText: '确定', cancelText: '取消', }); }; const onBatchLock = () => { Modal.confirm({ title: '操作提示', content: `是否确认执行批量解锁操作?`, maskClosable: true, onOk: async () => { const userIds = selectRows.map((item) => item.userId); await unlockApi(userIds); actionRef.current?.reload(); message.success('操作成功!'); }, okText: '确定', cancelText: '取消', }); }; const onLock = (record: UserFields) => { Modal.confirm({ title: '操作提示', content: `是否确认解锁用户名为"${record.userName}"操作?`, maskClosable: true, onOk: async () => { await unlockApi([record.userId]); actionRef.current?.reload(); }, okText: '确定', cancelText: '取消', }); }; const columns: ProColumns[] = [ { title: '名称', dataIndex: 'userName', ellipsis: true, }, { title: '昵称', dataIndex: 'nickName', hideInSearch: true, ellipsis: true, }, { title: '用户类别', dataIndex: 'userType', hideInSearch: true, ellipsis: true, valueType: 'select', fieldProps: { options: OPTIONS.OPTIONS_USER, }, }, { title: '邮箱', dataIndex: 'email', ellipsis: true, hideInSearch: true, }, { title: '手机号', ellipsis: true, dataIndex: 'phonenumber', hideInSearch: true, }, { title: '状态', dataIndex: 'status', hideInTable: true, valueType: 'select', fieldProps: { options: OPTIONS.OPTIONS_AVAILABLE, }, }, { title: '状态', dataIndex: 'status', ellipsis: true, hideInSearch: true, render: (_, record) => { if (isTrue('administration:user:switch')) { return ( { const { userId, status: preStatus } = record; const status = preStatus === '1' ? '2' : '1'; await changeStatusApi({ userId, status }); actionRef.current?.reload(); }} /> ); } else if (record.status === '1') { return 启用; } return 停用; }, }, { title: '是否锁定', dataIndex: 'lock', hideInSearch: true, ellipsis: true, render: (text, record) => { if (record.lock === '2') { return 是; } return 否; }, }, { title: '创建时间', key: 'showTime', dataIndex: 'createTime', valueType: 'dateTime', hideInSearch: true, ellipsis: true, }, { title: '创建时间', dataIndex: 'createTime', valueType: 'dateRange', hideInTable: true, search: { transform: (value) => { return { 'params[beginTime]': value[0], 'params[endTime]': value[1], }; }, }, }, { title: '操作', dataIndex: 'option', valueType: 'option', width: 320, fixed: 'right', render: (_, record) => ( 编辑} onOk={() => { actionRef.current?.reload(); }} > 重置密码} onOk={() => { actionRef.current?.reload(); }} > 分配权限} onOk={() => { actionRef.current?.reload(); }} > 分配角色} onOk={() => { actionRef.current?.reload(); }} > ), }, ]; return ( setSelectRows(rows), }} toolBarRender={() => [ 新增} onOk={() => { actionRef.current?.reload(); }} > , , ]} columns={columns} request={async (params) => { const { current: pageNum, ...rest } = params; const { total = 0, data = [] } = await getListApi({ ...rest, pageNum, }); actionRef.current?.clearSelected?.(); return { data, total, }; }} /> ); }; export default User;