/* Copyright (C) 2025 QuantumNous This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . For commercial licensing, please contact support@quantumnous.com */ import React, { useState, useEffect } from 'react'; import { Layout, Tabs, TabPane, Typography, Spin, Toast, } from '@douyinfe/semi-ui'; import { IconActivity, IconLineChart, IconPulse, } from '@douyinfe/semi-icons'; import { useTranslation } from 'react-i18next'; import { API } from '../../helpers'; import ChannelMonitorView from './components/ChannelMonitorView'; import AdminMonitorView from './components/AdminMonitorView'; const { Content } = Layout; const { Title } = Typography; const Monitoring = () => { const { t } = useTranslation(); const [activeTab, setActiveTab] = useState('channels'); const [loading, setLoading] = useState(false); const [channelStatus, setChannelStatus] = useState([]); const [isAdmin, setIsAdmin] = useState(false); // 检查用户权限 useEffect(() => { const userRole = localStorage.getItem('role'); setIsAdmin(userRole && (userRole === 'admin' || userRole === 'root')); }, []); // 获取渠道状态数据 const fetchChannelStatus = async () => { setLoading(true); try { const res = await API.get('/api/channels/status'); if (res.data.success) { setChannelStatus(res.data.data || []); } else { Toast.error(res.data.message || t('获取渠道状态失败')); } } catch (error) { console.error('Failed to fetch channel status:', error); Toast.error(t('获取渠道状态失败')); } finally { setLoading(false); } }; useEffect(() => { fetchChannelStatus(); // 每30秒刷新一次 const interval = setInterval(fetchChannelStatus, 30000); return () => clearInterval(interval); }, []); return (
<IconPulse style={{ marginRight: 8 }} /> {t('监控中心')}
{/* 页签一:渠道监控 (对所有用户可见) */} {t('渠道监控')} } itemKey='channels' > {/* 页签二:管理监控 (仅对管理员可见) */} {isAdmin && ( {t('管理监控')} } itemKey='admin' > )}
); }; export default Monitoring;