Files
monkey-ai-web/src/pages/Status/index.jsx
T
zhanjunhao c492e2b7c0 fix(*): 全量 UI 审查与 undefined 展示异常修复
分析模块:补齐看板、排行、趋势及报表数值兜底
企业与用户中心:修复统计、成员、技能及资金字段展示
充值与交易:修复充值、发票、订单、订阅及支付字段拼接
平台页面:修复渠道、模型、服务监控与状态空值展示
通用能力:新增安全展示工具,补齐九语言文案与回归测试
文档记录:更新修复范围、影响及回滚说明
2026-11-20 10:18:17 +08:00

251 lines
7.8 KiB
React

/*
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, { useEffect, useState } from 'react';
import {
Layout,
Card,
Tag,
Grid,
Typography,
Progress,
Spin,
Empty,
} from '@/components/ui';
import { Iconbolt, IconActivity } from '@/components/ui/icons';
import { useTranslation } from 'react-i18next';
import { API, showError } from '../../helpers';
import { formatPercent } from '../../helpers/safeDisplay';
const { Content } = Layout;
const { Text, Title } = Typography;
const { Row, Col } = Grid;
const Status = () => {
const { t } = useTranslation();
const [loading, setLoading] = useState(true);
const [data, setData] = useState([]);
useEffect(() => {
const fetchData = async () => {
try {
const res = await API.get('/api/channels/status');
const { success, message, data } = res.data;
if (success) {
setData(data);
} else {
showError(message);
}
} catch (error) {
showError(error);
} finally {
setLoading(false);
}
};
fetchData();
}, []);
const renderScore = (uptime) => {
let percent = Math.round(uptime * 100);
let color = 'success';
if (percent < 80) color = 'warning';
if (percent < 50) color = 'danger';
// Segmented bar simulation using multiple small bars or just a styled progress
// Requirement: "Segmented energy bar"
// We can simulate this with a customized progress bar or just standard one for now.
// For "smooth high level line", a high uptime bar looks like a high line.
return (
<div style={{ width: '100%', marginTop: 5 }}>
<Progress
percent={percent}
stroke={
color === 'danger'
? 'red'
: color === 'warning'
? 'orange'
: 'var(--ui-color-success)'
}
size='small'
style={{ height: 8 }}
showInfo={true}
format={(per) => formatPercent(per, 0)}
/>
</div>
);
};
const renderStatus = (status, responseTime) => {
// status: 1=up, 2=maintenance, 0=down
let text = t('Available');
if (status === 2) {
text = t('Maintenance');
} else if (status === 0) {
text = t('Unavailable');
}
return (
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
<div
style={{
width: 8,
height: 8,
borderRadius: '50%',
backgroundColor:
status === 1
? 'var(--ui-color-success)'
: status === 2
? 'var(--ui-color-warning)'
: 'var(--ui-color-danger)',
boxShadow: `0 0 4px ${status === 1 ? 'var(--ui-color-success)' : status === 2 ? 'var(--ui-color-warning)' : 'var(--ui-color-danger)'}`,
}}
/>
<Text
style={{
color:
status === 1
? 'var(--ui-color-success)'
: status === 2
? 'var(--ui-color-warning)'
: 'var(--ui-color-danger)',
}}
>
{text}
</Text>
{/* Fast Indicator */}
{status === 1 && responseTime > 0 && responseTime < 1000 && (
<Tag color='cyan' size='small' prefix={<Iconbolt />}>
{t('Fast')}
</Tag>
)}
</div>
);
};
return (
<Layout style={{ minHeight: '100vh', background: 'var(--ui-color-bg-0)' }}>
<Content style={{ padding: '24px' }}>
<div style={{ maxWidth: 1200, margin: '0 auto' }}>
<div style={{ marginBottom: 24, textAlign: 'center' }}>
<Title heading={2} style={{ marginBottom: 8 }}>
<IconActivity
style={{
marginRight: 12,
fontSize: 28,
verticalAlign: 'middle',
}}
/>
{t('System Status Monitor')}
</Title>
<Text type='secondary'>
{t('Real-time monitoring of all available services')}
</Text>
</div>
{loading ? (
<div style={{ textAlign: 'center', padding: 40 }}>
<Spin size='large' />
</div>
) : data.length === 0 ? (
<Empty
image={
<IconActivity
style={{ fontSize: 48, color: 'var(--ui-color-text-2)' }}
/>
}
description={t('No data available')}
/>
) : (
data.map((group, gIndex) => (
<Card
key={gIndex}
title={group.categoryName}
style={{
marginBottom: 24,
borderRadius: 12,
boxShadow: '0 4px 12px rgba(0,0,0,0.05)',
}}
headerStyle={{
borderBottom: '1px solid var(--ui-color-border)',
}}
styles={{ body: { padding: '20px' } }}
>
<Row gutter={[16, 16]}>
{group.monitors.map((item, mIndex) => (
<Col span={24} md={12} lg={8} key={mIndex}>
<div
style={{
padding: 16,
border: '1px solid var(--ui-color-border)',
borderRadius: 8,
background: 'var(--ui-color-bg-1)',
transition: 'all 0.3s',
height: '100%',
':hover': {
boxShadow: '0 4px 12px rgba(0,0,0,0.08)',
},
}}
>
<div
style={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
marginBottom: 12,
}}
>
<Text strong size='large' style={{ fontSize: 16 }}>
{item.name}
</Text>
{/* Optional: Add latency text if needed */}
</div>
<div style={{ marginBottom: 12 }}>
{renderStatus(item.status, item.response_time)}
</div>
{/* Energy Bar / Uptime Bar */}
{renderScore(item.uptime)}
{item.response_time > 0 && (
<Text
type='tertiary'
size='small'
style={{ marginTop: 8, display: 'block' }}
>
{t('Response')}: {item.response_time}ms
</Text>
)}
</div>
</Col>
))}
</Row>
</Card>
))
)}
</div>
</Content>
</Layout>
);
};
export default Status;