Initial import of weiyuan frontend

This commit is contained in:
qiubaishen
2026-10-15 16:33:46 +08:00
commit d8f3aee261
774 changed files with 374914 additions and 0 deletions
@@ -0,0 +1,236 @@
/*
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 from 'react';
import {
Card,
Grid,
Typography,
Tag,
Progress,
Empty,
Button,
} from '@douyinfe/semi-ui';
import { IconRefresh, IconAlertCircle } from '@douyinfe/semi-icons';
import { useTranslation } from 'react-i18next';
const { Row, Col } = Grid;
const { Title, Text } = Typography;
const ChannelMonitorView = ({ channelStatus, onRefresh }) => {
const { t } = useTranslation();
// 获取状态显示
const getStatusConfig = (status) => {
switch (status) {
case 1: // 在线
return { color: 'green', text: t('可用'), icon: '🟢' };
case 0: // 离线
return { color: 'red', text: t('不可用'), icon: '🔴' };
case 2: // 维护中
return { color: 'orange', text: t('维护中'), icon: '🟡' };
default:
return { color: 'grey', text: t('未知'), icon: '⚪' };
}
};
// 获取响应速度配置
const getSpeedConfig = (responseTime) => {
if (responseTime < 1000) {
return { level: t('快'), color: 'green', percent: 100, bars: '🟩🟩🟩' };
} else if (responseTime < 3000) {
return { level: t('中等'), color: 'yellow', percent: 66, bars: '🟨🟨' };
} else {
return { level: t('慢'), color: 'red', percent: 33, bars: '🟥' };
}
};
// 渲染迷你趋势图 (Sparkline)
const renderSparkline = (uptime) => {
const width = 100;
const height = 30;
const points = 12;
const data = Array.from({ length: points }, (_, i) => {
// 模拟趋势数据,基于uptime生成波动
const baseValue = uptime * 100;
const variance = (Math.random() - 0.5) * 10;
return Math.max(0, Math.min(100, baseValue + variance));
});
const pathData = data
.map((value, index) => {
const x = (index / (points - 1)) * width;
const y = height - (value / 100) * height;
return `${index === 0 ? 'M' : 'L'} ${x},${y}`;
})
.join(' ');
return (
<svg width={width} height={height} style={{ display: 'block' }}>
<path
d={pathData}
fill='none'
stroke={
uptime > 0.9
? 'var(--semi-color-success)'
: uptime > 0.7
? 'var(--semi-color-warning)'
: 'var(--semi-color-danger)'
}
strokeWidth='2'
/>
</svg>
);
};
if (!channelStatus || channelStatus.length === 0) {
return (
<Empty
image={<IconAlertCircle size='extra-large' />}
title={t('暂无渠道数据')}
description={t('请稍后刷新或联系管理员')}
>
<Button icon={<IconRefresh />} onClick={onRefresh}>
{t('刷新数据')}
</Button>
</Empty>
);
}
return (
<div>
{/* 刷新按钮 */}
<div style={{ marginBottom: 16, textAlign: 'right' }}>
<Button icon={<IconRefresh />} onClick={onRefresh}>
{t('刷新')}
</Button>
</div>
{/* 渠道分组展示 */}
{channelStatus.map((group, groupIndex) => (
<div key={groupIndex} style={{ marginBottom: 32 }}>
<Title heading={4} style={{ marginBottom: 16, color: '#1890ff' }}>
📁 {group.categoryName}
</Title>
<Row gutter={[16, 16]}>
{group.monitors &&
group.monitors.map((channel, index) => {
const statusConfig = getStatusConfig(channel.status);
const speedConfig = getSpeedConfig(channel.response_time || 0);
return (
<Col key={index} xs={24} sm={12} md={8} lg={6}>
<Card
title={
<div
style={{
display: 'flex',
alignItems: 'center',
gap: 8,
}}
>
<span style={{ fontSize: 20 }}>
{statusConfig.icon}
</span>
<Text strong>{channel.name}</Text>
</div>
}
headerStyle={{ borderBottom: '2px solid #f0f0f0' }}
bodyStyle={{ padding: 16 }}
style={{
height: '100%',
border: `2px solid ${
channel.status === 1
? '#52c41a20'
: channel.status === 0
? '#f5222d20'
: '#faad1420'
}`,
}}
>
{/* 1. 渠道状态 */}
<div style={{ marginBottom: 16 }}>
<Text type='tertiary' size='small'>
{t('状态')}
</Text>
<div style={{ marginTop: 4 }}>
<Tag color={statusConfig.color} size='large'>
{statusConfig.text}
</Tag>
</div>
</div>
{/* 2. 响应速度 */}
<div style={{ marginBottom: 16 }}>
<div
style={{
display: 'flex',
justifyContent: 'space-between',
marginBottom: 4,
}}
>
<Text type='tertiary' size='small'>
{t('响应速度')}
</Text>
<Text strong size='small'>
{speedConfig.level}
</Text>
</div>
<Progress
percent={speedConfig.percent}
stroke={speedConfig.color}
showInfo={false}
style={{ marginBottom: 4 }}
/>
<Text type='tertiary' size='small'>
{channel.response_time || 0}ms
</Text>
</div>
{/* 3. 稳定性 (Sparkline) */}
<div>
<Text type='tertiary' size='small'>
{t('稳定性趋势 (24h)')}
</Text>
<div
style={{
marginTop: 8,
display: 'flex',
alignItems: 'center',
gap: 8,
}}
>
{renderSparkline(channel.uptime || 0)}
<Text type='success' strong>
{((channel.uptime || 0) * 100).toFixed(1)}%
</Text>
</div>
</div>
</Card>
</Col>
);
})}
</Row>
</div>
))}
</div>
);
};
export default ChannelMonitorView;
+140
View File
@@ -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;