加上分页
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import {
|
||||
Card, Row, Col, Button, Typography, Space, Modal, Form, Tree, message,
|
||||
Input, Popconfirm, Divider, InputNumber, Switch
|
||||
Input, Popconfirm, Divider, InputNumber, Switch, Pagination
|
||||
} from 'antd';
|
||||
import {
|
||||
PlusOutlined, EditOutlined, DeleteOutlined, CloseOutlined
|
||||
@@ -23,18 +23,39 @@ export default function Roles() {
|
||||
const [editRole, setEditRole] = useState(null);
|
||||
const [messageApi, contextHolder] = message.useMessage();
|
||||
|
||||
// 获取角色列表
|
||||
// 统一分页
|
||||
const [pagination, setPagination] = useState({
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
total: 0
|
||||
});
|
||||
|
||||
// 获取角色列表(带分页)
|
||||
const getRole = () => {
|
||||
getRoleList().then(res => {
|
||||
const params = {
|
||||
pageNum: pagination.pageNum,
|
||||
pageSize: pagination.pageSize
|
||||
};
|
||||
|
||||
getRoleList(params).then(res => {
|
||||
if (res.code == 200) {
|
||||
setRoles(res.data || []);
|
||||
setPagination({
|
||||
...pagination,
|
||||
total: res.total || res.data?.length || 0
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 获取菜单树
|
||||
const getMenu = () => {
|
||||
getMenuList().then(res => {
|
||||
const params = {
|
||||
pageNum: 1,
|
||||
pageSize: 1000
|
||||
};
|
||||
|
||||
getMenuList(params).then(res => {
|
||||
if (res.code === 200) {
|
||||
const data = res.data || [];
|
||||
const treeData = buildTreeFromFlat(data);
|
||||
@@ -44,10 +65,19 @@ export default function Roles() {
|
||||
});
|
||||
}
|
||||
|
||||
// 分页切换(正确触发)
|
||||
const handlePageChange = (pageNum, pageSize) => {
|
||||
setPagination({
|
||||
...pagination,
|
||||
pageNum: pageNum,
|
||||
pageSize: pageSize
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
getMenu();
|
||||
getRole();
|
||||
}, []);
|
||||
getMenu();
|
||||
}, [pagination.pageNum, pagination.pageSize]);
|
||||
|
||||
// 新增角色
|
||||
const handleAddRole = () => {
|
||||
@@ -148,7 +178,7 @@ export default function Roles() {
|
||||
</div>
|
||||
|
||||
{/* 角色卡片列表 */}
|
||||
<Row gutter={[16, 16]}>
|
||||
<Row gutter={[16, 16]} style={{ marginBottom: 16 }}>
|
||||
{roles && roles.length > 0 ? (
|
||||
roles.map(role => (
|
||||
<Col xs={24} sm={12} md={8} lg={6} key={role.roleId}>
|
||||
@@ -200,6 +230,17 @@ export default function Roles() {
|
||||
</Col>
|
||||
)}
|
||||
</Row>
|
||||
|
||||
{/* 分页组件(正确触发) */}
|
||||
<Pagination
|
||||
current={pagination.pageNum}
|
||||
pageSize={pagination.pageSize}
|
||||
total={pagination.total}
|
||||
showSizeChanger
|
||||
showTotal={(total) => `共 ${total} 条`}
|
||||
onChange={handlePageChange}
|
||||
style={{ textAlign: 'right' }}
|
||||
/>
|
||||
</AntdCard>
|
||||
|
||||
{/* 新增/编辑弹窗 */}
|
||||
|
||||
Reference in New Issue
Block a user