布局修改
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import {
|
||||
Card, Table, Button, Typography, Space, Modal, Form,
|
||||
Input, Select, Popconfirm, message, Tag, Row, Col, Switch
|
||||
Input, Select, Popconfirm, message, Tag, Row, Col
|
||||
} from 'antd';
|
||||
import {
|
||||
PlusOutlined, EditOutlined, DeleteOutlined, UserOutlined
|
||||
PlusOutlined, EditOutlined, DeleteOutlined
|
||||
} from '@ant-design/icons';
|
||||
import { addUser, deleteUser, editUser, getUser } from '../api/user';
|
||||
import { getRoleList } from '../api/role';
|
||||
|
||||
const { Title } = Typography;
|
||||
const { Option } = Select;
|
||||
@@ -17,6 +18,7 @@ export default function UserList() {
|
||||
const [form] = Form.useForm();
|
||||
const [currentUser, setCurrentUser] = useState(null);
|
||||
const [messageApi, contextHolder] = message.useMessage();
|
||||
const [roles, setRoles] = useState([]);
|
||||
|
||||
// 统一分页
|
||||
const [pagination, setPagination] = useState({
|
||||
@@ -25,6 +27,16 @@ export default function UserList() {
|
||||
total: 0
|
||||
});
|
||||
|
||||
// 获取角色列表
|
||||
const getRole = () => {
|
||||
const params = { pageNum: 1, pageSize: 1000 };
|
||||
getRoleList(params).then(res => {
|
||||
if (res.code === 200) {
|
||||
setRoles(res.data || []);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// 获取用户列表
|
||||
const getUserList = () => {
|
||||
const params = {
|
||||
@@ -53,6 +65,7 @@ export default function UserList() {
|
||||
|
||||
useEffect(() => {
|
||||
getUserList();
|
||||
getRole();
|
||||
}, [pagination.pageNum, pagination.pageSize]);
|
||||
|
||||
// 新增
|
||||
@@ -65,8 +78,11 @@ export default function UserList() {
|
||||
// 编辑
|
||||
const handleEdit = (record) => {
|
||||
setCurrentUser(record);
|
||||
const roleIds = record.roles?.map(item => item.roleId) || [];
|
||||
|
||||
form.setFieldsValue({
|
||||
...record
|
||||
...record,
|
||||
roleIds: roleIds, // 回填多选角色
|
||||
});
|
||||
setModalVisible(true);
|
||||
};
|
||||
@@ -80,62 +96,66 @@ export default function UserList() {
|
||||
} else {
|
||||
messageApi.error(res.msg || '删除失败');
|
||||
}
|
||||
});
|
||||
}).catch(() => {
|
||||
messageApi.error('删除失败');
|
||||
})
|
||||
};
|
||||
|
||||
// 提交保存(完全匹配后端字段)
|
||||
// 提交保存
|
||||
const handleSubmit = () => {
|
||||
form.validateFields().then(values => {
|
||||
// 构建后端需要的完整参数
|
||||
const params = {
|
||||
...values,
|
||||
roleIds: values.roleId ? [values.roleId] : [] // 角色ID数组
|
||||
roleIds: values.roleIds || [], // 直接提交数组
|
||||
};
|
||||
|
||||
if (currentUser) {
|
||||
// 编辑
|
||||
params.userId = currentUser.userId;
|
||||
editUser(params).then(res => {
|
||||
if (res.code === 200) {
|
||||
messageApi.success('编辑成功');
|
||||
getUserList();
|
||||
setModalVisible(false);
|
||||
} else {
|
||||
messageApi.error(res.msg || '编辑失败');
|
||||
}
|
||||
}).catch(() => {
|
||||
messageApi.error('编辑失败');
|
||||
});
|
||||
} else {
|
||||
// 新增
|
||||
addUser(params).then(res => {
|
||||
if (res.code === 200) {
|
||||
messageApi.success('新增成功');
|
||||
getUserList();
|
||||
setModalVisible(false);
|
||||
} else {
|
||||
messageApi.error(res.msg || '新增失败');
|
||||
}
|
||||
});
|
||||
}).catch(() => {
|
||||
messageApi.error('新增失败');
|
||||
})
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// 表格列
|
||||
// 表格列(支持多角色展示)
|
||||
const columns = [
|
||||
{
|
||||
title: '用户账号',
|
||||
dataIndex: 'userName'
|
||||
},
|
||||
{
|
||||
title: '用户昵称',
|
||||
dataIndex: 'nickName'
|
||||
},
|
||||
{
|
||||
title: '手机号',
|
||||
dataIndex: 'phonenumber'
|
||||
},
|
||||
{
|
||||
title: '邮箱',
|
||||
dataIndex: 'email'
|
||||
},
|
||||
{ title: '用户账号', dataIndex: 'userName' },
|
||||
{ title: '用户昵称', dataIndex: 'nickName' },
|
||||
{ title: '手机号', dataIndex: 'phonenumber' },
|
||||
{ title: '邮箱', dataIndex: 'email' },
|
||||
{
|
||||
title: '角色',
|
||||
dataIndex: 'roleNames',
|
||||
render: (t) => <Tag color="blue">{t || '未分配'}</Tag>
|
||||
render: (_, record) => {
|
||||
const roles = record.roles || [];
|
||||
if (roles.length === 0) return <Tag>未分配</Tag>;
|
||||
|
||||
return roles.map(item => (
|
||||
<Tag color="blue" key={item.roleId}>
|
||||
{item.roleName || item.roleKey || '角色'}
|
||||
</Tag>
|
||||
));
|
||||
}
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
@@ -183,7 +203,7 @@ export default function UserList() {
|
||||
/>
|
||||
</Card>
|
||||
|
||||
{/* 新增/编辑弹窗(完全匹配后端字段) */}
|
||||
{/* 新增/编辑弹窗 */}
|
||||
<Modal
|
||||
title={currentUser ? '编辑用户' : '新增用户'}
|
||||
open={modalVisible}
|
||||
@@ -226,16 +246,26 @@ export default function UserList() {
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<Form.Item name="displayPassword" label="明文密码">
|
||||
<Input />
|
||||
<Form.Item name="language" label="语言">
|
||||
<Select placeholder="请选择语言">
|
||||
<Option value="zh-CN">中文</Option>
|
||||
<Option value="en">英语</Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Row gutter={16}>
|
||||
<Col span={12}>
|
||||
<Form.Item name="roleId" label="分配角色">
|
||||
<Input placeholder="角色ID" />
|
||||
{/* 多角色选择 */}
|
||||
<Form.Item name="roleIds" label="分配角色">
|
||||
<Select mode="multiple" placeholder="请选择角色">
|
||||
{roles.map(item => (
|
||||
<Option key={item.roleId} value={item.roleId}>
|
||||
{item.roleName || item.roleKey}
|
||||
</Option>
|
||||
))}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
@@ -248,19 +278,6 @@ export default function UserList() {
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Row gutter={16}>
|
||||
<Col span={12}>
|
||||
<Form.Item name="deptId" label="部门ID">
|
||||
<Input />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<Form.Item name="orgId" label="组织ID">
|
||||
<Input />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<Form.Item name="siteId" label="场站ID">
|
||||
<Input />
|
||||
</Form.Item>
|
||||
|
||||
Reference in New Issue
Block a user