加上分页
This commit is contained in:
@@ -9,10 +9,11 @@ import request from '../request';
|
|||||||
* @param {string} [params.status] - 菜单状态(0正常 1停用)
|
* @param {string} [params.status] - 菜单状态(0正常 1停用)
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
export function getMenuList() {
|
export function getMenuList(params) {
|
||||||
return request({
|
return request({
|
||||||
url: '/system/menu/list',
|
url: '/system/menu/list',
|
||||||
method: 'get',
|
method: 'get',
|
||||||
|
params
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import request from '../request';
|
import request from '../request';
|
||||||
|
|
||||||
//获取组织列表
|
//获取组织列表
|
||||||
export function getOrgList() {
|
export function getOrgList(params) {
|
||||||
return request({
|
return request({
|
||||||
url: '/system/org/list',
|
url: '/system/org/list',
|
||||||
method: 'get',
|
method: 'get',
|
||||||
|
params
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,10 +18,11 @@ export function editRoleApi(data) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
//获取角色列表
|
//获取角色列表
|
||||||
export function getRoleList() {
|
export function getRoleList(params) {
|
||||||
return request({
|
return request({
|
||||||
url: '/system/role/selectRoleAll',
|
url: '/system/role/selectRoleAll',
|
||||||
method: 'get',
|
method: 'get',
|
||||||
|
params
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import request from '../request';
|
import request from '../request';
|
||||||
|
|
||||||
//获取组织列表
|
//获取组织列表
|
||||||
export function getStationList() {
|
export function getStationList(params) {
|
||||||
return request({
|
return request({
|
||||||
url: '/system/site/list',
|
url: '/system/site/list',
|
||||||
method: 'get',
|
method: 'get',
|
||||||
|
params
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,9 +26,6 @@ const iconList = Object.keys(AllIcons).filter(item => {
|
|||||||
return item.endsWith('Outlined')
|
return item.endsWith('Outlined')
|
||||||
});
|
});
|
||||||
|
|
||||||
// 扁平数组 → 树形结构
|
|
||||||
|
|
||||||
|
|
||||||
const rolePermissionMap = {};
|
const rolePermissionMap = {};
|
||||||
|
|
||||||
export default function MenuList() {
|
export default function MenuList() {
|
||||||
@@ -46,24 +43,50 @@ export default function MenuList() {
|
|||||||
const [checkedKeys, setCheckedKeys] = useState([]);
|
const [checkedKeys, setCheckedKeys] = useState([]);
|
||||||
const [messageApi, contextHolder] = message.useMessage();
|
const [messageApi, contextHolder] = message.useMessage();
|
||||||
|
|
||||||
// 获取菜单
|
// 分页状态
|
||||||
|
const [pagination, setPagination] = useState({
|
||||||
|
pageNum: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
total: 0
|
||||||
|
});
|
||||||
|
|
||||||
|
// 获取菜单(带分页)
|
||||||
const getMenuListApi = () => {
|
const getMenuListApi = () => {
|
||||||
getMenuList().then(res => {
|
const params = {
|
||||||
|
pageNum: pagination.pageNum,
|
||||||
|
pageSize: pagination.pageSize
|
||||||
|
};
|
||||||
|
|
||||||
|
getMenuList(params).then(res => {
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
const data = res.data || [];
|
const data = res.data || [];
|
||||||
setRawMenuList(data);
|
setRawMenuList(data);
|
||||||
const tree = buildTreeFromFlat(data);
|
const tree = buildTreeFromFlat(data);
|
||||||
setMenuTreeData(tree);
|
setMenuTreeData(tree);
|
||||||
setMenuTree(buildPermTree(tree));
|
setMenuTree(buildPermTree(tree));
|
||||||
|
// 如果后台返回 total,设置总数
|
||||||
|
setPagination({
|
||||||
|
...pagination,
|
||||||
|
total: res.total || data.length
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
messageApi.error('菜单加载失败');
|
messageApi.error('菜单加载失败');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 分页变化
|
||||||
|
const handleTableChange = (newPagination) => {
|
||||||
|
setPagination({
|
||||||
|
...pagination,
|
||||||
|
pageNum: newPagination.current,
|
||||||
|
pageSize: newPagination.pageSize
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getMenuListApi();
|
getMenuListApi();
|
||||||
}, []);
|
}, [pagination.pageNum, pagination.pageSize]);
|
||||||
|
|
||||||
// 编辑
|
// 编辑
|
||||||
const handleEdit = (record) => {
|
const handleEdit = (record) => {
|
||||||
@@ -191,12 +214,6 @@ export default function MenuList() {
|
|||||||
{contextHolder}
|
{contextHolder}
|
||||||
<Card title="菜单管理" style={{ borderRadius: 8 }}>
|
<Card title="菜单管理" style={{ borderRadius: 8 }}>
|
||||||
<div style={{ marginBottom: 16, display: 'flex', justifyContent: 'space-between' }}>
|
<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={() => {
|
<Button type="primary" icon={<PlusOutlined />} onClick={() => {
|
||||||
setEditMenu(null);
|
setEditMenu(null);
|
||||||
menuForm.resetFields();
|
menuForm.resetFields();
|
||||||
@@ -208,7 +225,14 @@ export default function MenuList() {
|
|||||||
columns={columns}
|
columns={columns}
|
||||||
dataSource={menuTreeData}
|
dataSource={menuTreeData}
|
||||||
rowKey="menuId"
|
rowKey="menuId"
|
||||||
pagination={true}
|
pagination={{
|
||||||
|
current: pagination.pageNum,
|
||||||
|
pageSize: pagination.pageSize,
|
||||||
|
total: pagination.total,
|
||||||
|
showSizeChanger: true,
|
||||||
|
showTotal: (total) => `共 ${total} 条`
|
||||||
|
}}
|
||||||
|
onChange={handleTableChange}
|
||||||
bordered
|
bordered
|
||||||
size="middle"
|
size="middle"
|
||||||
indentSize={24}
|
indentSize={24}
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ import {
|
|||||||
} from '@ant-design/icons';
|
} from '@ant-design/icons';
|
||||||
import { addOrg, deleteOrg, getOrgList } from '../api/organization';
|
import { addOrg, deleteOrg, getOrgList } from '../api/organization';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const { Title } = Typography;
|
const { Title } = Typography;
|
||||||
const { Option } = Select;
|
const { Option } = Select;
|
||||||
const AntdCard = Card as any;
|
const AntdCard = Card as any;
|
||||||
@@ -21,18 +19,43 @@ export default function Organization() {
|
|||||||
const [editRecord, setEditRecord] = useState(null);
|
const [editRecord, setEditRecord] = useState(null);
|
||||||
const [messageApi, contextHolder] = message.useMessage();
|
const [messageApi, contextHolder] = message.useMessage();
|
||||||
|
|
||||||
// 获取组织列表
|
// 统一分页
|
||||||
|
const [pagination, setPagination] = useState({
|
||||||
|
pageNum: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
total: 0
|
||||||
|
});
|
||||||
|
|
||||||
|
// 获取组织列表(带分页)
|
||||||
const getOrgData = () => {
|
const getOrgData = () => {
|
||||||
getOrgList().then(res => {
|
const params = {
|
||||||
|
pageNum: pagination.pageNum,
|
||||||
|
pageSize: pagination.pageSize
|
||||||
|
};
|
||||||
|
|
||||||
|
getOrgList(params).then(res => {
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
setOrgList(res.rows || []);
|
setOrgList(res.rows || []);
|
||||||
|
setPagination({
|
||||||
|
...pagination,
|
||||||
|
total: res.total || res.rows?.length || 0
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 分页切换
|
||||||
|
const handleTableChange = (newPagination) => {
|
||||||
|
setPagination({
|
||||||
|
...pagination,
|
||||||
|
pageNum: newPagination.current,
|
||||||
|
pageSize: newPagination.pageSize
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getOrgData();
|
getOrgData();
|
||||||
}, []);
|
}, [pagination.pageNum, pagination.pageSize]);
|
||||||
|
|
||||||
// 打开新增
|
// 打开新增
|
||||||
const handleAdd = () => {
|
const handleAdd = () => {
|
||||||
@@ -53,10 +76,7 @@ export default function Organization() {
|
|||||||
|
|
||||||
// 删除
|
// 删除
|
||||||
const handleDelete = (id) => {
|
const handleDelete = (id) => {
|
||||||
|
|
||||||
|
|
||||||
deleteOrg({ id }).then(res => {
|
deleteOrg({ id }).then(res => {
|
||||||
console.log(id, "删除")
|
|
||||||
if (res.code == 200) {
|
if (res.code == 200) {
|
||||||
messageApi.success('删除成功');
|
messageApi.success('删除成功');
|
||||||
getOrgData();
|
getOrgData();
|
||||||
@@ -72,7 +92,6 @@ export default function Organization() {
|
|||||||
const handleSave = () => {
|
const handleSave = () => {
|
||||||
form.validateFields().then(values => {
|
form.validateFields().then(values => {
|
||||||
if (editRecord) {
|
if (editRecord) {
|
||||||
// 编辑
|
|
||||||
const params = {
|
const params = {
|
||||||
...values,
|
...values,
|
||||||
id: editRecord.id
|
id: editRecord.id
|
||||||
@@ -87,7 +106,6 @@ export default function Organization() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// 新增
|
|
||||||
addOrg(values).then(res => {
|
addOrg(values).then(res => {
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
messageApi.success('新增成功');
|
messageApi.success('新增成功');
|
||||||
@@ -133,27 +151,31 @@ export default function Organization() {
|
|||||||
<div style={{ padding: '20px' }}>
|
<div style={{ padding: '20px' }}>
|
||||||
{contextHolder}
|
{contextHolder}
|
||||||
|
|
||||||
{/* 统一卡片容器 */}
|
|
||||||
<AntdCard title="组织管理" style={{ borderRadius: 8 }}>
|
<AntdCard title="组织管理" style={{ borderRadius: 8 }}>
|
||||||
{/* 顶部按钮 */}
|
|
||||||
<div style={{ marginBottom: 16, display: 'flex', justifyContent: 'space-between' }}>
|
<div style={{ marginBottom: 16, display: 'flex', justifyContent: 'space-between' }}>
|
||||||
<Button type="primary" icon={<PlusOutlined />} onClick={handleAdd}>
|
<Button type="primary" icon={<PlusOutlined />} onClick={handleAdd}>
|
||||||
新增组织
|
新增组织
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* 表格 */}
|
{/* 表格 + 统一分页 */}
|
||||||
<Table
|
<Table
|
||||||
rowKey="id"
|
rowKey="id"
|
||||||
columns={columns}
|
columns={columns}
|
||||||
dataSource={orgList}
|
dataSource={orgList}
|
||||||
pagination={false}
|
pagination={{
|
||||||
|
current: pagination.pageNum,
|
||||||
|
pageSize: pagination.pageSize,
|
||||||
|
total: pagination.total,
|
||||||
|
showSizeChanger: true,
|
||||||
|
showTotal: (total) => `共 ${total} 条`
|
||||||
|
}}
|
||||||
|
onChange={handleTableChange}
|
||||||
bordered
|
bordered
|
||||||
size="middle"
|
size="middle"
|
||||||
/>
|
/>
|
||||||
</AntdCard>
|
</AntdCard>
|
||||||
|
|
||||||
{/* 新增/编辑弹窗 */}
|
|
||||||
<Modal
|
<Modal
|
||||||
title={editRecord ? '编辑组织' : '新增组织'}
|
title={editRecord ? '编辑组织' : '新增组织'}
|
||||||
open={modalVisible}
|
open={modalVisible}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import {
|
import {
|
||||||
Card, Row, Col, Button, Typography, Space, Modal, Form, Tree, message,
|
Card, Row, Col, Button, Typography, Space, Modal, Form, Tree, message,
|
||||||
Input, Popconfirm, Divider, InputNumber, Switch
|
Input, Popconfirm, Divider, InputNumber, Switch, Pagination
|
||||||
} from 'antd';
|
} from 'antd';
|
||||||
import {
|
import {
|
||||||
PlusOutlined, EditOutlined, DeleteOutlined, CloseOutlined
|
PlusOutlined, EditOutlined, DeleteOutlined, CloseOutlined
|
||||||
@@ -23,18 +23,39 @@ export default function Roles() {
|
|||||||
const [editRole, setEditRole] = useState(null);
|
const [editRole, setEditRole] = useState(null);
|
||||||
const [messageApi, contextHolder] = message.useMessage();
|
const [messageApi, contextHolder] = message.useMessage();
|
||||||
|
|
||||||
// 获取角色列表
|
// 统一分页
|
||||||
|
const [pagination, setPagination] = useState({
|
||||||
|
pageNum: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
total: 0
|
||||||
|
});
|
||||||
|
|
||||||
|
// 获取角色列表(带分页)
|
||||||
const getRole = () => {
|
const getRole = () => {
|
||||||
getRoleList().then(res => {
|
const params = {
|
||||||
|
pageNum: pagination.pageNum,
|
||||||
|
pageSize: pagination.pageSize
|
||||||
|
};
|
||||||
|
|
||||||
|
getRoleList(params).then(res => {
|
||||||
if (res.code == 200) {
|
if (res.code == 200) {
|
||||||
setRoles(res.data || []);
|
setRoles(res.data || []);
|
||||||
|
setPagination({
|
||||||
|
...pagination,
|
||||||
|
total: res.total || res.data?.length || 0
|
||||||
|
});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取菜单树
|
// 获取菜单树
|
||||||
const getMenu = () => {
|
const getMenu = () => {
|
||||||
getMenuList().then(res => {
|
const params = {
|
||||||
|
pageNum: 1,
|
||||||
|
pageSize: 1000
|
||||||
|
};
|
||||||
|
|
||||||
|
getMenuList(params).then(res => {
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
const data = res.data || [];
|
const data = res.data || [];
|
||||||
const treeData = buildTreeFromFlat(data);
|
const treeData = buildTreeFromFlat(data);
|
||||||
@@ -44,10 +65,19 @@ export default function Roles() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 分页切换(正确触发)
|
||||||
|
const handlePageChange = (pageNum, pageSize) => {
|
||||||
|
setPagination({
|
||||||
|
...pagination,
|
||||||
|
pageNum: pageNum,
|
||||||
|
pageSize: pageSize
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getMenu();
|
|
||||||
getRole();
|
getRole();
|
||||||
}, []);
|
getMenu();
|
||||||
|
}, [pagination.pageNum, pagination.pageSize]);
|
||||||
|
|
||||||
// 新增角色
|
// 新增角色
|
||||||
const handleAddRole = () => {
|
const handleAddRole = () => {
|
||||||
@@ -148,7 +178,7 @@ export default function Roles() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* 角色卡片列表 */}
|
{/* 角色卡片列表 */}
|
||||||
<Row gutter={[16, 16]}>
|
<Row gutter={[16, 16]} style={{ marginBottom: 16 }}>
|
||||||
{roles && roles.length > 0 ? (
|
{roles && roles.length > 0 ? (
|
||||||
roles.map(role => (
|
roles.map(role => (
|
||||||
<Col xs={24} sm={12} md={8} lg={6} key={role.roleId}>
|
<Col xs={24} sm={12} md={8} lg={6} key={role.roleId}>
|
||||||
@@ -200,6 +230,17 @@ export default function Roles() {
|
|||||||
</Col>
|
</Col>
|
||||||
)}
|
)}
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
|
{/* 分页组件(正确触发) */}
|
||||||
|
<Pagination
|
||||||
|
current={pagination.pageNum}
|
||||||
|
pageSize={pagination.pageSize}
|
||||||
|
total={pagination.total}
|
||||||
|
showSizeChanger
|
||||||
|
showTotal={(total) => `共 ${total} 条`}
|
||||||
|
onChange={handlePageChange}
|
||||||
|
style={{ textAlign: 'right' }}
|
||||||
|
/>
|
||||||
</AntdCard>
|
</AntdCard>
|
||||||
|
|
||||||
{/* 新增/编辑弹窗 */}
|
{/* 新增/编辑弹窗 */}
|
||||||
|
|||||||
@@ -32,18 +32,43 @@ export default function StationManage() {
|
|||||||
const [mapVisible, setMapVisible] = useState(false);
|
const [mapVisible, setMapVisible] = useState(false);
|
||||||
const [messageApi, contextHolder] = message.useMessage();
|
const [messageApi, contextHolder] = message.useMessage();
|
||||||
|
|
||||||
// ====================== 获取场站列表 ======================
|
// 分页状态
|
||||||
|
const [pagination, setPagination] = useState({
|
||||||
|
pageNum: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
total: 0
|
||||||
|
});
|
||||||
|
|
||||||
|
// ====================== 获取场站列表(分页) ======================
|
||||||
const getStationData = () => {
|
const getStationData = () => {
|
||||||
getStationList().then(res => {
|
const params = {
|
||||||
|
pageNum: pagination.pageNum,
|
||||||
|
pageSize: pagination.pageSize
|
||||||
|
};
|
||||||
|
|
||||||
|
getStationList(params).then(res => {
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
setStationList(res.rows || []);
|
setStationList(res.rows || []);
|
||||||
|
setPagination({
|
||||||
|
...pagination,
|
||||||
|
total: res.total || res.rows?.length || 0
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 切换分页
|
||||||
|
const handleTableChange = (newPagination) => {
|
||||||
|
setPagination({
|
||||||
|
...pagination,
|
||||||
|
pageNum: newPagination.current,
|
||||||
|
pageSize: newPagination.pageSize
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getStationData();
|
getStationData();
|
||||||
}, []);
|
}, [pagination.pageNum, pagination.pageSize]);
|
||||||
|
|
||||||
// ====================== 新增 / 编辑 场站 ======================
|
// ====================== 新增 / 编辑 场站 ======================
|
||||||
const handleAdd = () => {
|
const handleAdd = () => {
|
||||||
@@ -183,7 +208,14 @@ export default function StationManage() {
|
|||||||
rowKey="id"
|
rowKey="id"
|
||||||
columns={columns}
|
columns={columns}
|
||||||
dataSource={stationList}
|
dataSource={stationList}
|
||||||
pagination={true}
|
pagination={{
|
||||||
|
current: pagination.pageNum,
|
||||||
|
pageSize: pagination.pageSize,
|
||||||
|
total: pagination.total,
|
||||||
|
showSizeChanger: true,
|
||||||
|
showTotal: (total) => `共 ${total} 条`
|
||||||
|
}}
|
||||||
|
onChange={handleTableChange}
|
||||||
bordered
|
bordered
|
||||||
size="middle"
|
size="middle"
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user