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
+243
View File
@@ -0,0 +1,243 @@
/*
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 '@douyinfe/semi-ui';
import { Iconbolt, IconActivity } from '@douyinfe/semi-icons';
import { useTranslation } from 'react-i18next';
import { API, showError } from '../../helpers';
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(--semi-color-success)'
}
size='small'
style={{ height: 8 }}
showInfo={true}
format={(per) => `${per}%`}
/>
</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(--semi-color-success)' : status === 2 ? 'var(--semi-color-warning)' : 'var(--semi-color-danger)',
boxShadow: `0 0 4px ${status === 1 ? 'var(--semi-color-success)' : status === 2 ? 'var(--semi-color-warning)' : 'var(--semi-color-danger)'}`,
}}
/>
<Text
style={{
color:
status === 1 ? 'var(--semi-color-success)' : status === 2 ? 'var(--semi-color-warning)' : 'var(--semi-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(--semi-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(--semi-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(--semi-color-border)',
}}
bodyStyle={{ 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(--semi-color-border)',
borderRadius: 8,
background: 'var(--semi-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;