From e5360f49b654520b1ad57a2a9f49aec8bbf382a4 Mon Sep 17 00:00:00 2001 From: mmc <1556375442@qq.com> Date: Wed, 29 Apr 2026 10:00:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E4=B8=8A=E5=88=86=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/mune/index.ts | 3 +- src/api/organization/index.tsx | 3 +- src/api/role/index.ts | 3 +- src/api/stationManage/index.ts | 3 +- src/pages/MenuList.tsx | 50 +++++++++++++++++++++++-------- src/pages/Organization.tsx | 52 ++++++++++++++++++++++---------- src/pages/Roles.tsx | 55 +++++++++++++++++++++++++++++----- src/pages/StationManage.tsx | 40 ++++++++++++++++++++++--- 8 files changed, 166 insertions(+), 43 deletions(-) diff --git a/src/api/mune/index.ts b/src/api/mune/index.ts index b1ec8ea..78c4541 100644 --- a/src/api/mune/index.ts +++ b/src/api/mune/index.ts @@ -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 }); } diff --git a/src/api/organization/index.tsx b/src/api/organization/index.tsx index f782b92..c392c07 100644 --- a/src/api/organization/index.tsx +++ b/src/api/organization/index.tsx @@ -1,10 +1,11 @@ import request from '../request'; //获取组织列表 -export function getOrgList() { +export function getOrgList(params) { return request({ url: '/system/org/list', method: 'get', + params }); } diff --git a/src/api/role/index.ts b/src/api/role/index.ts index 4451ec3..986b8e4 100644 --- a/src/api/role/index.ts +++ b/src/api/role/index.ts @@ -18,10 +18,11 @@ export function editRoleApi(data) { }); } //获取角色列表 -export function getRoleList() { +export function getRoleList(params) { return request({ url: '/system/role/selectRoleAll', method: 'get', + params }); } diff --git a/src/api/stationManage/index.ts b/src/api/stationManage/index.ts index cfbf814..e7c1cea 100644 --- a/src/api/stationManage/index.ts +++ b/src/api/stationManage/index.ts @@ -1,10 +1,11 @@ import request from '../request'; //获取组织列表 -export function getStationList() { +export function getStationList(params) { return request({ url: '/system/site/list', method: 'get', + params }); } diff --git a/src/pages/MenuList.tsx b/src/pages/MenuList.tsx index 31e88d2..d91366d 100644 --- a/src/pages/MenuList.tsx +++ b/src/pages/MenuList.tsx @@ -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}
- {/* - - - */}
- {/* 表格 */} + {/* 表格 + 统一分页 */} `共 ${total} 条` + }} + onChange={handleTableChange} bordered size="middle" /> - {/* 新增/编辑弹窗 */} { - 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() { {/* 角色卡片列表 */} - + {roles && roles.length > 0 ? ( roles.map(role => ( @@ -200,6 +230,17 @@ export default function Roles() { )} + + {/* 分页组件(正确触发) */} + `共 ${total} 条`} + onChange={handlePageChange} + style={{ textAlign: 'right' }} + /> {/* 新增/编辑弹窗 */} diff --git a/src/pages/StationManage.tsx b/src/pages/StationManage.tsx index 38f9a5d..a290082 100644 --- a/src/pages/StationManage.tsx +++ b/src/pages/StationManage.tsx @@ -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" />