feat: 参考原型图 ui优化提交 个人端-用户中心 相关的页面

This commit is contained in:
zhanjunhao
2026-11-04 19:59:06 +08:00
parent 1fd4e084b6
commit 15192c433b
576 changed files with 18075 additions and 18912 deletions
+95 -145
View File
@@ -25,22 +25,17 @@ import {
Button,
Modal,
Tooltip,
} from '@douyinfe/semi-ui';
import {
Activity,
RefreshCw,
Server,
ChevronRight,
Zap,
Clock,
TrendingUp,
} from 'lucide-react';
Statistic,
theme,
} from 'antd';
import { RefreshCw, Server, ChevronRight, Zap, Clock } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { API, showError } from '../../helpers';
import { isAdmin } from '../../helpers/utils';
// 条形码状态组件 - 美化版
const StatusBars = ({ dataPoints = [], loading = false, t }) => {
const { token } = theme.useToken();
// 补全或截取数据以适应展示 (展示最近60个点)
// 注意:useMemo 必须在任何 early return 之前调用,保证 hook 调用顺序稳定。
const displayCount = 60;
@@ -63,7 +58,7 @@ const StatusBars = ({ dataPoints = [], loading = false, t }) => {
{Array.from({ length: 60 }).map((_, i) => (
<div
key={i}
className='w-[6px] h-4 bg-gray-200 dark:bg-gray-700 rounded-sm'
className='service-history-loading w-[6px] h-4 rounded-sm'
/>
))}
</div>
@@ -78,7 +73,7 @@ const StatusBars = ({ dataPoints = [], loading = false, t }) => {
return (
<div
key={i}
className='w-[6px] h-2 bg-gray-100 dark:bg-gray-800 rounded-sm'
className='service-history-pending w-[6px] h-2 rounded-sm'
/>
);
}
@@ -87,14 +82,11 @@ const StatusBars = ({ dataPoints = [], loading = false, t }) => {
const isWarning =
point.uptime_percent >= 50 && point.uptime_percent < 90;
let bgColor = '#ef4444'; // red-500
let glowColor = 'rgba(239, 68, 68, 0.3)';
let bgColor = token.colorError;
if (isHealthy) {
bgColor = '#10b981'; // emerald-500
glowColor = 'rgba(16, 185, 129, 0.3)';
bgColor = token.colorPrimary;
} else if (isWarning) {
bgColor = '#f59e0b'; // amber-500
glowColor = 'rgba(245, 158, 11, 0.3)';
bgColor = token.colorWarning;
}
const height = isHealthy ? '20px' : '16px';
@@ -102,7 +94,7 @@ const StatusBars = ({ dataPoints = [], loading = false, t }) => {
return (
<Tooltip
key={i}
content={
title={
<div className='text-xs p-1'>
<div style={{ color: bgColor }} className='font-semibold'>
{isHealthy ? t('正常') : t('异常')} (
@@ -117,11 +109,10 @@ const StatusBars = ({ dataPoints = [], loading = false, t }) => {
}
>
<div
className='w-[6px] rounded-sm transition-all duration-200 hover:scale-y-125 hover:opacity-80 cursor-pointer'
className={`w-[6px] rounded-sm hover:opacity-80 cursor-pointer ${isHealthy ? 'service-history-healthy' : ''}`}
style={{
backgroundColor: bgColor,
height: height,
boxShadow: `0 0 6px ${glowColor}`,
}}
/>
</Tooltip>
@@ -138,6 +129,7 @@ const StatusBars = ({ dataPoints = [], loading = false, t }) => {
// 模型测试单元格组件
const TestModelCell = ({ modelName, groupName, t }) => {
const { token } = theme.useToken();
const [testing, setTesting] = useState(false);
const [result, setResult] = useState(null);
@@ -182,30 +174,31 @@ const TestModelCell = ({ modelName, groupName, t }) => {
return (
<div className='flex items-center gap-3'>
<Button
size='small'
type='tertiary'
theme='light'
loading={testing}
onClick={handleTest}
className='!bg-gradient-to-r !from-emerald-50 !to-teal-50 !border !border-emerald-200 hover:!border-emerald-300 !rounded-lg'
style={{ color: '#047857' }}
>
<Zap size={12} className='mr-1' style={{ color: '#047857' }} />
<Button size='small' loading={testing} onClick={handleTest}>
<Zap size={12} className='mr-1' />
{testing ? t('测试中') : t('测试')}
</Button>
{result && (
<span
className={`text-xs font-medium ${result.success ? 'text-emerald-600 dark:text-emerald-400' : 'text-red-500 dark:text-red-400'}`}
className='text-xs font-medium'
style={{
color: result.success ? token.colorPrimary : token.colorError,
}}
>
{result.success ? (
<span className='flex items-center gap-1 px-2 py-0.5 bg-emerald-50 dark:bg-emerald-900/30 rounded-full'>
<span
className='flex items-center gap-1 px-2 py-0.5 rounded-full'
style={{ background: token.colorPrimaryBg }}
>
<span>✓</span>
<span>{result.time}ms</span>
</span>
) : (
<Tooltip content={result.error}>
<span className='flex items-center gap-1 px-2 py-0.5 bg-red-50 dark:bg-red-900/30 rounded-full cursor-help'>
<Tooltip title={result.error}>
<span
className='flex items-center gap-1 px-2 py-0.5 rounded-full cursor-help'
style={{ background: token.colorErrorBg }}
>
<span>✗</span>
{result.time > 0 && <span>{result.time}ms</span>}
</span>
@@ -219,6 +212,7 @@ const TestModelCell = ({ modelName, groupName, t }) => {
const GroupMonitor = () => {
const { t } = useTranslation();
const { token } = theme.useToken();
const [groups, setGroups] = useState([]);
const [loading, setLoading] = useState(true);
const [refreshing, setRefreshing] = useState(false);
@@ -313,18 +307,21 @@ const GroupMonitor = () => {
setSelectedGroup(null);
};
const getUptimeColor = (uptime) => {
const val = Number(uptime) || 0;
if (val >= 95) return '#10b981';
if (val >= 80) return '#f59e0b';
return '#ef4444';
};
const getUptimeColor = useCallback(
(uptime) => {
const val = Number(uptime) || 0;
if (val >= 95) return token.colorPrimary;
if (val >= 80) return token.colorWarning;
return token.colorError;
},
[token.colorPrimary, token.colorWarning, token.colorError],
);
const getUptimeGradient = (uptime) => {
const getUptimeClass = (uptime) => {
const val = Number(uptime) || 0;
if (val >= 95) return 'from-emerald-500 to-teal-500';
if (val >= 80) return 'from-amber-500 to-orange-500';
return 'from-red-500 to-rose-500';
if (val >= 95) return 'service-status-normal';
if (val >= 80) return 'service-status-warning';
return 'service-status-error';
};
const modelColumns = useMemo(
@@ -335,7 +332,10 @@ const GroupMonitor = () => {
key: 'model',
render: (text) => (
<div className='font-medium text-gray-700 dark:text-gray-200 flex items-center gap-2'>
<div className='w-2 h-2 rounded-full bg-gradient-to-r from-emerald-400 to-teal-400' />
<div
className='w-2 h-2 rounded-full'
style={{ background: token.colorPrimary }}
/>
{text}
</div>
),
@@ -348,8 +348,11 @@ const GroupMonitor = () => {
<div className='flex items-center gap-2'>
<div className='w-16 h-1.5 bg-gray-100 dark:bg-gray-700 rounded-full overflow-hidden'>
<div
className={`h-full rounded-full bg-gradient-to-r ${getUptimeGradient(value)}`}
style={{ width: `${Math.min(100, value || 0)}%` }}
className='h-full rounded-full'
style={{
width: `${Math.min(100, value || 0)}%`,
backgroundColor: getUptimeColor(value),
}}
/>
</div>
<span
@@ -367,7 +370,7 @@ const GroupMonitor = () => {
key: 'count',
render: (_, record) => (
<span className='text-gray-600 dark:text-gray-300 font-medium'>
<span className='text-emerald-600 dark:text-emerald-400'>
<span style={{ color: token.colorPrimary }}>
{record.available_count}
</span>
<span className='text-gray-300 dark:text-gray-600 mx-1'>/</span>
@@ -407,7 +410,7 @@ const GroupMonitor = () => {
),
},
],
[t, selectedGroup],
[t, selectedGroup, getUptimeColor, token.colorPrimary],
);
const modalDataSource = useMemo(() => {
@@ -431,7 +434,6 @@ const GroupMonitor = () => {
return (
<div className='flex flex-col items-center justify-center py-20'>
<div className='relative'>
<div className='absolute inset-0 bg-emerald-400/30 rounded-full blur-xl animate-pulse' />
<Spin size='large' />
</div>
<p className='mt-4 text-gray-500 dark:text-gray-400'>
@@ -463,12 +465,12 @@ const GroupMonitor = () => {
return (
<div
key={group.name}
className={`group relative bg-white/70 dark:bg-gray-800/70 backdrop-blur-sm rounded-xl border border-gray-100 dark:border-gray-700/50 transition-all duration-300 overflow-hidden ${adminUser ? 'hover:border-emerald-200 dark:hover:border-emerald-700/50 hover:shadow-lg hover:shadow-emerald-500/5 cursor-pointer' : ''}`}
className={`service-group-row group relative rounded-xl border overflow-hidden ${adminUser ? 'service-group-interactive cursor-pointer' : ''}`}
onClick={adminUser ? () => handleGroupClick(group) : undefined}
>
{/* 左侧状态指示条 */}
<div
className={`absolute left-0 top-0 bottom-0 w-1 bg-gradient-to-b ${getUptimeGradient(uptimePercent)}`}
className={`service-group-marker absolute left-0 top-0 bottom-0 w-1 ${getUptimeClass(uptimePercent)}`}
/>
{/* 桌面端布局 */}
@@ -477,13 +479,13 @@ const GroupMonitor = () => {
<div className='w-[180px] shrink-0 pr-4'>
<div className='flex items-center gap-3'>
<div
className={`w-10 h-10 rounded-xl bg-gradient-to-br ${getUptimeGradient(uptimePercent)} flex items-center justify-center shadow-lg`}
className={`service-status-icon w-10 h-10 rounded-xl ${getUptimeClass(uptimePercent)} flex items-center justify-center`}
>
<Server className='w-5 h-5 text-white' />
<Server className='w-5 h-5' />
</div>
<div className='min-w-0'>
<div
className='text-base font-bold text-gray-800 dark:text-gray-100 truncate group-hover:text-emerald-600 dark:group-hover:text-emerald-400 transition-colors'
className='text-base font-bold text-gray-800 dark:text-gray-100 truncate'
title={group.name}
>
{group.name}
@@ -499,13 +501,10 @@ const GroupMonitor = () => {
<div className='w-[120px] shrink-0 flex justify-center'>
<div className='relative'>
<div
className={`px-4 py-2 rounded-xl text-white text-sm font-bold shadow-lg bg-gradient-to-r ${getUptimeGradient(uptimePercent)}`}
className={`service-uptime-badge px-4 py-2 rounded-xl text-sm font-bold ${getUptimeClass(uptimePercent)}`}
>
{uptimePercent.toFixed(2)}%
</div>
{uptimePercent >= 95 && (
<div className='absolute -top-1 -right-1 w-3 h-3 bg-yellow-400 rounded-full animate-pulse shadow-lg' />
)}
</div>
</div>
@@ -541,8 +540,8 @@ const GroupMonitor = () => {
{/* 查看按钮 - 仅管理员可见 */}
{adminUser && (
<div className='w-[100px] shrink-0 flex justify-end'>
<button
className='flex items-center gap-1.5 px-4 py-2 text-sm font-medium text-emerald-600 dark:text-emerald-400 bg-emerald-50 dark:bg-emerald-900/30 hover:bg-emerald-100 dark:hover:bg-emerald-900/50 rounded-lg transition-all group-hover:translate-x-1'
<Button
className='service-group-details'
onClick={(e) => {
e.stopPropagation();
handleGroupClick(group);
@@ -553,7 +552,7 @@ const GroupMonitor = () => {
size={16}
className='transition-transform group-hover:translate-x-0.5'
/>
</button>
</Button>
</div>
)}
</div>
@@ -563,9 +562,9 @@ const GroupMonitor = () => {
<div className='flex items-center justify-between'>
<div className='flex items-center gap-3 min-w-0 flex-1'>
<div
className={`w-9 h-9 shrink-0 rounded-lg bg-gradient-to-br ${getUptimeGradient(uptimePercent)} flex items-center justify-center shadow-md`}
className={`service-status-icon w-9 h-9 shrink-0 rounded-lg ${getUptimeClass(uptimePercent)} flex items-center justify-center`}
>
<Server className='w-4 h-4 text-white' />
<Server className='w-4 h-4' />
</div>
<div className='min-w-0'>
<div
@@ -582,7 +581,7 @@ const GroupMonitor = () => {
<div className='flex items-center gap-3 shrink-0'>
<div className='relative'>
<div
className={`px-3 py-1.5 rounded-lg text-white text-xs font-bold shadow-md bg-gradient-to-r ${getUptimeGradient(uptimePercent)}`}
className={`service-uptime-badge px-3 py-1.5 rounded-lg text-xs font-bold ${getUptimeClass(uptimePercent)}`}
>
{uptimePercent.toFixed(2)}%
</div>
@@ -627,7 +626,7 @@ const GroupMonitor = () => {
{/* 刷新信息 */}
{lastUpdateTime && (
<div className='mt-8 flex flex-col items-center justify-center gap-3'>
<div className='flex items-center gap-4 px-6 py-3 bg-white/50 dark:bg-gray-800/50 backdrop-blur-sm rounded-full border border-gray-100 dark:border-gray-700/50'>
<div className='service-refresh-info flex items-center gap-4 px-6 py-3 bg-white/50 dark:bg-gray-800/50 backdrop-blur-sm rounded-full border border-gray-100 dark:border-gray-700/50'>
<div className='flex items-center gap-2 text-gray-500 dark:text-gray-400 text-sm'>
<Clock size={14} />
<span>
@@ -635,7 +634,7 @@ const GroupMonitor = () => {
</span>
</div>
<div className='w-px h-4 bg-gray-200 dark:bg-gray-700' />
<div className='flex items-center gap-2 text-emerald-600 dark:text-emerald-400 text-sm font-medium'>
<div className='service-refresh-countdown flex items-center gap-2 text-sm font-medium'>
<div className='relative'>
<svg
className='w-5 h-5 transform -rotate-90'
@@ -684,9 +683,8 @@ const GroupMonitor = () => {
}
onClick={() => fetchGroupData(true)}
loading={refreshing}
type='tertiary'
theme='borderless'
className='!text-gray-500 hover:!text-emerald-600 dark:!text-gray-400 dark:hover:!text-emerald-400'
type='text'
className='service-refresh-button'
>
{t('立即刷新')}
</Button>
@@ -695,89 +693,41 @@ const GroupMonitor = () => {
{/* 详情弹窗 */}
<Modal
visible={modalVisible}
open={modalVisible}
onCancel={handleCloseModal}
afterClose={handleAfterClose}
footer={null}
width={950}
title={null}
bodyStyle={{ padding: '0' }}
title={selectedGroup?.name}
centered
className='group-monitor-modal'
>
{selectedGroup && (
<div className='bg-gradient-to-br from-white to-gray-50/50 dark:from-gray-800 dark:to-gray-900/50 rounded-xl overflow-hidden'>
{/* Header */}
<div className='relative px-8 py-8 border-b border-gray-100 dark:border-gray-700 overflow-hidden'>
{/* 装饰背景 */}
<div className='absolute inset-0 bg-gradient-to-r from-emerald-500/5 via-teal-500/5 to-cyan-500/5' />
<div className='absolute top-0 right-0 w-64 h-64 bg-gradient-to-br from-emerald-400/10 to-transparent rounded-full blur-3xl' />
<div className='relative flex items-center justify-between'>
<div className='flex items-center gap-5'>
<div className='relative group'>
<div className='absolute inset-0 bg-gradient-to-br from-emerald-500 to-teal-600 rounded-2xl blur-lg opacity-50' />
<div
className={`relative w-16 h-16 rounded-2xl bg-gradient-to-br ${getUptimeGradient(selectedGroup.uptime_percent)} flex items-center justify-center shadow-xl`}
>
<Server className='w-8 h-8 text-white' />
</div>
</div>
<div>
<h2 className='text-2xl font-bold text-gray-900 dark:text-white'>
{selectedGroup.name}
</h2>
<div className='text-gray-500 dark:text-gray-400 text-sm mt-1 flex items-center gap-2'>
<Activity size={14} />
{t('分组监控详情')}
</div>
</div>
</div>
<div className='flex gap-4'>
<div className='px-6 py-4 bg-white/80 dark:bg-gray-800/80 backdrop-blur-sm rounded-2xl border border-gray-100 dark:border-gray-700 shadow-lg min-w-[120px]'>
<div className='flex items-center gap-1.5 text-xs text-gray-500 dark:text-gray-400 mb-2'>
<TrendingUp size={12} />
{t('可用率')}
</div>
<div
className={`text-2xl font-bold bg-clip-text text-transparent bg-gradient-to-r ${getUptimeGradient(selectedGroup.uptime_percent)}`}
>
{(selectedGroup.uptime_percent || 0).toFixed(2)}%
</div>
</div>
<div className='px-6 py-4 bg-white/80 dark:bg-gray-800/80 backdrop-blur-sm rounded-2xl border border-gray-100 dark:border-gray-700 shadow-lg min-w-[120px]'>
<div className='flex items-center gap-1.5 text-xs text-gray-500 dark:text-gray-400 mb-2'>
<Server size={12} />
{t('模型数量')}
</div>
<div className='text-2xl font-bold text-gray-800 dark:text-white'>
{selectedGroup.models?.length || 0}
</div>
</div>
</div>
</div>
<>
<div className='service-monitor-details'>
<Statistic
title={t('可用率')}
value={selectedGroup.uptime_percent || 0}
precision={2}
suffix='%'
/>
<Statistic
title={t('模型数量')}
value={selectedGroup.models?.length || 0}
/>
</div>
{/* Table Content */}
<div className='p-6 sm:p-8'>
<div className='bg-white dark:bg-gray-800 rounded-xl border border-gray-100 dark:border-gray-700 shadow-sm overflow-hidden'>
<Table
columns={modelColumns}
dataSource={modalDataSource}
pagination={modalPagination}
size='middle'
rowKey='model'
emptyText={
<Empty
description={t('暂无模型数据')}
imageStyle={{ height: 48 }}
/>
}
/>
</div>
</div>
</div>
<Table
columns={modelColumns}
dataSource={modalDataSource}
pagination={modalPagination}
size='middle'
rowKey='model'
scroll={{ x: 680 }}
locale={{
emptyText: <Empty description={t('暂无模型数据')} />,
}}
/>
</>
)}
</Modal>
</div>