菜单模块增删改查
This commit is contained in:
@@ -121,3 +121,14 @@ export function getDeptMenuTreeSelect(deptId) {
|
||||
method: 'get'
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//获取树形菜单/getRouters
|
||||
|
||||
export function getTreeMenuList() {
|
||||
return request({
|
||||
url: `/getRouters`,
|
||||
method: 'get'
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ import {
|
||||
Layout, Menu, Button, Space, ConfigProvider, theme,
|
||||
Breadcrumb, Badge, message
|
||||
} from 'antd';
|
||||
// 先引入中文语言包
|
||||
import zhCN from 'antd/locale/zh_CN';
|
||||
import {
|
||||
DashboardOutlined, ExperimentOutlined, VideoCameraOutlined,
|
||||
BellOutlined, DownloadOutlined, UserOutlined, LogoutOutlined,
|
||||
@@ -15,6 +17,7 @@ import { RootState, useAppDispatch } from '../store';
|
||||
import { logout } from '../store/userSlice';
|
||||
import { getMenuList } from '../api/mune';
|
||||
|
||||
|
||||
const { Header, Sider, Content } = Layout;
|
||||
|
||||
export default function AppLayout() {
|
||||
@@ -26,6 +29,8 @@ export default function AppLayout() {
|
||||
const { userInfo } = useSelector((state: RootState) => state.user);
|
||||
const dispatch = useAppDispatch();
|
||||
|
||||
|
||||
|
||||
const getMenu = () => {
|
||||
getMenuList().then(res => {
|
||||
if (res.code == 200) {
|
||||
@@ -66,6 +71,7 @@ export default function AppLayout() {
|
||||
|
||||
return (
|
||||
<ConfigProvider
|
||||
locale={zhCN}
|
||||
theme={{
|
||||
algorithm: theme.defaultAlgorithm,
|
||||
token: { colorPrimary: '#1890ff', borderRadius: 2 },
|
||||
@@ -111,7 +117,11 @@ export default function AppLayout() {
|
||||
</div>
|
||||
</Header>
|
||||
|
||||
<Layout>
|
||||
<Layout style={{
|
||||
overflow: 'auto', background: '#ffffff',
|
||||
height: "calc(100vh - 50px)",
|
||||
overflowX: 'hidden'
|
||||
}}>
|
||||
{/* 左侧:菜单 + 下部区域 */}
|
||||
<Sider
|
||||
trigger={null}
|
||||
@@ -141,11 +151,12 @@ export default function AppLayout() {
|
||||
</Sider>
|
||||
|
||||
{/* 右侧:主内容 */}
|
||||
<Content className=" overflow-y-auto bg-[#f4f7f9] min-h-0">
|
||||
<Content className=" overflow-y-auto bg-[#f4f7f9] min-h-0 overflow-x-hidden">
|
||||
<Outlet />
|
||||
</Content>
|
||||
</Layout>
|
||||
</Layout>
|
||||
</ConfigProvider>
|
||||
|
||||
</ConfigProvider >
|
||||
);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
Select,
|
||||
DatePicker,
|
||||
List,
|
||||
Layout,
|
||||
} from 'antd';
|
||||
import {
|
||||
BellOutlined,
|
||||
@@ -22,74 +23,99 @@ import {
|
||||
ClockCircleOutlined,
|
||||
RiseOutlined,
|
||||
FallOutlined,
|
||||
CloseOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import { ALERTS } from '../constants';
|
||||
|
||||
const { Text, Title } = Typography;
|
||||
const { Text } = Typography;
|
||||
const { RangePicker } = DatePicker;
|
||||
const AntdCard = Card as any;
|
||||
|
||||
// 模拟数据
|
||||
const alertList = [
|
||||
{
|
||||
id: 'AL20250525001',
|
||||
content: '逆变器停机',
|
||||
device: '逆变器 12 (组串式)',
|
||||
level: '严重',
|
||||
time: '2025-05-25 09:18:32',
|
||||
duration: '2小时18分',
|
||||
status: '处理中',
|
||||
handler: '张运维',
|
||||
},
|
||||
{
|
||||
id: 'AL20250525002',
|
||||
content: '发电量下降 > 15%',
|
||||
device: '汇流箱 05',
|
||||
level: '重要',
|
||||
time: '2025-05-25 08:46:11',
|
||||
duration: '3小时50分',
|
||||
status: '处理中',
|
||||
handler: '李工程师',
|
||||
},
|
||||
{
|
||||
id: 'AL20250525003',
|
||||
content: '逆变器温度过高',
|
||||
device: '逆变器 07 (组串式)',
|
||||
level: '重要',
|
||||
time: '2025-05-25 07:32:45',
|
||||
duration: '4小时24分',
|
||||
status: '待处理',
|
||||
handler: '-',
|
||||
},
|
||||
];
|
||||
|
||||
const stats = [
|
||||
{
|
||||
title: '今日告警总数',
|
||||
value: 36,
|
||||
change: '+28.6%',
|
||||
up: true,
|
||||
extra: '昨日 28',
|
||||
icon: <BellOutlined style={{ color: '#ff4d4f' }} />,
|
||||
},
|
||||
{
|
||||
title: '严重告警',
|
||||
value: 8,
|
||||
change: '+33.3%',
|
||||
up: true,
|
||||
extra: '昨日 6',
|
||||
icon: <AlertOutlined style={{ color: '#ff4d4f' }} />,
|
||||
},
|
||||
{
|
||||
title: '处理中',
|
||||
value: 12,
|
||||
change: '+20.0%',
|
||||
up: true,
|
||||
extra: '昨日 10',
|
||||
icon: <SyncOutlined style={{ color: '#fa8c16' }} />,
|
||||
},
|
||||
{
|
||||
title: '已关闭',
|
||||
value: 16,
|
||||
change: '+45.5%',
|
||||
up: true,
|
||||
extra: '昨日 11',
|
||||
icon: <CheckCircleOutlined style={{ color: '#52c41a' }} />,
|
||||
},
|
||||
{
|
||||
title: '平均响应时长',
|
||||
value: '18分32秒',
|
||||
change: '-12.6%',
|
||||
up: false,
|
||||
extra: '昨日 21分12秒',
|
||||
icon: <ClockCircleOutlined style={{ color: '#1890ff' }} />,
|
||||
},
|
||||
];
|
||||
|
||||
export default function Alerts() {
|
||||
// 控制右侧详情面板
|
||||
const [showDetail, setShowDetail] = useState(false);
|
||||
const [selectedAlert, setSelectedAlert] = useState<any>(null);
|
||||
const AntdCard = Card as any;
|
||||
|
||||
// 模拟告警数据(和参考图一致)
|
||||
const alertList = [
|
||||
{
|
||||
id: 'AL20250525001',
|
||||
content: '逆变器停机',
|
||||
device: '逆变器 12 (组串式)',
|
||||
level: '严重',
|
||||
time: '2025-05-25 09:18:32',
|
||||
duration: '2小时18分',
|
||||
status: '处理中',
|
||||
handler: '张运维'
|
||||
},
|
||||
{
|
||||
id: 'AL20250525002',
|
||||
content: '发电量下降 > 15%',
|
||||
device: '汇流箱 05',
|
||||
level: '重要',
|
||||
time: '2025-05-25 08:46:11',
|
||||
duration: '3小时50分',
|
||||
status: '处理中',
|
||||
handler: '李工程师'
|
||||
},
|
||||
{
|
||||
id: 'AL20250525003',
|
||||
content: '逆变器温度过高',
|
||||
device: '逆变器 07 (组串式)',
|
||||
level: '重要',
|
||||
time: '2025-05-25 07:32:45',
|
||||
duration: '4小时24分',
|
||||
status: '待处理',
|
||||
handler: '-'
|
||||
},
|
||||
{
|
||||
id: 'AL20250525004',
|
||||
content: '通信中断',
|
||||
device: '气象站 01',
|
||||
level: '一般',
|
||||
time: '2025-05-25 06:51:20',
|
||||
duration: '5小时05分',
|
||||
status: '待处理',
|
||||
handler: '王运维'
|
||||
},
|
||||
{
|
||||
id: 'AL20250525005',
|
||||
content: '数据异常',
|
||||
device: '电表 01 (并网点)',
|
||||
level: '提示',
|
||||
time: '2025-05-25 06:20:18',
|
||||
duration: '3小时36分',
|
||||
status: '已关闭',
|
||||
handler: '赵工程师'
|
||||
},
|
||||
];
|
||||
|
||||
const columns = [
|
||||
{ title: '告警编号', dataIndex: 'id', key: 'id', width: 120 },
|
||||
{ title: '告警内容', dataIndex: 'content', key: 'content' },
|
||||
{ title: '来源设备', dataIndex: 'device', key: 'device', width: 140 },
|
||||
{ title: '来源设备', dataIndex: 'device', key: 'device', width: 160 },
|
||||
{
|
||||
title: '告警级别',
|
||||
dataIndex: 'level',
|
||||
@@ -97,16 +123,16 @@ export default function Alerts() {
|
||||
width: 80,
|
||||
render: (level: string) => {
|
||||
const colorMap: Record<string, string> = {
|
||||
'严重': 'red',
|
||||
'重要': 'orange',
|
||||
'一般': 'gold',
|
||||
'提示': 'blue'
|
||||
严重: 'red',
|
||||
重要: 'orange',
|
||||
一般: 'gold',
|
||||
提示: 'blue',
|
||||
};
|
||||
return <Tag color={colorMap[level]}>{level}</Tag>;
|
||||
}
|
||||
},
|
||||
},
|
||||
{ title: '发生时间', dataIndex: 'time', key: 'time', width: 160 },
|
||||
{ title: '持续时长', dataIndex: 'duration', key: 'duration', width: 100 },
|
||||
{ title: '持续时长', dataIndex: 'duration', key: 'duration', width: 110 },
|
||||
{
|
||||
title: '处理状态',
|
||||
dataIndex: 'status',
|
||||
@@ -114,209 +140,184 @@ export default function Alerts() {
|
||||
width: 100,
|
||||
render: (status: string) => {
|
||||
const colorMap: Record<string, string> = {
|
||||
'处理中': 'blue',
|
||||
'待处理': 'orange',
|
||||
'已关闭': 'green'
|
||||
处理中: 'blue',
|
||||
待处理: 'orange',
|
||||
已关闭: 'green',
|
||||
};
|
||||
return <Tag color={colorMap[status]}>{status}</Tag>;
|
||||
}
|
||||
},
|
||||
},
|
||||
{ title: '负责人', dataIndex: 'handler', key: 'handler', width: 80 },
|
||||
{ title: '负责人', dataIndex: 'handler', key: 'handler', width: 90 },
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 60,
|
||||
render: () => <Button type="link" size="small">查看</Button>
|
||||
width: 80,
|
||||
render: (_, record) => (
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
onClick={() => {
|
||||
setSelectedAlert(record);
|
||||
setShowDetail(true);
|
||||
}}
|
||||
>
|
||||
查看
|
||||
</Button>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
// 顶部统计数据
|
||||
const stats = [
|
||||
{ title: '今日告警总数', value: 36, suffix: '', change: '+28.6%', up: true, extra: '昨日 28', icon: <BellOutlined style={{ color: '#ff4d4f' }} /> },
|
||||
{ title: '严重告警', value: 8, suffix: '', change: '+33.3%', up: true, extra: '昨日 6', icon: <AlertOutlined style={{ color: '#ff4d4f' }} /> },
|
||||
{ title: '处理中', value: 12, suffix: '', change: '+20.0%', up: true, extra: '昨日 10', icon: <SyncOutlined style={{ color: '#fa8c16' }} /> },
|
||||
{ title: '已关闭', value: 16, suffix: '', change: '+45.5%', up: true, extra: '昨日 11', icon: <CheckCircleOutlined style={{ color: '#52c41a' }} /> },
|
||||
{ title: '平均响应时长', value: '18分32秒', suffix: '', change: '-12.6%', up: false, extra: '昨日 21分12秒', icon: <ClockCircleOutlined style={{ color: '#1890ff' }} /> },
|
||||
];
|
||||
|
||||
return (
|
||||
<div style={{ padding: '16px', background: '#f4f7f9', minHeight: '100%' }}>
|
||||
<p className="text-lg font-semibold text-[#000] mb-2">
|
||||
告警中心
|
||||
</p>
|
||||
{/* 顶部筛选栏 */}
|
||||
<AntdCard size="small" style={{ borderRadius: 8, marginBottom: 16 }}>
|
||||
<Row gutter={[16, 16]} align="middle">
|
||||
<Col span={4}>
|
||||
<Select placeholder="告警级别" defaultValue="全部" style={{ width: '100%' }} options={[{ label: '全部', value: 'all' }, { label: '严重', value: 'critical' }, { label: '重要', value: 'important' }, { label: '一般', value: 'normal' }, { label: '提示', value: 'info' }]} />
|
||||
</Col>
|
||||
<Col span={4}>
|
||||
<Select placeholder="告警类型" defaultValue="全部" style={{ width: '100%' }} options={[{ label: '全部', value: 'all' }]} />
|
||||
</Col>
|
||||
<Col span={4}>
|
||||
<Select placeholder="设备类型" defaultValue="全部" style={{ width: '100%' }} options={[{ label: '全部', value: 'all' }]} />
|
||||
</Col>
|
||||
<Col span={6}>
|
||||
<RangePicker defaultValue={[null, null]} style={{ width: '100%' }} />
|
||||
</Col>
|
||||
<Col span={4}>
|
||||
<Select placeholder="处理状态" defaultValue="全部" style={{ width: '100%' }} options={[{ label: '全部', value: 'all' }, { label: '处理中', value: 'processing' }, { label: '已关闭', value: 'closed' }]} />
|
||||
</Col>
|
||||
<Col span={24} style={{ display: 'flex', alignItems: 'center', gap: 8, marginTop: 8 }}>
|
||||
<Input placeholder="请输入告警编号内容" style={{ width: 200 }} />
|
||||
<Button>重置</Button>
|
||||
<Button type="primary">查询</Button>
|
||||
</Col>
|
||||
</Row>
|
||||
</AntdCard>
|
||||
<div style={{ background: '#f4f7f9', minHeight: '100%' }}>
|
||||
<Layout style={{ background: 'transparent' }}>
|
||||
{/* 左侧主内容区:宽度动态变化 */}
|
||||
<Layout.Content
|
||||
style={{
|
||||
padding: '16px',
|
||||
transition: 'width 0.3s ease',
|
||||
width: showDetail ? 'calc(100% - 460px)' : '100%',
|
||||
}}
|
||||
>
|
||||
<div style={{ fontSize: 16, fontWeight: 600, marginBottom: 12 }}>告警中心</div>
|
||||
|
||||
{/* 统计卡片 */}
|
||||
<Row gutter={[16, 16]} style={{ marginBottom: 16 }}>
|
||||
{stats.map((stat, idx) => (
|
||||
<Col xs={24} sm={12} md={8} lg={4} key={idx}>
|
||||
<AntdCard size="small" style={{ borderRadius: 8, boxShadow: '0 2px 8px rgba(0,0,0,0.06)' }}>
|
||||
<Statistic
|
||||
title={<span style={{ fontSize: 13, color: '#666' }}>{stat.title}</span>}
|
||||
value={stat.value}
|
||||
valueStyle={{ color: '#1f2329', fontWeight: 600, fontSize: 20 }}
|
||||
prefix={stat.icon}
|
||||
suffix={stat.suffix}
|
||||
/>
|
||||
<div style={{ marginTop: 4, display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
|
||||
<Text type="secondary" style={{ fontSize: 12 }}>{stat.extra}</Text>
|
||||
<Text style={{ fontSize: 12, color: stat.up ? '#ff4d4f' : '#52c41a' }}>
|
||||
{stat.change} {stat.up ? <RiseOutlined /> : <FallOutlined />}
|
||||
</Text>
|
||||
</div>
|
||||
</AntdCard>
|
||||
</Col>
|
||||
))}
|
||||
</Row>
|
||||
{/* 筛选栏 */}
|
||||
<AntdCard size="small" style={{ borderRadius: 8, marginBottom: 16 }}>
|
||||
<Row gutter={[16, 16]} align="middle">
|
||||
<Col span={4}><Select placeholder="告警级别" style={{ width: '100%' }} /></Col>
|
||||
<Col span={4}><Select placeholder="告警类型" style={{ width: '100%' }} /></Col>
|
||||
<Col span={4}><Select placeholder="设备类型" style={{ width: '100%' }} /></Col>
|
||||
<Col span={6}><RangePicker style={{ width: '100%' }} /></Col>
|
||||
<Col span={6}><Select placeholder="处理状态" style={{ width: '100%' }} /></Col>
|
||||
<Col span={24} style={{ display: 'flex', gap: 8, marginTop: 8 }}>
|
||||
<Input placeholder="搜索" style={{ width: 220 }} />
|
||||
<Button>重置</Button>
|
||||
<Button type="primary">查询</Button>
|
||||
</Col>
|
||||
</Row>
|
||||
</AntdCard>
|
||||
|
||||
{/* 统计卡片 */}
|
||||
<Row gutter={[16, 16]} style={{ marginBottom: 16 }}>
|
||||
{stats.map((stat, idx) => (
|
||||
<Col xs={24} sm={12} md={8} lg={4} key={idx}>
|
||||
<AntdCard size="small" style={{ borderRadius: 8 }}>
|
||||
<Statistic
|
||||
title={<span style={{ fontSize: 13 }}>{stat.title}</span>}
|
||||
value={stat.value}
|
||||
valueStyle={{ fontSize: 20, fontWeight: 600 }}
|
||||
prefix={stat.icon}
|
||||
/>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', marginTop: 4 }}>
|
||||
<Text type="secondary" style={{ fontSize: 12 }}>{stat.extra}</Text>
|
||||
<Text style={{ color: stat.up ? '#ff4d4f' : '#52c41a', fontSize: 12 }}>
|
||||
{stat.change} {stat.up ? <RiseOutlined /> : <FallOutlined />}
|
||||
</Text>
|
||||
</div>
|
||||
</AntdCard>
|
||||
</Col>
|
||||
))}
|
||||
</Row>
|
||||
|
||||
<Row gutter={[16, 16]}>
|
||||
{/* 左侧主内容区 */}
|
||||
<Col xs={24} lg={18}>
|
||||
{/* 告警列表 */}
|
||||
<AntdCard size="small" title={
|
||||
<div style={{ display: 'flex', gap: 4, fontSize: 14, fontWeight: 600 }}>
|
||||
<span style={{ color: '#165DFF' }}>告警列表</span>
|
||||
<span style={{ color: '#1f2937' }}>(共36条)</span>
|
||||
</div>
|
||||
} style={{ borderRadius: 8, marginBottom: 16 }}>
|
||||
<AntdCard
|
||||
size="small"
|
||||
title={
|
||||
<div style={{ fontSize: 14, fontWeight: 600 }}>
|
||||
<span style={{ color: '#165DFF' }}>告警列表</span>
|
||||
<span style={{ color: '#333' }}>(共36条)</span>
|
||||
</div>
|
||||
}
|
||||
style={{ borderRadius: 8 }}
|
||||
>
|
||||
<Table
|
||||
size="small"
|
||||
columns={columns}
|
||||
dataSource={alertList}
|
||||
pagination={{ pageSize: 10, total: 36, showSizeChanger: true }}
|
||||
pagination={{ pageSize: 10 }}
|
||||
rowKey="id"
|
||||
onRow={(record) => ({ onClick: () => setSelectedAlert(record) })}
|
||||
rowSelection={{ selectedRowKeys: selectedAlert ? [selectedAlert.id] : [], type: 'radio' }}
|
||||
onRow={(record) => ({
|
||||
onClick: () => {
|
||||
setSelectedAlert(record);
|
||||
setShowDetail(true);
|
||||
},
|
||||
})}
|
||||
/>
|
||||
</AntdCard>
|
||||
</Layout.Content>
|
||||
|
||||
{/* 底部图表占位(和参考图结构一致) */}
|
||||
<Row gutter={[16, 16]}>
|
||||
<Col xs={24} lg={8}>
|
||||
<AntdCard size="small" style={{ borderRadius: 8 }}>
|
||||
<div style={{ height: 150, background: '#f5f7fa', borderRadius: 4, display: 'flex', alignItems: 'center', justifyContent: 'center', color: '#888' }}>
|
||||
趋势图占位
|
||||
</div>
|
||||
</AntdCard>
|
||||
</Col>
|
||||
<Col xs={24} lg={8}>
|
||||
<AntdCard size="small" style={{ borderRadius: 8 }}>
|
||||
<div style={{ height: 150, background: '#f5f7fa', borderRadius: 4, display: 'flex', alignItems: 'center', justifyContent: 'center', color: '#888' }}>
|
||||
占比图占位
|
||||
</div>
|
||||
</AntdCard>
|
||||
</Col>
|
||||
<Col xs={24} lg={8}>
|
||||
<AntdCard size="small" style={{ borderRadius: 8 }}>
|
||||
<div style={{ height: 150, background: '#f5f7fa', borderRadius: 4, display: 'flex', alignItems: 'center', justifyContent: 'center', color: '#888' }}>
|
||||
分布图占位
|
||||
</div>
|
||||
</AntdCard>
|
||||
</Col>
|
||||
</Row>
|
||||
</Col>
|
||||
|
||||
{/* 右侧告警详情面板 */}
|
||||
<Col xs={24} lg={6}>
|
||||
<AntdCard size="small" style={{ borderRadius: 8, height: '100%' }}>
|
||||
{selectedAlert ? (
|
||||
{/* 右侧详情面板:推挤式,非覆盖 */}
|
||||
{showDetail && (
|
||||
<Layout.Sider
|
||||
width={460}
|
||||
style={{
|
||||
background: '#fff',
|
||||
padding: '16px',
|
||||
height: 'calc(100vh - 50px)',
|
||||
overflow: 'auto',
|
||||
boxShadow: '-2px 0 8px rgba(0,0,0,0.08)',
|
||||
}}
|
||||
>
|
||||
{selectedAlert && (
|
||||
<div>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 16 }}>
|
||||
<Text strong style={{ fontSize: 16 }}>告警详情</Text>
|
||||
<Button
|
||||
type="text"
|
||||
icon={<CloseOutlined />}
|
||||
onClick={() => setShowDetail(false)}
|
||||
style={{ fontSize: 16 }}
|
||||
/> </div>
|
||||
|
||||
<div style={{ marginBottom: 16 }}>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 8 }}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
|
||||
<BellOutlined style={{ color: '#ff4d4f', fontSize: 20 }} />
|
||||
<Text strong style={{ fontSize: 16 }}>{selectedAlert.content}</Text>
|
||||
<Tag color="red">{selectedAlert.level}</Tag>
|
||||
</div>
|
||||
<Text type="secondary" style={{ fontSize: 12 }}>告警编号 AL20250525001</Text>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 8 }}>
|
||||
<BellOutlined style={{ color: '#ff4d4f', fontSize: 20 }} />
|
||||
<Text strong style={{ fontSize: 16 }}>{selectedAlert.content}</Text>
|
||||
<Tag color="red">{selectedAlert.level}</Tag>
|
||||
</div>
|
||||
<div style={{ fontSize: 12, color: '#666' }}>
|
||||
<div>来源设备:{selectedAlert.device}(设备类型:逆变器)</div>
|
||||
<div>发生时间:{selectedAlert.time} | 持续时长:{selectedAlert.duration}</div>
|
||||
<div>处理状态:<Tag color="blue">{selectedAlert.status}</Tag> | 负责人:{selectedAlert.handler}</div>
|
||||
<div>当前处理人:{selectedAlert.handler}({selectedAlert.time.split(' ')[0]} 接收)</div>
|
||||
<div>告警描述:逆变器因内部故障自动停机,当前无功率输出。</div>
|
||||
<div style={{ fontSize: 12, color: '#666', lineHeight: 1.8 }}>
|
||||
<div>告警编号:{selectedAlert.id}</div>
|
||||
<div>来源设备:{selectedAlert.device}</div>
|
||||
<div>发生时间:{selectedAlert.time}</div>
|
||||
<div>持续时长:{selectedAlert.duration}</div>
|
||||
<div>处理状态:{selectedAlert.status}</div>
|
||||
<div>负责人:{selectedAlert.handler}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style={{ marginBottom: 16 }}>
|
||||
<Text strong style={{ fontSize: 13, marginBottom: 8, display: 'block' }}>根因分析建议</Text>
|
||||
<List size="small" dataSource={[
|
||||
'逆变器内部保护触发(IGBT/继电器故障)',
|
||||
'交流侧电压异常或并网不稳定',
|
||||
'散热风扇故障导致过温保护'
|
||||
]} renderItem={(item) => <List.Item style={{ padding: '4px 0', fontSize: 12 }}>{item}</List.Item>} />
|
||||
<Button type="primary" size="small" style={{ marginTop: 8 }}>AI 诊断分析</Button>
|
||||
</div>
|
||||
|
||||
<div style={{ marginBottom: 16 }}>
|
||||
<Text strong style={{ fontSize: 13, marginBottom: 8, display: 'block' }}>相关趋势</Text>
|
||||
<div style={{ height: 100, background: '#f5f7fa', borderRadius: 4, display: 'flex', alignItems: 'center', justifyContent: 'center', color: '#888' }}>
|
||||
趋势图占位
|
||||
</div>
|
||||
<List
|
||||
size="small"
|
||||
dataSource={[
|
||||
'逆变器内部保护触发(IGBT/继电器故障)',
|
||||
'交流侧电压异常或并网不稳定',
|
||||
'散热风扇故障导致过温保护',
|
||||
]}
|
||||
renderItem={(item) => <List.Item style={{ padding: '4px 0' }}>{item}</List.Item>}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div style={{ marginBottom: 16 }}>
|
||||
<Text strong style={{ fontSize: 13, marginBottom: 8, display: 'block' }}>推荐处理措施</Text>
|
||||
<List size="small" dataSource={[
|
||||
'现场检查逆变器告警记录及指示灯状态',
|
||||
'检查散热风扇运行及通风条件',
|
||||
'检查交流侧电压及并网条件',
|
||||
'如无法恢复,建议联系厂家或更换模块'
|
||||
]} renderItem={(item) => <List.Item style={{ padding: '4px 0', fontSize: 12 }}>{item}</List.Item>} />
|
||||
<Button type="primary" size="small" style={{ marginTop: 8 }}>生成工单</Button>
|
||||
<List
|
||||
size="small"
|
||||
dataSource={[
|
||||
'现场检查逆变器告警记录及指示灯状态',
|
||||
'检查散热风扇运行及通风条件',
|
||||
'检查交流侧电压及并网条件',
|
||||
]}
|
||||
renderItem={(item) => <List.Item style={{ padding: '4px 0' }}>{item}</List.Item>}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div style={{ marginBottom: 16 }}>
|
||||
<Text strong style={{ fontSize: 13, marginBottom: 8, display: 'block' }}>通知与订阅</Text>
|
||||
<Space direction="vertical" size="small" style={{ width: '100%' }}>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', width: '100%' }}>
|
||||
<span style={{ fontSize: 12 }}>短信</span>
|
||||
<span style={{ fontSize: 12, color: '#1890ff' }}>已开启</span>
|
||||
</div>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', width: '100%' }}>
|
||||
<span style={{ fontSize: 12 }}>Telegram</span>
|
||||
<span style={{ fontSize: 12, color: '#1890ff' }}>已开启</span>
|
||||
</div>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', width: '100%' }}>
|
||||
<span style={{ fontSize: 12 }}>邮件</span>
|
||||
<span style={{ fontSize: 12, color: '#888' }}>未开启</span>
|
||||
</div>
|
||||
</Space>
|
||||
</div>
|
||||
|
||||
<Button type="primary" block>标记为已解决</Button>
|
||||
<Button type="primary" block style={{ marginTop: 16 }}>
|
||||
标记为已解决
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
<div style={{ textAlign: 'center', padding: '40px 0', color: '#888' }}>请选择一条告警查看详情</div>
|
||||
)}
|
||||
</AntdCard>
|
||||
</Col>
|
||||
</Row>
|
||||
</Layout.Sider>
|
||||
)}
|
||||
</Layout>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React from 'react';
|
||||
import React, { useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import {
|
||||
Form,
|
||||
@@ -6,7 +6,6 @@ import {
|
||||
Button,
|
||||
Typography,
|
||||
Card,
|
||||
message,
|
||||
Checkbox,
|
||||
App,
|
||||
} from 'antd';
|
||||
@@ -22,50 +21,46 @@ import { useAppDispatch } from '../store';
|
||||
import Cookies from 'js-cookie';
|
||||
|
||||
const { Text, Title } = Typography;
|
||||
const AntdCard = Card as any;
|
||||
|
||||
export default function Login() {
|
||||
const navigate = useNavigate();
|
||||
const dispatch = useAppDispatch();
|
||||
const { message, } = App.useApp();
|
||||
const { message } = App.useApp();
|
||||
// 登录 loading 状态
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
// 账号密码登录
|
||||
const onFinish = async (values: any) => {
|
||||
try {
|
||||
// 开启 loading
|
||||
setLoading(true);
|
||||
|
||||
// 👇 调用 dispatch,并用 unwrap() 拿到 return 的数据
|
||||
const loginResult = await dispatch(userLogin(values)).unwrap();
|
||||
|
||||
// loginResult 就是你 userLogin 里 return 的 res
|
||||
console.log("登录成功返回的数据:", loginResult);
|
||||
|
||||
if (loginResult.code == 200) {
|
||||
//dispatch(setUserInfo(loginResult))
|
||||
message.success('登录成功');
|
||||
const searchParams = new URLSearchParams(window.location.search);
|
||||
const goRemote = searchParams.get('goRemote');
|
||||
if (Number(goRemote) == 1) {
|
||||
const rawUserId = Cookies.get("userId"); // 比如 "32434"
|
||||
|
||||
const rawUserId = Cookies.get('userId');
|
||||
const encodedUserId = btoa(unescape(encodeURIComponent(rawUserId)));
|
||||
window.location.href = `https://ai.satabot.com/?userId=${encodedUserId}`;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
message.success(`登录成功`);
|
||||
navigate('/', { replace: true });
|
||||
} else {
|
||||
|
||||
message.error("登录失败:" + loginResult.msg);
|
||||
|
||||
|
||||
message.error('登录失败:' + loginResult.msg);
|
||||
}
|
||||
|
||||
// 登录成功后跳转
|
||||
|
||||
} catch (err) {
|
||||
message.error("登录失败:" + err.toString());
|
||||
|
||||
message.error('登录失败:' + err.toString());
|
||||
} finally {
|
||||
// 无论成功失败,关闭 loading
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -82,7 +77,7 @@ export default function Login() {
|
||||
transition={{ duration: 0.4 }}
|
||||
className="w-full max-w-5xl"
|
||||
>
|
||||
<Card
|
||||
<AntdCard
|
||||
variant={false}
|
||||
className="shadow-xl overflow-hidden rounded-2xl"
|
||||
styles={{ body: { padding: 0 } }}
|
||||
@@ -112,20 +107,26 @@ export default function Login() {
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
{/* 记住密码 */}
|
||||
{/*<Form.Item name="remember" valuePropName="checked" noStyle>
|
||||
{/* 用户协议 */}
|
||||
<Form.Item
|
||||
name="agreement"
|
||||
valuePropName="checked"
|
||||
rules={[{ validator: (_, value) => value ? Promise.resolve() : Promise.reject(new Error('请阅读并同意用户协议')) }]}
|
||||
>
|
||||
<Checkbox>
|
||||
<Text style={{ fontSize: 14, color: '#666' }}>记住密码</Text>
|
||||
<Text style={{ fontSize: 14, color: '#666' }}>
|
||||
我已阅读并同意 <Text type="link" style={{ padding: 0, color: '#1677ff' }}>用户协议</Text> 和 <Text type="link" style={{ padding: 0, color: '#1677ff' }}>隐私政策</Text>
|
||||
</Text>
|
||||
</Checkbox>
|
||||
</Form.Item>*/}
|
||||
|
||||
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item style={{ marginTop: 20 }}>
|
||||
<Button
|
||||
type="primary"
|
||||
htmlType="submit"
|
||||
block
|
||||
// 绑定 loading
|
||||
loading={loading}
|
||||
style={{
|
||||
borderRadius: 8,
|
||||
height: 52,
|
||||
@@ -139,18 +140,6 @@ export default function Login() {
|
||||
登录
|
||||
</Button>
|
||||
</Form.Item>
|
||||
{/* 用户协议 */}
|
||||
<Form.Item
|
||||
name="agreement"
|
||||
valuePropName="checked"
|
||||
rules={[{ validator: (_, value) => value ? Promise.resolve() : Promise.reject(new Error('请阅读并同意用户协议')) }]}
|
||||
>
|
||||
<Checkbox>
|
||||
<Text style={{ fontSize: 14, color: '#666' }}>
|
||||
我已阅读并同意 <Text type="link" style={{ padding: 0, color: "#1677ff" }}>用户协议</Text> 和 <Text type="link" style={{ padding: 0, color: "#1677ff" }}>隐私政策</Text>
|
||||
</Text>
|
||||
</Checkbox>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</motion.div>
|
||||
</div>
|
||||
@@ -159,7 +148,6 @@ export default function Login() {
|
||||
<div
|
||||
className="md:w-1/2 relative min-h-[600px] overflow-hidden"
|
||||
style={{
|
||||
// 梯形斜切效果
|
||||
clipPath: 'polygon(12% 0, 100% 0, 100% 100%, 0 100%)',
|
||||
}}
|
||||
>
|
||||
@@ -174,7 +162,7 @@ export default function Login() {
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
</AntdCard>
|
||||
</motion.div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,50 +1,16 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import {
|
||||
Table, Button, Typography, Space, Modal, Form, Tree, message,
|
||||
Input, Popconfirm, Select
|
||||
Table, Button, Space, Modal, Form, Tree, message,
|
||||
Input, Popconfirm, Select, Card, InputNumber
|
||||
} from 'antd';
|
||||
import {
|
||||
PlusOutlined, EditOutlined, DeleteOutlined, SettingOutlined
|
||||
} from '@ant-design/icons';
|
||||
import { addMenu, deleteMenu, getMenuList, updateMenu } from '../api/mune';
|
||||
|
||||
const { Title } = Typography;
|
||||
const { Option } = Select;
|
||||
|
||||
// 1. 完整菜单树
|
||||
const menuData = [
|
||||
{
|
||||
id: 1,
|
||||
title: '控制台',
|
||||
path: '/dashboard',
|
||||
parentId: 0,
|
||||
children: [
|
||||
{ id: 11, title: '概览', path: '/dashboard/overview', parentId: 1 },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
title: '设备管理',
|
||||
path: '/device',
|
||||
parentId: 0,
|
||||
children: [
|
||||
{ id: 21, title: '机器人管理', path: '/device/robot', parentId: 2 },
|
||||
{ id: 22, title: '视频监控', path: '/device/video', parentId: 2 },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
title: '系统管理',
|
||||
path: '/system',
|
||||
parentId: 0,
|
||||
children: [
|
||||
{ id: 31, title: '用户管理', path: '/system/user', parentId: 3 },
|
||||
{ id: 32, title: '角色管理', path: '/system/role', parentId: 3 },
|
||||
{ id: 33, title: '菜单管理', path: '/system/menu', parentId: 3 },
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
// 2. 角色列表
|
||||
// 角色列表
|
||||
const roleList = [
|
||||
{ name: '平台admin', key: 'admin' },
|
||||
{ name: '区域机构管理员', key: 'region_admin' },
|
||||
@@ -52,152 +18,176 @@ const roleList = [
|
||||
{ name: '场站员工', key: 'site_staff' },
|
||||
];
|
||||
|
||||
// 扁平化菜单
|
||||
const flattenMenu = (menus) => {
|
||||
let arr = [];
|
||||
const loop = (list, parentPath = '') => {
|
||||
list.forEach(item => {
|
||||
const fullPath = parentPath ? `${parentPath}/${item.path}` : item.path;
|
||||
arr.push({ ...item, fullPath });
|
||||
if (item.children?.length) loop(item.children, item.path);
|
||||
});
|
||||
};
|
||||
loop(menus);
|
||||
return arr;
|
||||
};
|
||||
|
||||
// 转树形结构(用于Tree组件)
|
||||
const buildTree = (flatten) => {
|
||||
// 扁平数组 → 树形结构(给表格 + 权限树共用)
|
||||
const buildTreeFromFlat = (data) => {
|
||||
const map = {};
|
||||
const tree = [];
|
||||
flatten.forEach(item => {
|
||||
map[item.id] = { ...item, children: [] };
|
||||
|
||||
data.forEach(item => {
|
||||
map[item.menuId] = { ...item, children: [] };
|
||||
});
|
||||
flatten.forEach(item => {
|
||||
if (item.parentId === 0) {
|
||||
tree.push(map[item.id]);
|
||||
|
||||
data.forEach(item => {
|
||||
if (item.parentId === 0 || !item.parentId) {
|
||||
tree.push(map[item.menuId]);
|
||||
} else {
|
||||
if (map[item.parentId]) {
|
||||
map[item.parentId].children.push(map[item.id]);
|
||||
map[item.parentId].children.push(map[item.menuId]);
|
||||
}
|
||||
}
|
||||
});
|
||||
return tree;
|
||||
};
|
||||
|
||||
// 存储角色权限
|
||||
// 菜单数据转 Tree组件 格式
|
||||
const buildPermTree = (treeData) => {
|
||||
const loop = (list) => {
|
||||
return list.map(item => {
|
||||
const node = {
|
||||
title: item.menuName,
|
||||
key: item.menuId,
|
||||
};
|
||||
if (item.children && item.children.length) {
|
||||
node.children = loop(item.children);
|
||||
}
|
||||
return node;
|
||||
});
|
||||
};
|
||||
return loop(treeData);
|
||||
};
|
||||
|
||||
const rolePermissionMap = {};
|
||||
|
||||
export default function Roles() {
|
||||
const [menus, setMenus] = useState(flattenMenu(menuData));
|
||||
const [menuTree, setMenuTree] = useState(buildTree(flattenMenu(menuData)));
|
||||
export default function MenuList() {
|
||||
const [rawMenuList, setRawMenuList] = useState([]);
|
||||
const [menuTreeData, setMenuTreeData] = useState([]);
|
||||
const [menuTree, setMenuTree] = useState([]);
|
||||
|
||||
// 新增/编辑菜单
|
||||
const [menuModal, setMenuModal] = useState(false);
|
||||
const [menuForm] = Form.useForm();
|
||||
const [editMenu, setEditMenu] = useState(null);
|
||||
|
||||
// 权限配置
|
||||
const [permModal, setPermModal] = useState(false);
|
||||
const [selectedRole, setSelectedRole] = useState('');
|
||||
const [checkedKeys, setCheckedKeys] = useState([]);
|
||||
const [messageApi, contextHolder] = message.useMessage();
|
||||
|
||||
// 菜单类型:一级/二级
|
||||
const menuType = Form.useWatch('menuType', menuForm);
|
||||
|
||||
// 每次菜单变化,重新生成树形
|
||||
useEffect(() => {
|
||||
setMenuTree(buildTree(menus));
|
||||
}, [menus]);
|
||||
|
||||
// 打开编辑
|
||||
const handleEdit = (record) => {
|
||||
setEditMenu(record);
|
||||
menuForm.setFieldsValue({
|
||||
...record,
|
||||
menuType: record.parentId === 0 ? 'top' : 'sub',
|
||||
// 获取菜单
|
||||
const getMenuListApi = () => {
|
||||
getMenuList().then(res => {
|
||||
if (res.code === 200) {
|
||||
const data = res.data || [];
|
||||
setRawMenuList(data);
|
||||
// 扁平转树形 → 表格树形 & 权限树
|
||||
const tree = buildTreeFromFlat(data);
|
||||
setMenuTreeData(tree);
|
||||
setMenuTree(buildPermTree(tree));
|
||||
}
|
||||
}).catch(() => {
|
||||
messageApi.error('菜单加载失败');
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
getMenuListApi();
|
||||
}, []);
|
||||
|
||||
// 编辑
|
||||
const handleEdit = (record) => {
|
||||
console.log(record, "values11")
|
||||
|
||||
setEditMenu(record);
|
||||
menuForm.setFieldsValue({ ...record });
|
||||
setMenuModal(true);
|
||||
};
|
||||
|
||||
// 保存菜单(新增+编辑)
|
||||
// 保存菜单
|
||||
const handleSaveMenu = () => {
|
||||
menuForm.validateFields().then(values => {
|
||||
const { menuType, parentId, title, path } = values;
|
||||
console.log(values, "values")
|
||||
if (editMenu) {
|
||||
// 编辑
|
||||
setMenus(menus.map(m =>
|
||||
m.id === editMenu.id
|
||||
? {
|
||||
...m,
|
||||
title,
|
||||
path,
|
||||
parentId: menuType === 'top' ? 0 : Number(parentId)
|
||||
}
|
||||
: m
|
||||
));
|
||||
message.success('编辑成功');
|
||||
const data = {
|
||||
menuId: editMenu.menuId,
|
||||
...values
|
||||
}
|
||||
updateMenu(data).then(res => {
|
||||
if (res.code === 200) {
|
||||
messageApi.success("编辑成功");
|
||||
setMenuModal(false);
|
||||
getMenuListApi();
|
||||
} else {
|
||||
messageApi.error(res.msg);
|
||||
}
|
||||
}).catch(() => {
|
||||
messageApi.error('编辑失败');
|
||||
});
|
||||
} else {
|
||||
// 新增
|
||||
const newMenu = {
|
||||
id: Date.now(),
|
||||
title,
|
||||
path,
|
||||
parentId: menuType === 'top' ? 0 : Number(parentId),
|
||||
};
|
||||
setMenus([...menus, newMenu]);
|
||||
message.success('新增菜单成功');
|
||||
addMenu(values).then(res => {
|
||||
if (res.code === 200) {
|
||||
messageApi.success("新增成功");
|
||||
setMenuModal(false);
|
||||
getMenuListApi();
|
||||
} else {
|
||||
messageApi.error(res.msg);
|
||||
}
|
||||
}).catch(() => {
|
||||
messageApi.error('新增失败');
|
||||
});
|
||||
}
|
||||
setMenuModal(false);
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
// 删除菜单
|
||||
const handleDelete = (id) => {
|
||||
setMenus(menus.filter(m => m.id !== id));
|
||||
message.success('删除成功');
|
||||
// 删除
|
||||
const handleDelete = (menuId) => {
|
||||
deleteMenu(menuId).then(res => {
|
||||
if (res.code == 200) {
|
||||
messageApi.success('删除成功');
|
||||
getMenuListApi();
|
||||
} else {
|
||||
messageApi.error(res.msg);
|
||||
}
|
||||
}).catch(() => {
|
||||
messageApi.error("删除失败");
|
||||
|
||||
})
|
||||
|
||||
};
|
||||
|
||||
// 打开权限配置
|
||||
// 权限弹窗
|
||||
const handlePermOpen = () => {
|
||||
if (!selectedRole) {
|
||||
message.warning('请先选择角色');
|
||||
return;
|
||||
}
|
||||
const saved = rolePermissionMap[selectedRole] || [];
|
||||
setCheckedKeys(saved);
|
||||
if (!selectedRole) return messageApi.warning('请选择角色');
|
||||
setCheckedKeys(rolePermissionMap[selectedRole] || []);
|
||||
setPermModal(true);
|
||||
};
|
||||
|
||||
// 保存权限
|
||||
const handlePermSave = () => {
|
||||
rolePermissionMap[selectedRole] = checkedKeys;
|
||||
message.success(`【${selectedRole}】权限保存成功`);
|
||||
messageApi.success(`【${selectedRole}】权限保存成功`);
|
||||
setPermModal(false);
|
||||
};
|
||||
|
||||
// 一级菜单列表(用于父级选择)
|
||||
const topMenus = menus.filter(m => m.parentId === 0);
|
||||
// 上级菜单下拉选项(只展示一级)
|
||||
const topMenus = rawMenuList.filter(m => m.parentId === 0 || !m.parentId);
|
||||
|
||||
const columns = [
|
||||
{ title: '菜单名称', dataIndex: 'title', key: 'title', width: 180 },
|
||||
{ title: '路由地址', dataIndex: 'fullPath', key: 'fullPath' },
|
||||
{
|
||||
title: '菜单名称',
|
||||
dataIndex: 'menuName',
|
||||
key: 'menuName',
|
||||
// 关键:antd 表格自带缩进树形
|
||||
},
|
||||
{ title: '路由地址', dataIndex: 'path', key: 'path' },
|
||||
{ title: '排序', dataIndex: 'orderNum', key: 'orderNum' },
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 220,
|
||||
render: (_, record) => (
|
||||
<Space>
|
||||
<Button type="link" icon={<EditOutlined />} onClick={() => handleEdit(record)}>
|
||||
编辑
|
||||
</Button>
|
||||
<Popconfirm
|
||||
title="确定删除该菜单?"
|
||||
onConfirm={() => handleDelete(record.id)}
|
||||
>
|
||||
<Button type="link" danger icon={<DeleteOutlined />}>
|
||||
删除
|
||||
</Button>
|
||||
<Button type="text" icon={<EditOutlined />} onClick={() => handleEdit(record)}>编辑</Button>
|
||||
<Popconfirm title="确定删除?" onConfirm={() => handleDelete(record.menuId)}>
|
||||
<Button type="text" danger>删除</Button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
),
|
||||
@@ -205,105 +195,84 @@ export default function Roles() {
|
||||
];
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="flex justify-between items-center">
|
||||
<Title level={5} style={{ margin: 0 }}>菜单权限管理</Title>
|
||||
<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>
|
||||
<Button
|
||||
type="primary"
|
||||
icon={<PlusOutlined />}
|
||||
onClick={() => {
|
||||
setEditMenu(null);
|
||||
menuForm.resetFields();
|
||||
setMenuModal(true);
|
||||
}}
|
||||
>
|
||||
新增菜单
|
||||
</Button>
|
||||
</Space>
|
||||
</div>
|
||||
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={menus}
|
||||
rowKey="id"
|
||||
pagination={false}
|
||||
variant
|
||||
/>
|
||||
|
||||
{/* 菜单 新增/编辑 弹窗 */}
|
||||
<Modal
|
||||
title={editMenu ? '编辑菜单' : '新增菜单'}
|
||||
open={menuModal}
|
||||
onCancel={() => setMenuModal(false)}
|
||||
onOk={handleSaveMenu}
|
||||
width={500}
|
||||
>
|
||||
<Form form={menuForm} layout="vertical">
|
||||
<Form.Item name="menuType" label="菜单类型" rules={[{ required: true }]}>
|
||||
<Select placeholder="请选择菜单类型">
|
||||
<Option value="top">一级菜单</Option>
|
||||
<Option value="sub">二级菜单</Option>
|
||||
<div style={{ padding: '20px' }}>
|
||||
{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>
|
||||
</Form.Item>
|
||||
<Button type="primary" icon={<SettingOutlined />} onClick={handlePermOpen}>配置权限</Button>
|
||||
</Space>
|
||||
<Button type="primary" icon={<PlusOutlined />} onClick={() => {
|
||||
setEditMenu(null);
|
||||
menuForm.resetFields();
|
||||
setMenuModal(true);
|
||||
}}>新增菜单</Button>
|
||||
</div>
|
||||
|
||||
{/* 二级菜单才显示父级选择 */}
|
||||
{menuType === 'sub' && (
|
||||
<Form.Item name="parentId" label="上级菜单" rules={[{ required: true }]}>
|
||||
<Select placeholder="请选择上级菜单">
|
||||
{/* 关键:rowKey + treeData + indentSize 开启树形表格 */}
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={menuTreeData}
|
||||
rowKey="menuId"
|
||||
pagination={false}
|
||||
bordered
|
||||
size="middle"
|
||||
indentSize={24}
|
||||
/>
|
||||
|
||||
{/* 新增/编辑弹窗 */}
|
||||
<Modal
|
||||
title={editMenu ? '编辑菜单' : '新增菜单'}
|
||||
open={menuModal}
|
||||
width={600}
|
||||
onCancel={() => setMenuModal(false)}
|
||||
onOk={handleSaveMenu}
|
||||
destroyOnClose
|
||||
>
|
||||
<Form form={menuForm} layout="vertical">
|
||||
<Form.Item label="上级菜单" name="parentId">
|
||||
<Select placeholder="无(一级菜单)">
|
||||
<Option value={0}>无(一级菜单)</Option>
|
||||
{topMenus.map(m => (
|
||||
<Option key={m.id} value={m.id}>{m.title}</Option>
|
||||
<Option key={m.menuId} value={m.menuId}>{m.menuName}</Option>
|
||||
))}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
)}
|
||||
|
||||
<Form.Item name="title" label="菜单名称" rules={[{ required: true }]}>
|
||||
<Input placeholder="请输入菜单名称" />
|
||||
</Form.Item>
|
||||
<Form.Item name="path" label="路由地址" rules={[{ required: true }]}>
|
||||
<Input placeholder="/system/xxx" />
|
||||
</Form.Item>
|
||||
<Form.Item name="sort" label="排序号">
|
||||
<Input type="number" placeholder="数字越小越靠前" />
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
<Form.Item label="菜单名称" name="menuName" rules={[{ required: true }]}>
|
||||
<Input placeholder="请输入菜单名称" />
|
||||
</Form.Item>
|
||||
|
||||
{/* 权限配置弹窗 */}
|
||||
<Modal
|
||||
title={`【${selectedRole}】菜单权限配置`}
|
||||
open={permModal}
|
||||
width={520}
|
||||
onCancel={() => setPermModal(false)}
|
||||
onOk={handlePermSave}
|
||||
>
|
||||
<Tree
|
||||
checkable
|
||||
treeData={menuTree}
|
||||
checkedKeys={checkedKeys}
|
||||
onCheck={setCheckedKeys}
|
||||
defaultExpandAll
|
||||
fieldNames={{ title: 'title', key: 'id', children: 'children' }}
|
||||
/>
|
||||
</Modal>
|
||||
<Form.Item label="路由地址" name="path">
|
||||
<Input placeholder="/system/menu" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="显示排序" name="orderNum">
|
||||
<InputNumber min={0} style={{ width: '100%' }} placeholder="数字越小越靠前" />
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
|
||||
{/* 权限树弹窗 */}
|
||||
<Modal
|
||||
title={`【${selectedRole}】权限配置`}
|
||||
open={permModal}
|
||||
width={520}
|
||||
onCancel={() => setPermModal(false)}
|
||||
onOk={handlePermSave}
|
||||
>
|
||||
<Tree
|
||||
checkable
|
||||
treeData={menuTree}
|
||||
checkedKeys={checkedKeys}
|
||||
onCheck={setCheckedKeys}
|
||||
defaultExpandAll
|
||||
/>
|
||||
</Modal>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import React, { useState } from 'react';
|
||||
import {
|
||||
Card, Row, Col, Button, Typography, Space, Modal, Form, Tree, message,
|
||||
Input, Popconfirm, Divider
|
||||
} from 'antd';
|
||||
import {
|
||||
PlusOutlined, LockOutlined, SettingOutlined, EditOutlined, DeleteOutlined
|
||||
PlusOutlined, SettingOutlined, EditOutlined, DeleteOutlined, CloseOutlined
|
||||
} from '@ant-design/icons';
|
||||
|
||||
const { Text, Title } = Typography;
|
||||
const { Text } = Typography;
|
||||
const AntdCard = Card as any;
|
||||
|
||||
// 默认角色
|
||||
const defaultRoles = [
|
||||
@@ -46,7 +47,7 @@ export default function Roles() {
|
||||
const [editRole, setEditRole] = useState(null);
|
||||
|
||||
// 打开权限配置
|
||||
const handleOpenPerm = async (role) => {
|
||||
const handleOpenPerm = (role) => {
|
||||
setCurrentRole(role);
|
||||
setCheckedKeys([]);
|
||||
setPermVisible(true);
|
||||
@@ -54,7 +55,7 @@ export default function Roles() {
|
||||
|
||||
// 保存权限
|
||||
const handleSavePerm = () => {
|
||||
message.success(`【${currentRole.name}】菜单权限配置成功!`);
|
||||
message.success(`【${currentRole?.name}】菜单权限配置成功!`);
|
||||
setPermVisible(false);
|
||||
};
|
||||
|
||||
@@ -85,16 +86,14 @@ export default function Roles() {
|
||||
roleForm.validateFields().then(values => {
|
||||
const roleData = {
|
||||
...values,
|
||||
menuKeys: checkedKeys, // 保存菜单权限
|
||||
menuKeys: checkedKeys,
|
||||
level: editRole ? editRole.level : 'Level Custom'
|
||||
};
|
||||
|
||||
if (editRole) {
|
||||
// 编辑
|
||||
setRoles(roles.map(r => r.key === editRole.key ? { ...r, ...roleData } : r));
|
||||
message.success('编辑成功');
|
||||
} else {
|
||||
// 新增
|
||||
const newRole = {
|
||||
...roleData,
|
||||
key: values.key || Date.now().toString(),
|
||||
@@ -107,52 +106,76 @@ export default function Roles() {
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="flex justify-between items-center">
|
||||
<Title level={5} style={{ margin: 0 }}>角色管理</Title>
|
||||
<Button type="primary" icon={<PlusOutlined />} onClick={handleAddRole}>
|
||||
新增角色
|
||||
</Button>
|
||||
</div>
|
||||
<div style={{ padding: '16px', background: '#f4f7f9', minHeight: '100%' }}>
|
||||
{/* 标题 */}
|
||||
<div style={{ fontSize: 16, fontWeight: 600, marginBottom: 16 }}>角色管理</div>
|
||||
|
||||
<Row gutter={16}>
|
||||
{/* 顶部操作栏 */}
|
||||
<AntdCard size="small" style={{ borderRadius: 8, marginBottom: 16 }}>
|
||||
<div style={{ display: 'flex', justifyContent: 'flex-end' }}>
|
||||
<Button
|
||||
type="primary"
|
||||
icon={<PlusOutlined />}
|
||||
onClick={handleAddRole}
|
||||
style={{ borderRadius: 2 }}
|
||||
>
|
||||
新增角色
|
||||
</Button>
|
||||
</div>
|
||||
</AntdCard>
|
||||
|
||||
{/* 角色卡片列表 */}
|
||||
<Row gutter={[16, 16]}>
|
||||
{roles.map(role => (
|
||||
<Col span={8} key={role.key}>
|
||||
<Card
|
||||
<Col xs={24} sm={12} md={8} lg={6} key={role.key}>
|
||||
<AntdCard
|
||||
size="small"
|
||||
hoverable
|
||||
style={{ borderRadius: 8, boxShadow: '0 2px 8px rgba(0,0,0,0.06)' }}
|
||||
actions={[
|
||||
<Button
|
||||
type="link"
|
||||
type="text"
|
||||
icon={<SettingOutlined />}
|
||||
onClick={() => handleOpenPerm(role)}
|
||||
style={{ fontSize: 12 }}
|
||||
>
|
||||
菜单权限
|
||||
</Button>,
|
||||
<Button
|
||||
type="link"
|
||||
type="text"
|
||||
icon={<EditOutlined />}
|
||||
onClick={() => handleEditRole(role)}
|
||||
style={{ fontSize: 12 }}
|
||||
>
|
||||
编辑
|
||||
</Button>,
|
||||
<Popconfirm
|
||||
title="确定删除该角色?"
|
||||
onConfirm={() => handleDeleteRole(role.key)}
|
||||
okText="确定"
|
||||
cancelText="取消"
|
||||
>
|
||||
<Button type="link" danger icon={<DeleteOutlined />}>删除</Button>
|
||||
<Button
|
||||
type="text"
|
||||
danger
|
||||
icon={<DeleteOutlined />}
|
||||
style={{ fontSize: 12 }}
|
||||
>
|
||||
删除
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
]}
|
||||
>
|
||||
<Card.Meta
|
||||
title={role.name}
|
||||
title={<span style={{ fontWeight: 600, fontSize: 14 }}>{role.name}</span>}
|
||||
description={
|
||||
<Space direction="vertical" size={2}>
|
||||
<Text type="secondary" style={{ fontSize: 10 }}>{role.level}</Text>
|
||||
<Text type="secondary" style={{ fontSize: 12 }}>{role.desc}</Text>
|
||||
<Space direction="vertical" size={2} style={{ width: '100%' }}>
|
||||
<Text type="secondary" style={{ fontSize: 11 }}>{role.level}</Text>
|
||||
<Text type="secondary" style={{ fontSize: 12, lineHeight: 1.4 }}>{role.desc}</Text>
|
||||
</Space>
|
||||
}
|
||||
/>
|
||||
</Card>
|
||||
</AntdCard>
|
||||
</Col>
|
||||
))}
|
||||
</Row>
|
||||
@@ -164,6 +187,7 @@ export default function Roles() {
|
||||
width={520}
|
||||
onCancel={() => setPermVisible(false)}
|
||||
onOk={handleSavePerm}
|
||||
closeIcon={<CloseOutlined />}
|
||||
>
|
||||
<Tree
|
||||
checkable
|
||||
@@ -174,7 +198,7 @@ export default function Roles() {
|
||||
/>
|
||||
</Modal>
|
||||
|
||||
{/* ========== 新增/编辑角色弹窗(带菜单选择) ========== */}
|
||||
{/* ========== 新增/编辑角色弹窗 ========== */}
|
||||
<Modal
|
||||
title={editRole ? '编辑角色' : '新增角色'}
|
||||
open={roleModalVisible}
|
||||
@@ -182,6 +206,7 @@ export default function Roles() {
|
||||
onOk={handleSaveRole}
|
||||
maskClosable={false}
|
||||
width={550}
|
||||
closeIcon={<CloseOutlined />}
|
||||
>
|
||||
<Form form={roleForm} layout="vertical">
|
||||
<Form.Item
|
||||
@@ -189,7 +214,7 @@ export default function Roles() {
|
||||
label="角色名称"
|
||||
rules={[{ required: true, message: '请输入角色名称' }]}
|
||||
>
|
||||
<Input placeholder="例如:运维管理员" />
|
||||
<Input placeholder="例如:运维管理员" style={{ borderRadius: 2 }} />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
@@ -197,15 +222,14 @@ export default function Roles() {
|
||||
label="角色标识"
|
||||
rules={[{ required: true, message: '请输入角色标识' }]}
|
||||
>
|
||||
<Input placeholder="例如:operation" />
|
||||
<Input placeholder="例如:operation" style={{ borderRadius: 2 }} />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item name="desc" label="角色描述">
|
||||
<Input.TextArea rows={3} placeholder="描述该角色的权限范围" />
|
||||
<Input.TextArea rows={3} placeholder="描述该角色的权限范围" style={{ borderRadius: 2 }} />
|
||||
</Form.Item>
|
||||
|
||||
{/* ========== 新增角色时直接选择菜单权限 ========== */}
|
||||
<Divider orientation="left">菜单权限配置</Divider>
|
||||
<Divider orientation="left" style={{ margin: '16px 0' }}>菜单权限配置</Divider>
|
||||
<Tree
|
||||
checkable
|
||||
treeData={menuTree}
|
||||
|
||||
Reference in New Issue
Block a user