Initial import of weiyuan frontend
This commit is contained in:
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
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 || '获取渠道状态失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch channel status:', error);
|
||||
Toast.error('获取渠道状态失败');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchChannelStatus();
|
||||
// 每30秒刷新一次
|
||||
const interval = setInterval(fetchChannelStatus, 30000);
|
||||
return () => clearInterval(interval);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Layout>
|
||||
<Content style={{ padding: '24px' }}>
|
||||
<div
|
||||
style={{
|
||||
marginBottom: 24,
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'space-between',
|
||||
}}
|
||||
>
|
||||
<Title heading={2} style={{ margin: 0 }}>
|
||||
<IconPulse style={{ marginRight: 8 }} />
|
||||
{t('监控中心')}
|
||||
</Title>
|
||||
</div>
|
||||
|
||||
<Tabs
|
||||
type='line'
|
||||
activeKey={activeTab}
|
||||
onChange={setActiveTab}
|
||||
style={{ marginTop: 16 }}
|
||||
>
|
||||
{/* 页签一:渠道监控 (对所有用户可见) */}
|
||||
<TabPane
|
||||
tab={
|
||||
<span>
|
||||
<IconActivity style={{ marginRight: 4 }} />
|
||||
{t('渠道监控')}
|
||||
</span>
|
||||
}
|
||||
itemKey='channels'
|
||||
>
|
||||
<Spin spinning={loading}>
|
||||
<ChannelMonitorView
|
||||
channelStatus={channelStatus}
|
||||
onRefresh={fetchChannelStatus}
|
||||
/>
|
||||
</Spin>
|
||||
</TabPane>
|
||||
|
||||
{/* 页签二:管理监控 (仅对管理员可见) */}
|
||||
{isAdmin && (
|
||||
<TabPane
|
||||
tab={
|
||||
<span>
|
||||
<IconLineChart style={{ marginRight: 4 }} />
|
||||
{t('管理监控')}
|
||||
</span>
|
||||
}
|
||||
itemKey='admin'
|
||||
>
|
||||
<AdminMonitorView />
|
||||
</TabPane>
|
||||
)}
|
||||
</Tabs>
|
||||
</Content>
|
||||
</Layout>
|
||||
);
|
||||
};
|
||||
|
||||
export default Monitoring;
|
||||
Reference in New Issue
Block a user