Files
web-Iot/src/pages/SystemSetting.tsx

222 lines
13 KiB
TypeScript
Raw Normal View History

2026-04-30 10:49:44 +08:00
import React, { useState, useEffect } from 'react';
2026-04-29 14:26:01 +08:00
import {
2026-04-30 10:49:44 +08:00
Layout, Menu, Card, Row, Col, Button, Form, Input, Select, Switch, Tag, Space, Typography, message, Table
2026-04-29 14:26:01 +08:00
} from 'antd';
import {
SettingOutlined, UserOutlined, BellOutlined, LinkOutlined, SafetyOutlined, SyncOutlined,
CloudOutlined, TeamOutlined, FileTextOutlined, DatabaseOutlined, CalendarOutlined,
2026-04-30 10:49:44 +08:00
CheckCircleOutlined, ReloadOutlined, DownloadOutlined, DeleteOutlined,
KeyOutlined, AppstoreOutlined, BankOutlined,
NotificationOutlined,
2026-04-30 13:04:17 +08:00
ExperimentOutlined,
EnvironmentOutlined
2026-04-29 14:26:01 +08:00
} from '@ant-design/icons';
import UserRolePage from './UserPage';
import MenuList from './MenuList';
import Organization from './Organization';
import StationManage from './StationManage';
2026-04-30 10:49:44 +08:00
import { getMenuList } from '../api/mune';
2026-04-29 14:26:01 +08:00
const { Header, Content } = Layout;
2026-04-30 10:49:44 +08:00
const { Text } = Typography;
2026-04-29 14:26:01 +08:00
const { Option } = Select;
const AntdCard = Card as any;
2026-04-30 10:49:44 +08:00
// 基础设置
2026-04-29 14:26:01 +08:00
const BasicSettings = () => {
const [form] = Form.useForm();
2026-04-30 10:49:44 +08:00
const handleSave = () => { message.success('设置已保存'); };
2026-04-29 14:26:01 +08:00
return (
<div style={{ padding: 24 }}>
<Row gutter={16} style={{ marginBottom: 24 }}>
2026-04-30 10:49:44 +08:00
<Col span={5}><AntdCard size="small"><Space><div style={{ background: '#e6f4ff', borderRadius: 8, padding: 8 }}><CloudOutlined style={{ color: '#1677ff', fontSize: 20 }} /></div><div><div style={{ fontSize: 13, color: '#666' }}>当前版本</div><div style={{ fontWeight: 600 }}>v2.8.1 <Tag color="blue">最新版</Tag></div></div></Space></AntdCard></Col>
<Col span={5}><AntdCard size="small"><Space><div style={{ background: '#f6ffed', borderRadius: 8, padding: 8 }}><TeamOutlined style={{ color: '#52c41a', fontSize: 20 }} /></div><div><div style={{ fontSize: 13, color: '#666' }}>在线用户</div><div style={{ fontWeight: 600 }}>12 <span style={{ color: '#52c41a', fontSize: 12 }}>↑ 2</span></div></div></Space></AntdCard></Col>
<Col span={5}><AntdCard size="small"><Space><div style={{ background: '#fff2f0', borderRadius: 8, padding: 8 }}><BellOutlined style={{ color: '#ff4d4f', fontSize: 20 }} /></div><div><div style={{ fontSize: 13, color: '#666' }}>告警通道</div><div style={{ fontWeight: 600 }}>3 / 4 <span style={{ color: '#52c41a', fontSize: 12 }}>正常</span></div></div></Space></AntdCard></Col>
<Col span={5}><AntdCard size="small"><Space><div style={{ background: '#e6fffb', borderRadius: 8, padding: 8 }}><DatabaseOutlined style={{ color: '#13c2c2', fontSize: 20 }} /></div><div><div style={{ fontSize: 13, color: '#666' }}>数据备份状态</div><div style={{ fontWeight: 600 }}>正常 <span style={{ color: '#52c41a', fontSize: 12 }}>●</span></div></div></Space></AntdCard></Col>
<Col span={4}><AntdCard size="small"><Space><div style={{ background: '#f9f0ff', borderRadius: 8, padding: 8 }}><CalendarOutlined style={{ color: '#722ed1', fontSize: 20 }} /></div><div><div style={{ fontSize: 13, color: '#666' }}>最近更新</div><div style={{ fontWeight: 600 }}>2025-05-20</div></div></Space></AntdCard></Col>
2026-04-29 14:26:01 +08:00
</Row>
<AntdCard title="基础配置" style={{ marginBottom: 24 }}>
<Form form={form} layout="vertical">
2026-04-30 10:49:44 +08:00
<Row gutter={16}><Col span={8}><Form.Item label="系统名称" name="systemName"><Input defaultValue="光伏电站智能监控与运维系统" /></Form.Item></Col><Col span={8}><Form.Item label="默认电站" name="defaultSite"><Select defaultValue="1MW 光伏电站"><Option value="1MW">1MW 光伏电站</Option></Select></Form.Item></Col><Col span={8}><Form.Item label="默认语言" name="defaultLang"><Select defaultValue="中文"><Option value="zh">中文</Option><Option value="en">English</Option></Select></Form.Item></Col></Row>
<Row gutter={16}><Col span={8}><Form.Item label="时区" name="timezone"><Select defaultValue="UTC+08:00"><Option value="UTC+08:00">UTC+08:00</Option></Select></Form.Item></Col><Col span={8}><Form.Item label="首页默认页面" name="homePage"><Select defaultValue="总览首页"><Option value="overview">总览首页</Option></Select></Form.Item></Col><Col span={8}><Form.Item label="数据刷新频率" name="refreshRate"><Select defaultValue="5分钟"><Option value="5">5分钟</Option></Select></Form.Item></Col></Row>
<Row gutter={16}><Col span={8}><Form.Item label="地图服务" name="mapService"><Select defaultValue="高德地图"><Option value="amap">高德地图</Option></Select></Form.Item></Col><Col span={8}><Form.Item label="工单自动编号" valuePropName="checked"><Switch defaultChecked /></Form.Item></Col><Col span={8}><Form.Item label="AI建议自动生成" valuePropName="checked"><Switch defaultChecked /></Form.Item></Col></Row>
<Row gutter={16}><Col span={8}><Form.Item label="移动端同步" valuePropName="checked"><Switch defaultChecked /></Form.Item></Col></Row>
<Space><Button type="primary" onClick={handleSave}>保存设置</Button><Button>恢复默认</Button></Space>
2026-04-29 14:26:01 +08:00
</Form>
</AntdCard>
<AntdCard title="通知与告警策略" style={{ marginBottom: 24 }}>
<Row gutter={16} style={{ marginBottom: 16 }}>
2026-04-30 10:49:44 +08:00
<Col span={6}><Space><div style={{ background: '#f6ffed', borderRadius: 8, padding: 8 }}><BellOutlined style={{ color: '#52c41a', fontSize: 20 }} /></div><div><div style={{ display: 'flex', alignItems: 'center', gap: 8 }}><Text strong>短信</Text><Switch defaultChecked /></div><Text type="secondary">已启用</Text></div></Space></Col>
<Col span={6}><Space><div style={{ background: '#e6f4ff', borderRadius: 8, padding: 8 }}><BellOutlined style={{ color: '#1677ff', fontSize: 20 }} /></div><div><div style={{ display: 'flex', alignItems: 'center', gap: 8 }}><Text strong>邮件</Text><Switch defaultChecked /></div><Text type="secondary">已启用</Text></div></Space></Col>
<Col span={6}><Space><div style={{ background: '#fff7e6', borderRadius: 8, padding: 8 }}><BellOutlined style={{ color: '#fa8c16', fontSize: 20 }} /></div><div><div style={{ display: 'flex', alignItems: 'center', gap: 8 }}><Text strong>Telegram</Text><Switch defaultChecked /></div><Text type="secondary">已启用</Text></div></Space></Col>
<Col span={6}><Space><div style={{ background: '#fff0f6', borderRadius: 8, padding: 8 }}><BellOutlined style={{ color: '#eb2f96', fontSize: 20 }} /></div><div><div style={{ display: 'flex', alignItems: 'center', gap: 8 }}><Text strong>系统通知</Text><Switch defaultChecked /></div><Text type="secondary">已启用</Text></div></Space></Col>
2026-04-29 14:26:01 +08:00
</Row>
2026-04-30 10:49:44 +08:00
<Row gutter={16}><Col span={8}><Form.Item label="严重告警立即通知" valuePropName="checked"><Switch defaultChecked /></Form.Item></Col><Col span={8}><Form.Item label="发电下降超过15%" valuePropName="checked"><Switch defaultChecked /></Form.Item></Col><Col span={8}><Form.Item label="通信中断通知" valuePropName="checked"><Switch defaultChecked /></Form.Item></Col></Row>
<Row gutter={16}><Col span={8}><Form.Item label="每日汇总推送" valuePropName="checked"><Switch defaultChecked /></Form.Item></Col><Col span={8}><Form.Item label="夜间免打扰"><Select defaultValue="23:00-07:00"><Option value="23:00-07:00">23:00-07:00</Option></Select></Form.Item></Col></Row>
2026-04-29 14:26:01 +08:00
</AntdCard>
<AntdCard title="用户与权限预览">
2026-04-30 10:49:44 +08:00
<Table size="small" pagination={{ pageSize: 4 }} columns={[
{ title: '用户名', dataIndex: 'name' },
{ title: '角色', render: () => <Tag color="blue">管理员</Tag> },
{ title: '手机号', dataIndex: 'phone' },
{ title: '邮箱', dataIndex: 'email' },
{ title: '状态', render: () => <span style={{ color: '#52c41a' }}>● 在线</span> },
]} dataSource={[
{ name: '张运维', phone: '138****0001', email: 'zhangyw@pvsrmart.com' },
{ name: '李工程师', phone: '139****0002', email: 'li.gongcheng@pvsrmart.com' },
]} />
2026-04-29 14:26:01 +08:00
</AntdCard>
</div>
);
};
2026-04-30 10:49:44 +08:00
// 右侧面板
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>
2026-04-29 14:26:01 +08:00
2026-04-30 10:49:44 +08:00
<AntdCard title="设备接入状态" style={{ marginBottom: 24 }}>
<Space direction="vertical"><div style={{ display: 'flex', justifyContent: 'space-between' }}><span>逆变器</span><span>正常</span></div></Space>
</AntdCard>
2026-04-29 14:26:01 +08:00
2026-04-30 10:49:44 +08:00
<AntdCard title="数据与安全" style={{ marginBottom: 24 }}>
<Space direction="vertical"><div style={{ display: 'flex', justifyContent: 'space-between' }}><span>数据保留</span><span>3年</span></div></Space>
</AntdCard>
2026-04-29 14:26:01 +08:00
2026-04-30 10:49:44 +08:00
<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>
);
2026-04-29 14:26:01 +08:00
2026-04-30 10:49:44 +08:00
// ======================
// 主页面
// ======================
2026-04-29 14:26:01 +08:00
export default function SystemSettings() {
const [activeTab, setActiveTab] = useState('basic');
2026-04-30 10:49:44 +08:00
const [rawMenuList, setRawMenuList] = useState([]);
const [showTabs, setShowTabs] = useState([]);
2026-04-29 14:26:01 +08:00
2026-04-30 10:49:44 +08:00
// 获取菜单
const getMenuListApi = () => {
const params = { pageNum: 1, pageSize: 99999 };
return getMenuList(params);
};
2026-04-29 14:26:01 +08:00
2026-04-30 10:49:44 +08:00
// 动态生成 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 /> };
}
2026-04-30 13:04:17 +08:00
if (item.path === '/systemSetting/org') {
return { key: 'org', label: '组织管理', icon: <TeamOutlined /> };
}
if (item.path === '/systemSetting/site') {
return { key: 'site', label: '场站管理', icon: <EnvironmentOutlined /> };
}
2026-04-30 10:49:44 +08:00
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 /> };
}
return null;
}).filter(Boolean);
setShowTabs(tabs);
// 默认选中第一个
if (tabs.length > 0) {
setActiveTab(tabs[0].key);
}
}
});
}, []);
const BasicSettingsPage = () => <div style={{ padding: 20 }}><h2>基础设置页面</h2></div>;
const NoticePage = () => <div style={{ padding: 20 }}><h2>通知策略页面</h2></div>;
const DeviceAccessPage = () => <div style={{ padding: 20 }}><h2>设备接入页面</h2></div>;
const DataSafetyPage = () => <div style={{ padding: 20 }}><h2>数据与安全页面</h2></div>;
const SystemMaintenancePage = () => <div style={{ padding: 20 }}><h2>系统维护页面</h2></div>;
const DefaultPage = () => <div style={{ padding: 20 }}><h2>请选择菜单</h2></div>;
2026-04-29 14:26:01 +08:00
const renderTabContent = () => {
switch (activeTab) {
case 'basic':
2026-04-30 10:49:44 +08:00
return <BasicSettingsPage />;
2026-04-29 14:26:01 +08:00
case 'user-role':
return <UserRolePage />;
case 'menu':
2026-04-30 10:49:44 +08:00
return <MenuList />;
2026-04-30 13:04:17 +08:00
case 'org':
return <Organization />;
case 'site':
return <StationManage />;
2026-04-30 10:49:44 +08:00
case 'notice':
return <NoticePage />;
case 'deviceAccess':
return <DeviceAccessPage />;
case 'dataSafety':
return <DataSafetyPage />;
case 'systemMaintenance':
return <SystemMaintenancePage />;
2026-04-29 14:26:01 +08:00
default:
2026-04-30 10:49:44 +08:00
return <DefaultPage />;
2026-04-29 14:26:01 +08:00
}
};
return (
<Layout style={{ minHeight: '100vh', background: '#fff', overflow: 'hidden' }}>
2026-04-30 10:49:44 +08:00
<Header style={{ background: '#fff', padding: 0, borderBottom: '1px solid #f0f0f0', position: 'sticky', top: 0, zIndex: 10 }}>
2026-04-29 14:26:01 +08:00
<Menu
mode="horizontal"
selectedKeys={[activeTab]}
onClick={({ key }) => setActiveTab(key)}
2026-04-30 10:49:44 +08:00
items={showTabs}
style={{ border: 0, height: 64, lineHeight: '64px' }}
2026-04-29 14:26:01 +08:00
/>
</Header>
<Content style={{
2026-04-30 10:49:44 +08:00
maxHeight: 'calc(100vh - 64px)', overflowY: 'auto', background: '#f5f7fa',
2026-04-29 14:26:01 +08:00
scrollbarWidth: 'none',
msOverflowStyle: 'none',
}}>
{renderTabContent()}
</Content>
</Layout>
);
}