二级菜单配置

This commit is contained in:
mmc
2026-08-03 14:22:17 +08:00
parent a1e5cd1c6a
commit 575229947d
5 changed files with 82 additions and 225 deletions

View File

@@ -19,51 +19,16 @@ const { Text } = Typography;
export default function AlarmCenterPage() {
const [activeTab, setActiveTab] = useState('overview');
const [rawMenuList, setRawMenuList] = useState([]);
const [showTabs, setShowTabs] = useState([]);
// 获取菜单(和系统设置一模一样)
const getMenuListApi = () => {
const params = { pageNum: 1, pageSize: 99999 };
return getMenuList(params);
};
// 动态生成 tab
useEffect(() => {
getMenuListApi().then(res => {
if (res.code === 200) {
const data = res.rows || [];
// 告警中心 parentId 你自己改成你数据库里的 ID
const alarmChild = data.filter(m => m.parentId == 3388);
alarmChild.sort((a, b) => (a.orderNum || 0) - (b.orderNum || 0));
const tabs = alarmChild.map(item => {
if (item.path === '/alerts/all') return { key: 'overview', label: '告警总览', icon: <AlertOutlined /> };
if (item.path === '/alerts/time') return { key: 'realtime', label: '实时告警', icon: <ClockCircleOutlined /> };
if (item.path === '/alerts/history') return { key: 'history', label: '告警历史', icon: <FileTextOutlined /> };
if (item.path === '/alerts/counts') return { key: 'statistics', label: '告警统计', icon: <BarChartOutlined /> };
if (item.path === '/alerts/rules') return { key: 'rules', label: '告警规则', icon: <SettingOutlined /> };
if (item.path === '/alerts/subscribe') return { key: 'subscription', label: '告警订阅', icon: <BellOutlined /> };
return null;
}).filter(Boolean);
setShowTabs(tabs);
if (tabs.length > 0) setActiveTab(tabs[0].key);
}
});
}, []);
// 渲染对应组件
const renderTabContent = () => {
switch (activeTab) {
case 'overview': return <AlarmOverview />;
case 'realtime': return <AlarmRealtime />;
case 'history': return <AlarmHistory />;
case 'statistics': return <AlarmStatistics />;
case 'rules': return <AlarmRules />;
case 'subscription': return <AlarmSubscription />;
default: return <div style={{ padding: 20 }}><Text>请选择菜单</Text></div>;
}
};

View File

@@ -23,12 +23,6 @@ export default function DeviceIndexPage() {
const { userInfo } = useSelector((state: RootState) => state.user);
const tabs = [
{ key: 'overview', label: '装备总览', icon: <AppstoreOutlined /> },
{ key: 'status', label: '设备状态', icon: <SettingOutlined /> },
{ key: 'wayLineTask', label: '航线任务', icon: <AimOutlined /> },
{ key: 'robotTask', label: '机器人任务', icon: <BranchesOutlined /> },
];
// 获取设备列表(用于默认选择第一个)
const fetchAllData = async () => {
@@ -76,15 +70,6 @@ export default function DeviceIndexPage() {
setActiveTab('status');
};
// 切换tab时,如果是overview或status,确保选择的是第一个设备
const handleTabChange = (key) => {
setActiveTab(key);
console.log('切换到tab', key, '当前选中设备SN', selectedSn);
// 如果没有选择设备,自动选择第一个
if ((key === 'wayLineTask' || key === 'robotTask') && devicesAll.length > 0) {
setSelectedSn(devicesAll[0].device_sn || devicesAll[0].serialNumber);
}
};
const renderContent = () => {
if (activeTab === 'overview') {
@@ -94,43 +79,14 @@ export default function DeviceIndexPage() {
onDeviceSelect={(sn) => setSelectedSn(sn)}
/>;
}
if (activeTab === 'status') {
return <DeviceStatusPage
serialNumber={selectedSn}
onDeviceChange={(sn) => setSelectedSn(sn)}
/>;
}
if (activeTab === 'wayLineTask') return <WayLinePage />;
if (activeTab === 'robotTask') return <RobotTaskPage />;
return null;
};
return (
<Layout style={{ minHeight: '100vh', overflow: 'hidden', scrollbarWidth: "thin", scrollbarColor: '#ccc transparent' }}>
<div style={{ display: 'flex', paddingBottom: "4px" }}>
<div style={{ padding: '8px 0px 0', flexShrink: 0 }}>
<Typography.Title level={4} style={{ margin: 0, fontSize: 'clamp(14px, 1.2vw, 18px)' }}>装备控制</Typography.Title>
</div>
<Header style={{
flex: 1, padding: 0, background: 'transparent',
backgroundColor: 'transparent', borderBottom: '1px solid #f0f0f0', height: 40, lineHeight: '40px'
}}>
<Menu
mode="horizontal"
selectedKeys={[activeTab]}
onClick={({ key }) => handleTabChange(key)}
items={tabs}
style={{
border: '0',
height: 40,
lineHeight: '40px',
background: 'transparent',
backgroundColor: 'transparent'
}} />
</Header>
</div>
<Content style={{
maxHeight: 'calc(100vh - 40px)',

View File

@@ -27,56 +27,15 @@ import BasicSettings from '../components/SystemSetting/BasicSettings';
import ErrorManagement from '../components/SystemSetting/ErrorManagement';
import AlarmSettingsManagement from '../components/SystemSetting/AlarmSettingsManagement';
import WorkOrderSettingsManagement from '../components/SystemSetting/WorkOrderSettingsManagement';
import { Outlet } from 'react-router-dom';
const { Header, Content } = Layout;
const { Text } = Typography;
const { Option } = Select;
const AntdCard = Card as any;
// 重构后的系统维护页面 - 使用Tabs样式
const SystemMaintenancePage = () => {
const [activeSubTab, setActiveSubTab] = useState('error');
return (
<div className="p-0 pt-[8px] bg-[#f5f7fa] min-h-screen">
<Card className="mb-4">
<Tabs activeKey={activeSubTab} onChange={setActiveSubTab}>
<TabPane tab={<span><ExclamationCircleOutlined />错误管理</span>} key="error" />
<TabPane tab={<span><AlertOutlined />告警模型管理</span>} key="alarm" />
<TabPane tab={<span><FormOutlined />工单模型管理</span>} key="workOrder" />
</Tabs>
</Card>
{activeSubTab === 'error' && <ErrorManagement />}
{activeSubTab === 'alarm' && <AlarmSettingsManagement />}
{activeSubTab === 'workOrder' && <WorkOrderSettingsManagement />}
</div>
);
};
// 右侧面板
const RightPanel = () => (
<div style={{ padding: 24 }}>
<AntdCard title="角色权限概览" style={{ marginBottom: 24 }}>
<Row gutter={16}>
<Col span={12}><AntdCard size="small" hoverable style={{ background: '#f0f5ff' }}><Space direction="vertical"><div style={{ display: 'flex', alignItems: 'center', gap: 8 }}><div style={{ background: '#1677ff', borderRadius: '50%', padding: 4 }}><SafetyOutlined style={{ color: '#fff', fontSize: 16 }} /></div><Text strong>超级管理员</Text></div><Text type="secondary">全部权限</Text></Space></AntdCard></Col>
<Col span={12}><AntdCard size="small" hoverable style={{ background: '#f6ffed' }}><Space direction="vertical"><div style={{ display: 'flex', alignItems: 'center', gap: 8 }}><div style={{ background: '#52c41a', borderRadius: '50%', padding: 4 }}><UserOutlined style={{ color: '#fff', fontSize: 16 }} /></div><Text strong>运维工程师</Text></div><Text type="secondary">设备管理</Text></Space></AntdCard></Col>
</Row>
</AntdCard>
<AntdCard title="设备接入状态" style={{ marginBottom: 24 }}>
<Space direction="vertical"><div style={{ display: 'flex', justifyContent: 'space-between' }}><span>逆变器</span><span>正常</span></div></Space>
</AntdCard>
<AntdCard title="数据与安全" style={{ marginBottom: 24 }}>
<Space direction="vertical"><div style={{ display: 'flex', justifyContent: 'space-between' }}><span>数据保留</span><span>3年</span></div></Space>
</AntdCard>
<AntdCard title="系统维护">
<Row gutter={16}><Col span={6}><Button block icon={<DeleteOutlined />}>清理缓存</Button></Col><Col span={6}><Button block icon={<SyncOutlined />}>重启服务</Button></Col></Row>
</AntdCard>
</div>
);
// ======================
// 主页面
@@ -92,100 +51,12 @@ export default function SystemSettings() {
return getMenuList(params);
};
// 动态生成 tab
useEffect(() => {
getMenuListApi().then(res => {
if (res.code === 200) {
const data = res.rows || [];
// 系统设置 parentId = 3394
const systemChild = data.filter(m => m.parentId == 3394);
// ======================
// 👇 按 orderNum 正序排序(数字越小越靠前)
// ======================
systemChild.sort((a, b) => {
return (a.orderNum || 0) - (b.orderNum || 0);
});
const tabs = systemChild.map(item => {
if (item.path == '/systemSetting/basic') {
return { key: 'basic', label: '基础设置', icon: <SettingOutlined /> };
}
if (item.path === '/systemSetting/User') {
return { key: 'user-role', label: '用户与角色', icon: <UserOutlined /> };
}
if (item.path === '/systemSetting/menu') {
return { key: 'menu', label: '菜单管理', icon: <AppstoreOutlined /> };
}
if (item.path === '/systemSetting/org') {
return { key: 'org', label: '组织管理', icon: <TeamOutlined /> };
}
if (item.path === '/systemSetting/site') {
return { key: 'site', label: '场站管理', icon: <EnvironmentOutlined /> };
}
if (item.path === '/systemSetting/notice') {
return { key: 'notice', label: '通知策略', icon: <NotificationOutlined /> };
}
if (item.path === '/systemSetting/deviceAccess') {
return { key: 'deviceAccess', label: '设备接入', icon: <ExperimentOutlined /> };
}
if (item.path === '/systemSetting/dataSafety') {
return { key: 'dataSafety', label: '数据与安全', icon: <SafetyOutlined /> };
}
if (item.path === '/systemSetting/systemMaintenance') {
return { key: 'systemMaintenance', label: '系统维护', icon: <SyncOutlined /> };
}
if (item.path === '/systemSetting/monitor') {
return { key: 'monitor', label: '系统监控', icon: <SyncOutlined /> };
}
if (item.path === '/systemSetting/devices') {
return { key: 'devices', label: '设备管理', icon: <AppstoreOutlined /> };
}
// 移除错误管理的单独菜单,已经放在系统维护里面了
return null;
}).filter(Boolean);
setShowTabs(tabs);
// 默认选中第一个
if (tabs.length > 0) {
setActiveTab(tabs[0].key);
}
}
});
}, []);
const NoticePage = () => <div style={{ padding: 20 }}><h2>通知策略页面</h2></div>;
const DataSafetyPage = () => <div style={{ padding: 20 }}><h2>数据与安全页面</h2></div>;
const DefaultPage = () => <div style={{ padding: 20 }}><h2>请选择菜单</h2></div>;
const renderTabContent = () => {
switch (activeTab) {
case 'basic':
return <BasicSettings />;
case 'user-role':
return <UserRolePage />;
case 'menu':
return <MenuList />;
case 'org':
return <Organization />;
case 'site':
return <StationManage />;
case 'notice':
return <NoticePage />;
case 'deviceAccess':
return <DeviceAccessPage />;
case 'dataSafety':
return <DataSafetyPage />;
case 'systemMaintenance':
return <SystemMaintenancePage />;
case 'monitor':
return <OnlineUserPage />;
case 'devices':
return <DeviceManagementPage />;
default:
return <DefaultPage />;
}
};
return (
<Layout style={{ minHeight: '100vh', overflow: 'hidden' }}>
@@ -193,22 +64,14 @@ export default function SystemSettings() {
<Typography.Title level={4} style={{ margin: 0, fontSize: 'clamp(14px, 1.2vw, 18px)' }}>系统设置</Typography.Title>
<Text type="secondary" style={{ fontSize: '12px' }}>告警规则配置、用户角色、通知管理与系统参数设置</Text>
</div>
<Header style={{ padding: 0, borderBottom: '1px solid #f0f0f0', position: 'sticky', top: 0, zIndex: 10, height: 40, lineHeight: '40px' }}>
<Menu
mode="horizontal"
selectedKeys={[activeTab]}
onClick={({ key }) => setActiveTab(key)}
items={showTabs}
style={{ border: 0, height: 40, lineHeight: '40px' }}
/>
</Header>
<Content style={{
maxHeight: 'calc(100vh - 40px)', overflowY: 'auto', background: '#f5f7fa',
scrollbarWidth: 'none',
msOverflowStyle: 'none',
}}>
{renderTabContent()}
<Outlet />
</Content>
</Layout>
);