import { userPage, userUpPwd, userInfo, userUpdate, userAdd, userDelete } from '@/services/system/user'; import React, { useState, useRef, useEffect } from 'react'; import { useIntl, FormattedMessage, useAccess } from '@umijs/max'; import { Button, message, Modal, Tag, Image } from 'antd'; import { ActionType, PageContainer, ProColumns, ProTable } from '@ant-design/pro-components'; import { PlusOutlined } from '@ant-design/icons'; import UpdateForm from './edit'; /** * 添加节点 * * @param fields */ const handleAdd = async (fields: API.System.Menu) => { const hide = message.loading('正在添加'); try { await userAdd({ ...fields }); hide(); message.success('添加成功'); return true; } catch (error) { hide(); message.error('添加失败请重试!'); return false; } }; /** * 更新节点 * * @param fields */ const handleUpdate = async (fields: API.System.Menu) => { const hide = message.loading('正在修改'); try { await userUpdate(fields); hide(); message.success('修改成功'); return true; } catch (error) { hide(); message.error('修改失败请重试!'); return false; } }; const handleRemoveOne = async (selectedRow: API.System.Menu) => { const hide = message.loading('正在删除'); if (!selectedRow) return true; try { const params = [selectedRow.id]; await userDelete(params); hide(); message.success('删除成功,即将刷新'); return true; } catch (error) { hide(); message.error('删除失败,请重试'); return false; } }; const UserTableList: React.FC = () => { const [modalVisible, setModalVisible] = useState(false); const [currentRow, setCurrentRow] = useState(); const actionRef = useRef(); /** 国际化配置 */ const intl = useIntl(); const access = useAccess(); useEffect(() => { // getDictValueEnum('sys_show_hide').then((data) => { // setVisibleOptions(data); // }); // getDictValueEnum('sys_normal_disable').then((data) => { // setStatusOptions(data); // }); }, []); const columns = [ { title: 'ID', dataIndex: 'id', valueType: 'text', search: false, }, { title: '用户信息', dataIndex: 'username', valueType: 'text', search: false, render: (_: any, record: any) => { return
昵称:{record.nickName}
用户名:{record.username}
手机号:{record.phoneNumber}
} }, { title: '角色', dataIndex: 'sysRoleDTOList', valueType: 'text', render: (_: any, record: any) => { return record?.sysRoleDTOList?.map((item: any) => { return {item.roleName} }) } }, { title: '邮箱', dataIndex: 'email', valueType: 'text', search: false, }, { title: '性别', dataIndex: 'sexName', valueType: 'text', search: false, }, { title: '最后登录IP', dataIndex: 'loginIp', valueType: 'text', search: false, }, { title: '最后登录时间', dataIndex: 'loginDate', valueType: 'text', search: false, }, { title: '创建时间', dataIndex: 'createTime', search: false, }, { title: , dataIndex: 'option', width: '220px', valueType: 'option', render: (_, record: any) => [ , , ], }, ]; return (
actionRef={actionRef} rowKey="id" key="userList" search={{ labelWidth: 120, }} toolBarRender={() => [ , ]} request={async (params, sorter, filter) => { let { data } = await userPage(params) return { data: data?.records || [], total: data?.total, }; }} columns={columns} />
{ let success = false; if (values.id) { success = await handleUpdate({ ...values }); } else { success = await handleAdd({ ...values }); } if (success) { setModalVisible(false); setCurrentRow(undefined); if (actionRef.current) { actionRef.current.reload(); } } }} onCancel={() => { setModalVisible(false); setCurrentRow(undefined); }} open={modalVisible} values={currentRow || {}} />
); }; export default UserTableList;