加上分页

This commit is contained in:
mmc
2026-04-29 10:00:24 +08:00
parent dcee7c601f
commit e5360f49b6
8 changed files with 166 additions and 43 deletions

View File

@@ -9,10 +9,11 @@ import request from '../request';
* @param {string} [params.status] - 菜单状态(0正常 1停用)
* @returns {Promise}
*/
export function getMenuList() {
export function getMenuList(params) {
return request({
url: '/system/menu/list',
method: 'get',
params
});
}

View File

@@ -1,10 +1,11 @@
import request from '../request';
//获取组织列表
export function getOrgList() {
export function getOrgList(params) {
return request({
url: '/system/org/list',
method: 'get',
params
});
}

View File

@@ -18,10 +18,11 @@ export function editRoleApi(data) {
});
}
//获取角色列表
export function getRoleList() {
export function getRoleList(params) {
return request({
url: '/system/role/selectRoleAll',
method: 'get',
params
});
}

View File

@@ -1,10 +1,11 @@
import request from '../request';
//获取组织列表
export function getStationList() {
export function getStationList(params) {
return request({
url: '/system/site/list',
method: 'get',
params
});
}

View File

@@ -26,9 +26,6 @@ const iconList = Object.keys(AllIcons).filter(item => {
return item.endsWith('Outlined')
});
// 扁平数组 → 树形结构
const rolePermissionMap = {};
export default function MenuList() {
@@ -46,24 +43,50 @@ export default function MenuList() {
const [checkedKeys, setCheckedKeys] = useState([]);
const [messageApi, contextHolder] = message.useMessage();
// 获取菜单
// 分页状态
const [pagination, setPagination] = useState({
pageNum: 1,
pageSize: 10,
total: 0
});
// 获取菜单(带分页)
const getMenuListApi = () => {
getMenuList().then(res => {
const params = {
pageNum: pagination.pageNum,
pageSize: pagination.pageSize
};
getMenuList(params).then(res => {
if (res.code === 200) {
const data = res.data || [];
setRawMenuList(data);
const tree = buildTreeFromFlat(data);
setMenuTreeData(tree);
setMenuTree(buildPermTree(tree));
// 如果后台返回 total,设置总数
setPagination({
...pagination,
total: res.total || data.length
});
}
}).catch(() => {
messageApi.error('菜单加载失败');
});
};
// 分页变化
const handleTableChange = (newPagination) => {
setPagination({
...pagination,
pageNum: newPagination.current,
pageSize: newPagination.pageSize
});
};
useEffect(() => {
getMenuListApi();
}, []);
}, [pagination.pageNum, pagination.pageSize]);
// 编辑
const handleEdit = (record) => {
@@ -191,12 +214,6 @@ export default function MenuList() {
{contextHolder}
<Card title="菜单管理" style={{ borderRadius: 8 }}>
<div style={{ marginBottom: 16, display: 'flex', justifyContent: 'space-between' }}>
{/*<Space>
<Select placeholder="选择角色" style={{ width: 180 }} value={selectedRole} onChange={setSelectedRole}>
{roleList.map(r => <Option key={r.key} value={r.key}>{r.name}</Option>)}
</Select>
<Button type="primary" icon={<SettingOutlined />} onClick={handlePermOpen}>配置权限</Button>
</Space>*/}
<Button type="primary" icon={<PlusOutlined />} onClick={() => {
setEditMenu(null);
menuForm.resetFields();
@@ -208,7 +225,14 @@ export default function MenuList() {
columns={columns}
dataSource={menuTreeData}
rowKey="menuId"
pagination={true}
pagination={{
current: pagination.pageNum,
pageSize: pagination.pageSize,
total: pagination.total,
showSizeChanger: true,
showTotal: (total) => `共 ${total} 条`
}}
onChange={handleTableChange}
bordered
size="middle"
indentSize={24}

View File

@@ -8,8 +8,6 @@ import {
} from '@ant-design/icons';
import { addOrg, deleteOrg, getOrgList } from '../api/organization';
const { Title } = Typography;
const { Option } = Select;
const AntdCard = Card as any;
@@ -21,18 +19,43 @@ export default function Organization() {
const [editRecord, setEditRecord] = useState(null);
const [messageApi, contextHolder] = message.useMessage();
// 获取组织列表
// 统一分页
const [pagination, setPagination] = useState({
pageNum: 1,
pageSize: 10,
total: 0
});
// 获取组织列表(带分页)
const getOrgData = () => {
getOrgList().then(res => {
const params = {
pageNum: pagination.pageNum,
pageSize: pagination.pageSize
};
getOrgList(params).then(res => {
if (res.code === 200) {
setOrgList(res.rows || []);
setPagination({
...pagination,
total: res.total || res.rows?.length || 0
});
}
});
};
// 分页切换
const handleTableChange = (newPagination) => {
setPagination({
...pagination,
pageNum: newPagination.current,
pageSize: newPagination.pageSize
});
};
useEffect(() => {
getOrgData();
}, []);
}, [pagination.pageNum, pagination.pageSize]);
// 打开新增
const handleAdd = () => {
@@ -53,10 +76,7 @@ export default function Organization() {
// 删除
const handleDelete = (id) => {
deleteOrg({ id }).then(res => {
console.log(id, "删除")
if (res.code == 200) {
messageApi.success('删除成功');
getOrgData();
@@ -72,7 +92,6 @@ export default function Organization() {
const handleSave = () => {
form.validateFields().then(values => {
if (editRecord) {
// 编辑
const params = {
...values,
id: editRecord.id
@@ -87,7 +106,6 @@ export default function Organization() {
}
});
} else {
// 新增
addOrg(values).then(res => {
if (res.code === 200) {
messageApi.success('新增成功');
@@ -133,27 +151,31 @@ export default function Organization() {
<div style={{ padding: '20px' }}>
{contextHolder}
{/* 统一卡片容器 */}
<AntdCard title="组织管理" style={{ borderRadius: 8 }}>
{/* 顶部按钮 */}
<div style={{ marginBottom: 16, display: 'flex', justifyContent: 'space-between' }}>
<Button type="primary" icon={<PlusOutlined />} onClick={handleAdd}>
新增组织
</Button>
</div>
{/* 表格 */}
{/* 表格 + 统一分页 */}
<Table
rowKey="id"
columns={columns}
dataSource={orgList}
pagination={false}
pagination={{
current: pagination.pageNum,
pageSize: pagination.pageSize,
total: pagination.total,
showSizeChanger: true,
showTotal: (total) => `共 ${total} 条`
}}
onChange={handleTableChange}
bordered
size="middle"
/>
</AntdCard>
{/* 新增/编辑弹窗 */}
<Modal
title={editRecord ? '编辑组织' : '新增组织'}
open={modalVisible}

View File

@@ -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>
{/* 新增/编辑弹窗 */}

View File

@@ -32,18 +32,43 @@ export default function StationManage() {
const [mapVisible, setMapVisible] = useState(false);
const [messageApi, contextHolder] = message.useMessage();
// ====================== 获取场站列表 ======================
// 分页状态
const [pagination, setPagination] = useState({
pageNum: 1,
pageSize: 10,
total: 0
});
// ====================== 获取场站列表(分页) ======================
const getStationData = () => {
getStationList().then(res => {
const params = {
pageNum: pagination.pageNum,
pageSize: pagination.pageSize
};
getStationList(params).then(res => {
if (res.code === 200) {
setStationList(res.rows || []);
setPagination({
...pagination,
total: res.total || res.rows?.length || 0
});
}
});
};
// 切换分页
const handleTableChange = (newPagination) => {
setPagination({
...pagination,
pageNum: newPagination.current,
pageSize: newPagination.pageSize
});
};
useEffect(() => {
getStationData();
}, []);
}, [pagination.pageNum, pagination.pageSize]);
// ====================== 新增 / 编辑 场站 ======================
const handleAdd = () => {
@@ -183,7 +208,14 @@ export default function StationManage() {
rowKey="id"
columns={columns}
dataSource={stationList}
pagination={true}
pagination={{
current: pagination.pageNum,
pageSize: pagination.pageSize,
total: pagination.total,
showSizeChanger: true,
showTotal: (total) => `共 ${total} 条`
}}
onChange={handleTableChange}
bordered
size="middle"
/>