Initial import of weiyuan frontend
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
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, Tag, Timeline, Empty } from '@douyinfe/semi-ui';
|
||||
import { Bell } from 'lucide-react';
|
||||
import { marked } from 'marked';
|
||||
import {
|
||||
IllustrationConstruction,
|
||||
IllustrationConstructionDark,
|
||||
} from '../common/illustrations';
|
||||
import ScrollableContainer from '../common/ui/ScrollableContainer';
|
||||
|
||||
const AnnouncementsPanel = ({
|
||||
announcementData,
|
||||
announcementLegendData,
|
||||
CARD_PROPS,
|
||||
ILLUSTRATION_SIZE,
|
||||
t,
|
||||
}) => {
|
||||
return (
|
||||
<Card
|
||||
{...CARD_PROPS}
|
||||
className='shadow-sm !rounded-2xl lg:col-span-2'
|
||||
title={
|
||||
<div className='flex flex-col lg:flex-row lg:items-center lg:justify-between gap-2 w-full'>
|
||||
<div className='flex items-center gap-2'>
|
||||
<Bell size={16} />
|
||||
{t('系统公告')}
|
||||
<Tag color='white' shape='circle'>
|
||||
{t('显示最新20条')}
|
||||
</Tag>
|
||||
</div>
|
||||
{/* 图例 */}
|
||||
<div className='flex flex-wrap gap-3 text-xs'>
|
||||
{announcementLegendData.map((legend, index) => (
|
||||
<div key={index} className='flex items-center gap-1'>
|
||||
<div
|
||||
className='w-2 h-2 rounded-full'
|
||||
style={{
|
||||
backgroundColor:
|
||||
legend.color === 'grey'
|
||||
? '#8b9aa7'
|
||||
: legend.color === 'blue'
|
||||
? '#3b82f6'
|
||||
: legend.color === 'green'
|
||||
? '#10b981'
|
||||
: legend.color === 'orange'
|
||||
? '#f59e0b'
|
||||
: legend.color === 'red'
|
||||
? '#ef4444'
|
||||
: '#8b9aa7',
|
||||
}}
|
||||
/>
|
||||
<span className='text-gray-600'>{legend.label}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
bodyStyle={{ padding: 0 }}
|
||||
>
|
||||
<ScrollableContainer maxHeight='24rem'>
|
||||
{announcementData.length > 0 ? (
|
||||
<Timeline mode='left'>
|
||||
{announcementData.map((item, idx) => {
|
||||
const htmlExtra = item.extra ? marked.parse(item.extra) : '';
|
||||
return (
|
||||
<Timeline.Item
|
||||
key={idx}
|
||||
type={item.type || 'default'}
|
||||
time={`${item.relative ? item.relative + ' ' : ''}${item.time}`}
|
||||
extra={
|
||||
item.extra ? (
|
||||
<div
|
||||
className='text-xs text-gray-500'
|
||||
dangerouslySetInnerHTML={{ __html: htmlExtra }}
|
||||
/>
|
||||
) : null
|
||||
}
|
||||
>
|
||||
<div>
|
||||
<div
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: marked.parse(item.content || ''),
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</Timeline.Item>
|
||||
);
|
||||
})}
|
||||
</Timeline>
|
||||
) : (
|
||||
<div className='flex justify-center items-center py-8'>
|
||||
<Empty
|
||||
image={<IllustrationConstruction style={ILLUSTRATION_SIZE} />}
|
||||
darkModeImage={
|
||||
<IllustrationConstructionDark style={ILLUSTRATION_SIZE} />
|
||||
}
|
||||
title={t('暂无系统公告')}
|
||||
description={t('请联系管理员在系统设置中配置公告信息')}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</ScrollableContainer>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default AnnouncementsPanel;
|
||||
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
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, Avatar, Tag, Divider, Empty } from '@douyinfe/semi-ui';
|
||||
import { Server, Gauge, ExternalLink } from 'lucide-react';
|
||||
import {
|
||||
IllustrationConstruction,
|
||||
IllustrationConstructionDark,
|
||||
} from '../common/illustrations';
|
||||
import ScrollableContainer from '../common/ui/ScrollableContainer';
|
||||
|
||||
const ApiInfoPanel = ({
|
||||
apiInfoData,
|
||||
handleCopyUrl,
|
||||
handleSpeedTest,
|
||||
CARD_PROPS,
|
||||
FLEX_CENTER_GAP2,
|
||||
ILLUSTRATION_SIZE,
|
||||
t,
|
||||
}) => {
|
||||
return (
|
||||
<Card
|
||||
{...CARD_PROPS}
|
||||
className='bg-gray-50 border-0 !rounded-2xl'
|
||||
title={
|
||||
<div className={FLEX_CENTER_GAP2}>
|
||||
<Server size={16} />
|
||||
{t('API信息')}
|
||||
</div>
|
||||
}
|
||||
bodyStyle={{ padding: 0 }}
|
||||
>
|
||||
<ScrollableContainer maxHeight='24rem'>
|
||||
{apiInfoData.length > 0 ? (
|
||||
apiInfoData.map((api) => (
|
||||
<React.Fragment key={api.id}>
|
||||
<div className='flex p-2 hover:bg-white rounded-lg transition-colors cursor-pointer'>
|
||||
<div className='flex-shrink-0 mr-3'>
|
||||
<Avatar size='extra-small' color={api.color}>
|
||||
{api.route.substring(0, 2)}
|
||||
</Avatar>
|
||||
</div>
|
||||
<div className='flex-1'>
|
||||
<div className='flex flex-wrap items-center justify-between mb-1 w-full gap-2'>
|
||||
<span className='text-sm font-medium text-gray-900 !font-bold break-all'>
|
||||
{api.route}
|
||||
</span>
|
||||
<div className='flex items-center gap-1 mt-1 lg:mt-0'>
|
||||
<Tag
|
||||
prefixIcon={<Gauge size={12} />}
|
||||
size='small'
|
||||
color='white'
|
||||
shape='circle'
|
||||
onClick={() => handleSpeedTest(api.url)}
|
||||
className='cursor-pointer hover:opacity-80 text-xs'
|
||||
>
|
||||
{t('测速')}
|
||||
</Tag>
|
||||
<Tag
|
||||
prefixIcon={<ExternalLink size={12} />}
|
||||
size='small'
|
||||
color='white'
|
||||
shape='circle'
|
||||
onClick={() =>
|
||||
window.open(api.url, '_blank', 'noopener,noreferrer')
|
||||
}
|
||||
className='cursor-pointer hover:opacity-80 text-xs'
|
||||
>
|
||||
{t('跳转')}
|
||||
</Tag>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
className='!text-semi-color-primary break-all cursor-pointer hover:underline mb-1'
|
||||
onClick={() => handleCopyUrl(api.url)}
|
||||
>
|
||||
{api.url}
|
||||
</div>
|
||||
<div className='text-gray-500'>{api.description}</div>
|
||||
</div>
|
||||
</div>
|
||||
<Divider />
|
||||
</React.Fragment>
|
||||
))
|
||||
) : (
|
||||
<div className='flex justify-center items-center min-h-[20rem] w-full'>
|
||||
<Empty
|
||||
image={<IllustrationConstruction style={ILLUSTRATION_SIZE} />}
|
||||
darkModeImage={
|
||||
<IllustrationConstructionDark style={ILLUSTRATION_SIZE} />
|
||||
}
|
||||
title={t('暂无API信息')}
|
||||
description={t('请联系管理员在系统设置中配置API信息')}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</ScrollableContainer>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default ApiInfoPanel;
|
||||
@@ -0,0 +1,339 @@
|
||||
/*
|
||||
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, { useMemo } from 'react';
|
||||
import { AreaChart, Trophy } from 'lucide-react';
|
||||
import { VChart } from '@visactor/react-vchart';
|
||||
import { useIsMobile } from '../../hooks/common/useIsMobile';
|
||||
|
||||
// 手机屏幕下的 VChart 渲染模式:桌面模式下 tooltip 依赖 hover,触屏点不出来
|
||||
const MOBILE_CHART_CONFIG = { mode: 'mobile-browser' };
|
||||
|
||||
// 手机端最多展示前 N 个模型,超出的合并成「其他」,避免图例和榜单被几十个模型撑爆
|
||||
const MOBILE_MAX_SERIES = 5;
|
||||
|
||||
// 轴标签在窄屏上截断,完整名称仍可在 tooltip 中看到
|
||||
const truncateLabel = (text, max = 12) => {
|
||||
const str = String(text ?? '');
|
||||
return str.length > max ? `${str.slice(0, max)}…` : str;
|
||||
};
|
||||
|
||||
/**
|
||||
* 把桌面版 spec 改写成手机可读的版本。
|
||||
*
|
||||
* 窄屏下的两个致命问题:
|
||||
* 1) 图例 orient:'right' 会横向吃掉一大半宽度,折线被压成一条竖带;
|
||||
* 2) 图内标题与卡片头部标题重复,白白占用本就紧张的高度。
|
||||
* 因此手机端把图例挪到底部并限制行数(多余的走翻页器),同时隐藏图内标题,
|
||||
* 「总计」改由卡片头部承载(见下方 totalText)。
|
||||
*/
|
||||
const toMobileSpec = (spec) => {
|
||||
if (!spec) return spec;
|
||||
|
||||
const next = {
|
||||
...spec,
|
||||
// 图内标题在手机端隐藏,信息由卡片头部承担
|
||||
title: { ...(spec.title || {}), visible: false },
|
||||
padding: { top: 4, right: 8, bottom: 4, left: 4 },
|
||||
};
|
||||
|
||||
if (spec.legends && spec.legends.visible !== false) {
|
||||
next.legends = {
|
||||
...spec.legends,
|
||||
orient: 'bottom',
|
||||
position: 'start',
|
||||
padding: { top: 8, left: 0, right: 0, bottom: 0 },
|
||||
maxRow: 2,
|
||||
pager: {
|
||||
textStyle: { fontSize: 10 },
|
||||
space: 4,
|
||||
},
|
||||
item: {
|
||||
...(spec.legends.item || {}),
|
||||
padding: { top: 2, bottom: 2, left: 0, right: 10 },
|
||||
shape: {
|
||||
...(spec.legends.item?.shape || {}),
|
||||
style: {
|
||||
...(spec.legends.item?.shape?.style || {}),
|
||||
symbolType: 'circle',
|
||||
size: 7,
|
||||
},
|
||||
},
|
||||
label: {
|
||||
...(spec.legends.item?.label || {}),
|
||||
style: {
|
||||
...(spec.legends.item?.label?.style || {}),
|
||||
fontSize: 10,
|
||||
},
|
||||
},
|
||||
// 长模型名(如 dreamina-seedance-2-0-260128)在窄屏必须截断,否则一条就占满一行
|
||||
maxWidth: 108,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
if (Array.isArray(spec.axes)) {
|
||||
next.axes = spec.axes.map((axis) => {
|
||||
if (!axis || axis.visible === false) return axis;
|
||||
const label = axis.label || {};
|
||||
return {
|
||||
...axis,
|
||||
label: {
|
||||
...label,
|
||||
style: { ...(label.style || {}), fontSize: 9 },
|
||||
// 横向柱状榜单的左轴是模型名,需要截断
|
||||
...(axis.orient === 'left' && spec.direction === 'horizontal'
|
||||
? { formatMethod: (text) => truncateLabel(text) }
|
||||
: {}),
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
return next;
|
||||
};
|
||||
|
||||
/**
|
||||
* 手机端裁剪数据系列:只保留支出/调用量最高的前 N 个,其余合并为「其他」。
|
||||
*
|
||||
* - groupField:系列字段(模型名)
|
||||
* - valueField:排序与求和用的数值字段
|
||||
* - bucketField:折叠后按哪个维度分桶。走势图按时间点分桶(每个时间点一条「其他」),
|
||||
* 榜单没有第二维度,传 null 表示所有被折叠的系列合并成唯一一条。
|
||||
* 注意不要拿 spec.xField 推断——横向柱图的 xField 是度量而非维度,会导致「其他」被拆成多条。
|
||||
* - extraSumFields:除 valueField 外还需要累加的字段(如 tooltip 用的 rawQuota)
|
||||
*/
|
||||
const limitSeriesForMobile = (
|
||||
spec,
|
||||
{ groupField, valueField, bucketField = null, extraSumFields = [] },
|
||||
t,
|
||||
) => {
|
||||
const dataset = spec?.data?.[0];
|
||||
const values = dataset?.values;
|
||||
if (!Array.isArray(values) || values.length === 0) return spec;
|
||||
|
||||
const totals = new Map();
|
||||
values.forEach((row) => {
|
||||
const key = String(row?.[groupField] ?? '');
|
||||
if (!key) return;
|
||||
totals.set(key, (totals.get(key) || 0) + (Number(row?.[valueField]) || 0));
|
||||
});
|
||||
if (totals.size <= MOBILE_MAX_SERIES) return spec;
|
||||
|
||||
const keep = new Set(
|
||||
Array.from(totals.entries())
|
||||
.sort((a, b) => b[1] - a[1])
|
||||
.slice(0, MOBILE_MAX_SERIES)
|
||||
.map(([key]) => key),
|
||||
);
|
||||
|
||||
const otherLabel = t('其他');
|
||||
const merged = [];
|
||||
const otherBuckets = new Map();
|
||||
values.forEach((row) => {
|
||||
const key = String(row?.[groupField] ?? '');
|
||||
if (keep.has(key)) {
|
||||
merged.push(row);
|
||||
return;
|
||||
}
|
||||
const bucketKey = bucketField
|
||||
? String(row?.[bucketField] ?? '')
|
||||
: '__all__';
|
||||
const existing = otherBuckets.get(bucketKey);
|
||||
if (!existing) {
|
||||
otherBuckets.set(bucketKey, { ...row, [groupField]: otherLabel });
|
||||
return;
|
||||
}
|
||||
existing[valueField] =
|
||||
(Number(existing[valueField]) || 0) + (Number(row?.[valueField]) || 0);
|
||||
extraSumFields.forEach((field) => {
|
||||
existing[field] =
|
||||
(Number(existing[field]) || 0) + (Number(row?.[field]) || 0);
|
||||
});
|
||||
});
|
||||
|
||||
merged.push(...otherBuckets.values());
|
||||
|
||||
// 榜单类(无分桶维度)按数值重排,否则「其他」会固定落在末尾与排序语义冲突
|
||||
if (!bucketField) {
|
||||
merged.sort(
|
||||
(a, b) => (Number(b?.[valueField]) || 0) - (Number(a?.[valueField]) || 0),
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
...spec,
|
||||
data: [{ ...dataset, values: merged }],
|
||||
};
|
||||
};
|
||||
|
||||
// 双图配置 - 同行展示,统一品牌色系
|
||||
const BRAND_CHART_STYLE = {
|
||||
gradient: 'from-brand-from via-brand-via to-brand-to',
|
||||
glow: 'from-brand-from/20 via-brand-via/10 to-transparent',
|
||||
border: 'border-brand/15 dark:border-brand-deep/30',
|
||||
ring: 'ring-1 ring-brand/10 dark:ring-brand-from/15',
|
||||
badge:
|
||||
'bg-brand/10 dark:bg-brand-deep/40 text-brand-deep dark:text-brand-from border-brand/20 dark:border-brand-deep/40',
|
||||
};
|
||||
const CHARTS = [
|
||||
{
|
||||
key: 'consume',
|
||||
icon: AreaChart,
|
||||
label: '消费时段走势',
|
||||
sublabel: '按时间维度堆叠展示各模型支出',
|
||||
...BRAND_CHART_STYLE,
|
||||
badgeText: '面积图',
|
||||
},
|
||||
{
|
||||
key: 'pie',
|
||||
icon: Trophy,
|
||||
label: '模型调用排行',
|
||||
sublabel: '高到低排序的模型调用量榜单',
|
||||
...BRAND_CHART_STYLE,
|
||||
badgeText: '排行榜',
|
||||
},
|
||||
];
|
||||
|
||||
const ChartsPanel = ({
|
||||
spec_line,
|
||||
spec_pie,
|
||||
CHART_CONFIG,
|
||||
hasApiInfoPanel,
|
||||
t,
|
||||
}) => {
|
||||
const isMobile = useIsMobile();
|
||||
|
||||
const specs = useMemo(() => {
|
||||
if (!isMobile) {
|
||||
return { consume: spec_line, pie: spec_pie };
|
||||
}
|
||||
return {
|
||||
consume: toMobileSpec(
|
||||
limitSeriesForMobile(
|
||||
spec_line,
|
||||
{
|
||||
groupField: 'Model',
|
||||
valueField: 'Usage',
|
||||
bucketField: 'Time',
|
||||
extraSumFields: ['rawQuota'],
|
||||
},
|
||||
t,
|
||||
),
|
||||
),
|
||||
pie: toMobileSpec(
|
||||
limitSeriesForMobile(
|
||||
spec_pie,
|
||||
{ groupField: 'type', valueField: 'value', bucketField: null },
|
||||
t,
|
||||
),
|
||||
),
|
||||
};
|
||||
}, [isMobile, spec_line, spec_pie, t]);
|
||||
|
||||
// 手机端隐藏了图内标题,「总计」改挂到卡片头部,信息不丢
|
||||
const totals = {
|
||||
consume: spec_line?.title?.subtext || '',
|
||||
pie: spec_pie?.title?.subtext || '',
|
||||
};
|
||||
|
||||
const chartOption = isMobile ? MOBILE_CHART_CONFIG : CHART_CONFIG;
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`flex flex-col flex-1 min-h-0 ${hasApiInfoPanel ? 'lg:col-span-3' : ''}`}
|
||||
>
|
||||
<div className='grid grid-cols-1 xl:grid-cols-2 gap-4 flex-1 min-h-0'>
|
||||
{CHARTS.map((chart) => {
|
||||
const Icon = chart.icon;
|
||||
return (
|
||||
<div key={chart.key} className='relative flex flex-col min-h-0'>
|
||||
{/* 装饰渐变光晕 */}
|
||||
<div
|
||||
className={`pointer-events-none absolute -inset-1 bg-gradient-to-br ${chart.glow} rounded-3xl blur-xl opacity-60`}
|
||||
/>
|
||||
|
||||
<div
|
||||
className={`relative flex-1 flex flex-col min-h-0 bg-white dark:bg-neutral-900/90 backdrop-blur-sm rounded-2xl border border-gray-100 dark:border-neutral-800 shadow-[0_2px_12px_-2px_rgba(0,0,0,0.06)] dark:shadow-[0_2px_12px_-2px_rgba(0,0,0,0.4)] overflow-hidden`}
|
||||
>
|
||||
{/* 顶部高光条 */}
|
||||
<div
|
||||
className={`pointer-events-none absolute top-0 left-0 right-0 h-px bg-gradient-to-r ${chart.gradient} opacity-60`}
|
||||
/>
|
||||
|
||||
{/* 图表标题 + 副标题 + 类型徽章 */}
|
||||
<div className='relative flex items-center justify-between gap-3 px-4 pt-3.5 pb-2.5 shrink-0'>
|
||||
<div className='flex items-center gap-2.5 min-w-0'>
|
||||
<div
|
||||
className={`w-8 h-8 shrink-0 rounded-lg bg-gradient-to-br ${chart.gradient} flex items-center justify-center shadow-md`}
|
||||
>
|
||||
<Icon size={14} className='text-white' />
|
||||
</div>
|
||||
<div className='min-w-0'>
|
||||
<h3 className='font-semibold text-gray-900 dark:text-white text-[13px] tracking-wide leading-tight'>
|
||||
{t(chart.label)}
|
||||
</h3>
|
||||
{/* 手机端图内标题被隐藏,这里改显示「总计」,其余尺寸仍显示副标题 */}
|
||||
<p className='text-[10px] text-gray-400 dark:text-gray-500 leading-tight mt-0.5 truncate'>
|
||||
{isMobile && totals[chart.key]
|
||||
? totals[chart.key]
|
||||
: t(chart.sublabel)}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<span
|
||||
className={`shrink-0 inline-flex items-center px-2 py-0.5 rounded-md text-[10px] font-semibold border ${chart.badge}`}
|
||||
>
|
||||
{t(chart.badgeText)}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* 分隔线 */}
|
||||
<div className='mx-4 h-px bg-gradient-to-r from-transparent via-gray-200/60 to-transparent dark:via-gray-700/40 shrink-0' />
|
||||
|
||||
{/* 图表区域 - flex-1 撑满剩余高度,min-h 兜底防止过矮 */}
|
||||
<div className='relative flex-1 min-h-[300px] sm:min-h-[320px] p-1.5 sm:p-3 overflow-hidden'>
|
||||
{/* 网格装饰 */}
|
||||
<div
|
||||
className='pointer-events-none absolute inset-0 opacity-[0.025] dark:opacity-[0.05]'
|
||||
style={{
|
||||
backgroundImage: `
|
||||
linear-gradient(rgba(100, 100, 100, 0.5) 1px, transparent 1px),
|
||||
linear-gradient(90deg, rgba(100, 100, 100, 0.5) 1px, transparent 1px)
|
||||
`,
|
||||
backgroundSize: '36px 36px',
|
||||
}}
|
||||
/>
|
||||
<div className='relative h-full'>
|
||||
{/* 注意是 options 复数:react-vchart 的 notSpecKeys 里只认 'options',
|
||||
写成 option 会被当成普通 prop 丢弃(原来的 option={CHART_CONFIG}
|
||||
一直是失效的),移动端 mobile-browser 触屏 tooltip 也就一直没生效 */}
|
||||
<VChart spec={specs[chart.key]} options={chartOption} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ChartsPanel;
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
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 { Button } from '@douyinfe/semi-ui';
|
||||
import { RefreshCw, Search } from 'lucide-react';
|
||||
|
||||
const DashboardHeader = ({
|
||||
getGreeting,
|
||||
greetingVisible,
|
||||
showSearchModal,
|
||||
refresh,
|
||||
loading,
|
||||
t,
|
||||
}) => {
|
||||
const ICON_BUTTON_CLASS = 'text-white hover:bg-opacity-80 !rounded-full';
|
||||
|
||||
return (
|
||||
<div className='flex items-center justify-between mb-4'>
|
||||
<h2
|
||||
className='text-2xl font-semibold text-gray-800 transition-opacity duration-1000 ease-in-out'
|
||||
style={{ opacity: greetingVisible ? 1 : 0 }}
|
||||
>
|
||||
{getGreeting}
|
||||
</h2>
|
||||
<div className='flex gap-3'>
|
||||
<Button
|
||||
type='tertiary'
|
||||
icon={<Search size={16} />}
|
||||
onClick={showSearchModal}
|
||||
className={`bg-green-500 hover:bg-green-600 ${ICON_BUTTON_CLASS}`}
|
||||
/>
|
||||
<Button
|
||||
type='tertiary'
|
||||
icon={<RefreshCw size={16} />}
|
||||
onClick={refresh}
|
||||
loading={loading}
|
||||
className={`bg-blue-500 hover:bg-blue-600 ${ICON_BUTTON_CLASS}`}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default DashboardHeader;
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
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, Collapse, Empty } from '@douyinfe/semi-ui';
|
||||
import { HelpCircle } from 'lucide-react';
|
||||
import { IconPlus, IconMinus } from '@douyinfe/semi-icons';
|
||||
import { marked } from 'marked';
|
||||
import {
|
||||
IllustrationConstruction,
|
||||
IllustrationConstructionDark,
|
||||
} from '../common/illustrations';
|
||||
import ScrollableContainer from '../common/ui/ScrollableContainer';
|
||||
|
||||
const FaqPanel = ({
|
||||
faqData,
|
||||
CARD_PROPS,
|
||||
FLEX_CENTER_GAP2,
|
||||
ILLUSTRATION_SIZE,
|
||||
t,
|
||||
}) => {
|
||||
return (
|
||||
<Card
|
||||
{...CARD_PROPS}
|
||||
className='shadow-sm !rounded-2xl lg:col-span-1'
|
||||
title={
|
||||
<div className={FLEX_CENTER_GAP2}>
|
||||
<HelpCircle size={16} />
|
||||
{t('常见问答')}
|
||||
</div>
|
||||
}
|
||||
bodyStyle={{ padding: 0 }}
|
||||
>
|
||||
<ScrollableContainer maxHeight='24rem'>
|
||||
{faqData.length > 0 ? (
|
||||
<Collapse
|
||||
accordion
|
||||
expandIcon={<IconPlus />}
|
||||
collapseIcon={<IconMinus />}
|
||||
>
|
||||
{faqData.map((item, index) => (
|
||||
<Collapse.Panel
|
||||
key={index}
|
||||
header={item.question}
|
||||
itemKey={index.toString()}
|
||||
>
|
||||
<div
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: marked.parse(item.answer || ''),
|
||||
}}
|
||||
/>
|
||||
</Collapse.Panel>
|
||||
))}
|
||||
</Collapse>
|
||||
) : (
|
||||
<div className='flex justify-center items-center py-8'>
|
||||
<Empty
|
||||
image={<IllustrationConstruction style={ILLUSTRATION_SIZE} />}
|
||||
darkModeImage={
|
||||
<IllustrationConstructionDark style={ILLUSTRATION_SIZE} />
|
||||
}
|
||||
title={t('暂无常见问答')}
|
||||
description={t('请联系管理员在系统设置中配置常见问答')}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</ScrollableContainer>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default FaqPanel;
|
||||
@@ -0,0 +1,268 @@
|
||||
/*
|
||||
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 { Skeleton } from '@douyinfe/semi-ui';
|
||||
import { VChart } from '@visactor/react-vchart';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { ArrowUpRight, Wallet, TrendingUp, Zap, Clock } from 'lucide-react';
|
||||
|
||||
// 卡片调色板 —— 4 张指标卡用同一蓝色家族的冷色渐进(青→天蓝→蓝→靛),
|
||||
// 贴合云平台克制专业的观感;既能区分 4 张卡,又不像四色那样"花"。
|
||||
// 卡片本体为实底白(dark 实底深灰),强调色仅用于图标 / 顶部高光条 / 角落光斑 / 角标,
|
||||
// 既不透出页面 bg-glow 背景(解决"发灰"),又靠冷蓝 accent 提供层次。
|
||||
const CARD_PALETTES = [
|
||||
{
|
||||
// 账户 / 钱包 —— 青(cyan)
|
||||
iconBg: 'from-cyan-500 to-sky-600',
|
||||
iconShadow: 'shadow-cyan-500/25',
|
||||
glow: 'from-cyan-400/25 to-sky-300/5',
|
||||
bar: 'from-cyan-400 to-sky-500',
|
||||
badge: 'bg-cyan-50 text-cyan-600 dark:bg-cyan-500/15 dark:text-cyan-400',
|
||||
},
|
||||
{
|
||||
// 使用统计 —— 天蓝(sky)
|
||||
iconBg: 'from-sky-500 to-blue-600',
|
||||
iconShadow: 'shadow-sky-500/25',
|
||||
glow: 'from-sky-400/25 to-blue-300/5',
|
||||
bar: 'from-sky-400 to-blue-500',
|
||||
badge: 'bg-sky-50 text-sky-600 dark:bg-sky-500/15 dark:text-sky-400',
|
||||
},
|
||||
{
|
||||
// Token 消耗 —— 蓝(blue)
|
||||
iconBg: 'from-blue-500 to-indigo-600',
|
||||
iconShadow: 'shadow-blue-500/25',
|
||||
glow: 'from-blue-400/25 to-indigo-300/5',
|
||||
bar: 'from-blue-400 to-indigo-500',
|
||||
badge: 'bg-blue-50 text-blue-600 dark:bg-blue-500/15 dark:text-blue-400',
|
||||
},
|
||||
{
|
||||
// 性能指标 —— 靛(indigo)
|
||||
iconBg: 'from-indigo-500 to-violet-600',
|
||||
iconShadow: 'shadow-indigo-500/25',
|
||||
glow: 'from-indigo-400/25 to-violet-300/5',
|
||||
bar: 'from-indigo-400 to-violet-500',
|
||||
badge:
|
||||
'bg-indigo-50 text-indigo-600 dark:bg-indigo-500/15 dark:text-indigo-400',
|
||||
},
|
||||
];
|
||||
|
||||
// 分组图标映射
|
||||
const GROUP_ICONS = {
|
||||
0: Wallet, // 账户数据
|
||||
1: TrendingUp, // 使用统计
|
||||
2: Zap, // Token 消耗
|
||||
3: Clock, // 性能指标
|
||||
};
|
||||
|
||||
const StatsCards = ({
|
||||
groupedStatsData,
|
||||
loading,
|
||||
getTrendSpec,
|
||||
CARD_PROPS,
|
||||
CHART_CONFIG,
|
||||
}) => {
|
||||
const _navigate = useNavigate();
|
||||
const { t: _t } = useTranslation();
|
||||
const gridColsClass =
|
||||
groupedStatsData.length >= 4 ? 'xl:grid-cols-4' : 'xl:grid-cols-3';
|
||||
|
||||
return (
|
||||
<div className={`grid grid-cols-1 md:grid-cols-2 ${gridColsClass} gap-4`}>
|
||||
{groupedStatsData.map((group, idx) => {
|
||||
const palette = CARD_PALETTES[idx % CARD_PALETTES.length];
|
||||
const GroupIcon = GROUP_ICONS[idx] || Wallet;
|
||||
const isTwoColumnLayout = group.layout === 'two-column';
|
||||
|
||||
return (
|
||||
<div
|
||||
key={idx}
|
||||
className={`group/card relative overflow-hidden rounded-2xl bg-white dark:bg-neutral-900/90 border border-gray-100 dark:border-neutral-800 shadow-[0_2px_12px_-2px_rgba(0,0,0,0.06)] dark:shadow-[0_2px_12px_-2px_rgba(0,0,0,0.4)] hover:shadow-[0_12px_28px_-6px_rgba(0,0,0,0.12)] hover:-translate-y-0.5 transition-all duration-300 ease-out`}
|
||||
>
|
||||
{/* 装饰性渐变光斑 */}
|
||||
<div
|
||||
className={`pointer-events-none absolute -top-12 -right-12 w-36 h-36 bg-gradient-to-br ${palette.glow} rounded-full blur-2xl group-hover/card:scale-110 transition-transform duration-500`}
|
||||
/>
|
||||
{/* 顶部高光条 */}
|
||||
<div
|
||||
className={`pointer-events-none absolute top-0 left-0 right-0 h-px bg-gradient-to-r ${palette.bar} opacity-60`}
|
||||
/>
|
||||
{/* 微点阵纹理 - 强化卡片质感 */}
|
||||
<div
|
||||
className='pointer-events-none absolute inset-0 opacity-[0.025] dark:opacity-[0.04]'
|
||||
style={{
|
||||
backgroundImage:
|
||||
'radial-gradient(circle, currentColor 0.5px, transparent 0.5px)',
|
||||
backgroundSize: '12px 12px',
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* 卡片头部 - 标题 + 角标编号 */}
|
||||
<div className='relative px-4 pt-3.5 pb-2.5 flex items-center justify-between'>
|
||||
<div className='flex items-center gap-2.5'>
|
||||
<div
|
||||
className={`relative w-9 h-9 rounded-xl bg-gradient-to-br ${palette.iconBg} flex items-center justify-center shadow-md ${palette.iconShadow} group-hover/card:scale-105 transition-transform duration-300`}
|
||||
>
|
||||
<GroupIcon size={16} className='text-white' />
|
||||
<div className='absolute inset-0 rounded-xl bg-gradient-to-t from-white/0 via-white/0 to-white/30' />
|
||||
</div>
|
||||
<h3 className='font-semibold text-gray-900 dark:text-white text-[13px] tracking-wide'>
|
||||
{group.title}
|
||||
</h3>
|
||||
</div>
|
||||
{/* 序号角标 - 弱化的装饰编号 */}
|
||||
<span
|
||||
className={`text-[10px] font-bold tracking-widest tabular-nums ${palette.badge} px-1.5 py-0.5 rounded-md opacity-70`}
|
||||
>
|
||||
{String(idx + 1).padStart(2, '0')}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* 分隔线 - 渐变细线 */}
|
||||
<div className='mx-4 h-px bg-gradient-to-r from-transparent via-gray-200/60 to-transparent dark:via-gray-700/40' />
|
||||
|
||||
{/* 卡片内容 - 紧凑布局
|
||||
- two-column 模式:4 项 2×2 紧凑网格(Token 消耗)
|
||||
- 默认模式:2 项 左标题 + 右大数字 的两端对齐,把右侧留白用数值填满 */}
|
||||
<div
|
||||
className={`relative px-3 py-2.5 ${
|
||||
isTwoColumnLayout ? 'grid grid-cols-2 gap-2' : 'space-y-1'
|
||||
}`}
|
||||
>
|
||||
{group.items.map((item, itemIdx) => {
|
||||
// 趋势图仅在 item 显式提供 trendData 且非空时渲染
|
||||
const hasTrend =
|
||||
Array.isArray(item.trendData) && item.trendData.length > 0;
|
||||
|
||||
if (isTwoColumnLayout) {
|
||||
// ========== Token 消耗 - 紧凑卡片样式 ==========
|
||||
return (
|
||||
<div
|
||||
key={itemIdx}
|
||||
className={`group relative flex min-w-0 items-center gap-2.5 px-2 py-2 rounded-xl transition-all ${
|
||||
item.onClick ? 'cursor-pointer' : ''
|
||||
} hover:bg-white/60 dark:hover:bg-white/[0.04]`}
|
||||
onClick={item.onClick}
|
||||
>
|
||||
<div
|
||||
className='w-8 h-8 shrink-0 rounded-lg flex items-center justify-center text-[13px]'
|
||||
style={{
|
||||
backgroundColor: `var(--semi-color-${item.avatarColor}-light-default)`,
|
||||
color: `var(--semi-color-${item.avatarColor})`,
|
||||
}}
|
||||
>
|
||||
{item.icon}
|
||||
</div>
|
||||
<div className='min-w-0'>
|
||||
<div className='truncate text-[11px] text-gray-500 dark:text-gray-400 leading-tight mb-0.5'>
|
||||
{item.title}
|
||||
</div>
|
||||
<div className='truncate text-[15px] font-extrabold text-gray-900 dark:text-white leading-tight tabular-nums tracking-tight'>
|
||||
<Skeleton
|
||||
loading={loading}
|
||||
active
|
||||
placeholder={
|
||||
<Skeleton.Paragraph
|
||||
active
|
||||
rows={1}
|
||||
style={{ width: '60px', height: '18px' }}
|
||||
/>
|
||||
}
|
||||
>
|
||||
{item.value}
|
||||
</Skeleton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ========== 账户/使用统计/性能指标 - 单列 hero 行 ==========
|
||||
// 左:小图标 + 小标题;右:大数字(吃掉之前的留白)
|
||||
return (
|
||||
<div
|
||||
key={itemIdx}
|
||||
className={`group relative flex items-center justify-between gap-3 px-2.5 py-2.5 rounded-xl transition-all ${
|
||||
item.onClick ? 'cursor-pointer' : ''
|
||||
} hover:bg-white/60 dark:hover:bg-white/[0.04]`}
|
||||
onClick={item.onClick}
|
||||
>
|
||||
{/* 左侧:图标 + 标题 */}
|
||||
<div className='flex min-w-0 items-center gap-2.5'>
|
||||
<div
|
||||
className='w-7 h-7 shrink-0 rounded-lg flex items-center justify-center text-[12px]'
|
||||
style={{
|
||||
backgroundColor: `var(--semi-color-${item.avatarColor}-light-default)`,
|
||||
color: `var(--semi-color-${item.avatarColor})`,
|
||||
}}
|
||||
>
|
||||
{item.icon}
|
||||
</div>
|
||||
<span className='truncate text-[12px] text-gray-500 dark:text-gray-400'>
|
||||
{item.title}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* 右侧:大数字 + 可选趋势图(仅当显式提供) */}
|
||||
<div className='flex items-center gap-3 min-w-0'>
|
||||
{hasTrend && (
|
||||
<div className='w-14 h-6 opacity-70 group-hover:opacity-100 transition-opacity'>
|
||||
<VChart
|
||||
spec={getTrendSpec(item.trendData, item.trendColor)}
|
||||
option={CHART_CONFIG}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<div className='truncate text-right text-lg font-extrabold text-gray-900 dark:text-white leading-none tabular-nums tracking-tight'>
|
||||
<Skeleton
|
||||
loading={loading}
|
||||
active
|
||||
placeholder={
|
||||
<Skeleton.Paragraph
|
||||
active
|
||||
rows={1}
|
||||
style={{ width: '80px', height: '20px' }}
|
||||
/>
|
||||
}
|
||||
>
|
||||
{item.value}
|
||||
</Skeleton>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 悬停箭头 */}
|
||||
{item.onClick && (
|
||||
<ArrowUpRight
|
||||
size={12}
|
||||
className='absolute right-1.5 top-1.5 text-gray-300 dark:text-gray-600 opacity-0 group-hover:opacity-100 transition-opacity'
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default StatsCards;
|
||||
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
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,
|
||||
Button,
|
||||
Spin,
|
||||
Tabs,
|
||||
TabPane,
|
||||
Tag,
|
||||
Empty,
|
||||
} from '@douyinfe/semi-ui';
|
||||
import { Gauge, RefreshCw } from 'lucide-react';
|
||||
import {
|
||||
IllustrationConstruction,
|
||||
IllustrationConstructionDark,
|
||||
} from '../common/illustrations';
|
||||
import ScrollableContainer from '../common/ui/ScrollableContainer';
|
||||
|
||||
const UptimePanel = ({
|
||||
uptimeData,
|
||||
uptimeLoading,
|
||||
activeUptimeTab,
|
||||
setActiveUptimeTab,
|
||||
loadUptimeData,
|
||||
uptimeLegendData,
|
||||
renderMonitorList,
|
||||
CARD_PROPS,
|
||||
ILLUSTRATION_SIZE,
|
||||
t,
|
||||
}) => {
|
||||
return (
|
||||
<Card
|
||||
{...CARD_PROPS}
|
||||
className='shadow-sm !rounded-2xl lg:col-span-1'
|
||||
title={
|
||||
<div className='flex items-center justify-between w-full gap-2'>
|
||||
<div className='flex items-center gap-2'>
|
||||
<Gauge size={16} />
|
||||
{t('服务可用性')}
|
||||
</div>
|
||||
<Button
|
||||
icon={<RefreshCw size={14} />}
|
||||
onClick={loadUptimeData}
|
||||
loading={uptimeLoading}
|
||||
size='small'
|
||||
theme='borderless'
|
||||
type='tertiary'
|
||||
className='text-gray-500 hover:text-blue-500 hover:bg-blue-50 !rounded-full'
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
bodyStyle={{ padding: 0 }}
|
||||
>
|
||||
{/* 内容区域 */}
|
||||
<div className='relative'>
|
||||
<Spin spinning={uptimeLoading}>
|
||||
{uptimeData.length > 0 ? (
|
||||
uptimeData.length === 1 ? (
|
||||
<ScrollableContainer maxHeight='24rem'>
|
||||
{renderMonitorList(uptimeData[0].monitors)}
|
||||
</ScrollableContainer>
|
||||
) : (
|
||||
<Tabs
|
||||
type='card'
|
||||
collapsible
|
||||
activeKey={activeUptimeTab}
|
||||
onChange={setActiveUptimeTab}
|
||||
size='small'
|
||||
>
|
||||
{uptimeData.map((group, groupIdx) => (
|
||||
<TabPane
|
||||
tab={
|
||||
<span className='flex items-center gap-2'>
|
||||
<Gauge size={14} />
|
||||
{group.categoryName}
|
||||
<Tag
|
||||
color={
|
||||
activeUptimeTab === group.categoryName
|
||||
? 'red'
|
||||
: 'grey'
|
||||
}
|
||||
size='small'
|
||||
shape='circle'
|
||||
>
|
||||
{group.monitors ? group.monitors.length : 0}
|
||||
</Tag>
|
||||
</span>
|
||||
}
|
||||
itemKey={group.categoryName}
|
||||
key={groupIdx}
|
||||
>
|
||||
<ScrollableContainer maxHeight='21.5rem'>
|
||||
{renderMonitorList(group.monitors)}
|
||||
</ScrollableContainer>
|
||||
</TabPane>
|
||||
))}
|
||||
</Tabs>
|
||||
)
|
||||
) : (
|
||||
<div className='flex justify-center items-center py-8'>
|
||||
<Empty
|
||||
image={<IllustrationConstruction style={ILLUSTRATION_SIZE} />}
|
||||
darkModeImage={
|
||||
<IllustrationConstructionDark style={ILLUSTRATION_SIZE} />
|
||||
}
|
||||
title={t('暂无监控数据')}
|
||||
description={t('请联系管理员在系统设置中配置Uptime')}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</Spin>
|
||||
</div>
|
||||
|
||||
{/* 图例 */}
|
||||
{uptimeData.length > 0 && (
|
||||
<div className='p-3 bg-gray-50 rounded-b-2xl'>
|
||||
<div className='flex flex-wrap gap-3 text-xs justify-center'>
|
||||
{uptimeLegendData.map((legend, index) => (
|
||||
<div key={index} className='flex items-center gap-1'>
|
||||
<div
|
||||
className='w-2 h-2 rounded-full'
|
||||
style={{ backgroundColor: legend.color }}
|
||||
/>
|
||||
<span className='text-gray-600'>{legend.label}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default UptimePanel;
|
||||
@@ -0,0 +1,271 @@
|
||||
/*
|
||||
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, { useContext, useEffect } from 'react';
|
||||
import { getRelativeTime } from '../../helpers';
|
||||
import { UserContext } from '../../context/User';
|
||||
import { StatusContext } from '../../context/Status';
|
||||
|
||||
import DashboardHeader from './DashboardHeader';
|
||||
import StatsCards from './StatsCards';
|
||||
import ChartsPanel from './ChartsPanel';
|
||||
import ApiInfoPanel from './ApiInfoPanel';
|
||||
import AnnouncementsPanel from './AnnouncementsPanel';
|
||||
import FaqPanel from './FaqPanel';
|
||||
import UptimePanel from './UptimePanel';
|
||||
import SearchModal from './modals/SearchModal';
|
||||
|
||||
import { useDashboardData } from '../../hooks/dashboard/useDashboardData';
|
||||
import { useDashboardStats } from '../../hooks/dashboard/useDashboardStats';
|
||||
import { useDashboardCharts } from '../../hooks/dashboard/useDashboardCharts';
|
||||
|
||||
import {
|
||||
CHART_CONFIG,
|
||||
CARD_PROPS,
|
||||
FLEX_CENTER_GAP2,
|
||||
ILLUSTRATION_SIZE,
|
||||
ANNOUNCEMENT_LEGEND_DATA,
|
||||
UPTIME_STATUS_MAP,
|
||||
} from '../../constants/dashboard.constants';
|
||||
import {
|
||||
getTrendSpec,
|
||||
handleCopyUrl,
|
||||
handleSpeedTest,
|
||||
getUptimeStatusColor,
|
||||
getUptimeStatusText,
|
||||
renderMonitorList,
|
||||
} from '../../helpers/dashboard';
|
||||
|
||||
const Dashboard = () => {
|
||||
// ========== Context ==========
|
||||
const [userState, userDispatch] = useContext(UserContext);
|
||||
const [statusState] = useContext(StatusContext);
|
||||
|
||||
// ========== 主要数据管理 ==========
|
||||
const dashboardData = useDashboardData(userState, userDispatch, statusState);
|
||||
|
||||
// ========== 图表管理 ==========
|
||||
const dashboardCharts = useDashboardCharts(
|
||||
dashboardData.dataExportDefaultTime,
|
||||
dashboardData.setTrendData,
|
||||
dashboardData.setConsumeQuota,
|
||||
dashboardData.setTimes,
|
||||
dashboardData.setConsumeTokens,
|
||||
dashboardData.setPieData,
|
||||
dashboardData.setLineData,
|
||||
dashboardData.setModelColors,
|
||||
dashboardData.t,
|
||||
);
|
||||
|
||||
// ========== 统计数据 ==========
|
||||
const { groupedStatsData } = useDashboardStats(
|
||||
userState,
|
||||
dashboardData.consumeQuota,
|
||||
dashboardData.consumeTokens,
|
||||
dashboardData.times,
|
||||
dashboardData.trendData,
|
||||
dashboardData.performanceMetrics,
|
||||
dashboardData.navigate,
|
||||
dashboardData.t,
|
||||
);
|
||||
|
||||
// ========== 数据处理 ==========
|
||||
const initChart = async () => {
|
||||
await dashboardData.loadQuotaData().then((data) => {
|
||||
if (data && data.length > 0) {
|
||||
dashboardCharts.updateChartData(data);
|
||||
}
|
||||
});
|
||||
await dashboardData.loadUptimeData();
|
||||
};
|
||||
|
||||
const handleRefresh = async () => {
|
||||
const data = await dashboardData.refresh();
|
||||
if (data && data.length > 0) {
|
||||
dashboardCharts.updateChartData(data);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSearchConfirm = async () => {
|
||||
await dashboardData.handleSearchConfirm(dashboardCharts.updateChartData);
|
||||
};
|
||||
|
||||
// ========== 数据准备 ==========
|
||||
const apiInfoData = statusState?.status?.api_info || [];
|
||||
const announcementData = (statusState?.status?.announcements || []).map(
|
||||
(item) => {
|
||||
const pubDate = item?.publishDate ? new Date(item.publishDate) : null;
|
||||
const absoluteTime =
|
||||
pubDate && !isNaN(pubDate.getTime())
|
||||
? `${pubDate.getFullYear()}-${String(pubDate.getMonth() + 1).padStart(2, '0')}-${String(pubDate.getDate()).padStart(2, '0')} ${String(pubDate.getHours()).padStart(2, '0')}:${String(pubDate.getMinutes()).padStart(2, '0')}`
|
||||
: item?.publishDate || '';
|
||||
const relativeTime = getRelativeTime(item.publishDate);
|
||||
return {
|
||||
...item,
|
||||
time: absoluteTime,
|
||||
relative: relativeTime,
|
||||
};
|
||||
},
|
||||
);
|
||||
const faqData = statusState?.status?.faq || [];
|
||||
|
||||
const uptimeLegendData = Object.entries(UPTIME_STATUS_MAP).map(
|
||||
([status, info]) => ({
|
||||
status: Number(status),
|
||||
color: info.color,
|
||||
label: dashboardData.t(info.label),
|
||||
}),
|
||||
);
|
||||
|
||||
// ========== Effects ==========
|
||||
useEffect(() => {
|
||||
initChart();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className='h-full'>
|
||||
<DashboardHeader
|
||||
getGreeting={dashboardData.getGreeting}
|
||||
greetingVisible={dashboardData.greetingVisible}
|
||||
showSearchModal={dashboardData.showSearchModal}
|
||||
refresh={handleRefresh}
|
||||
loading={dashboardData.loading}
|
||||
t={dashboardData.t}
|
||||
/>
|
||||
|
||||
<SearchModal
|
||||
searchModalVisible={dashboardData.searchModalVisible}
|
||||
handleSearchConfirm={handleSearchConfirm}
|
||||
handleCloseModal={dashboardData.handleCloseModal}
|
||||
isMobile={dashboardData.isMobile}
|
||||
isAdminUser={dashboardData.isAdminUser}
|
||||
inputs={dashboardData.inputs}
|
||||
dataExportDefaultTime={dashboardData.dataExportDefaultTime}
|
||||
timeOptions={dashboardData.timeOptions}
|
||||
handleInputChange={dashboardData.handleInputChange}
|
||||
t={dashboardData.t}
|
||||
/>
|
||||
|
||||
<StatsCards
|
||||
groupedStatsData={groupedStatsData}
|
||||
loading={dashboardData.loading}
|
||||
getTrendSpec={getTrendSpec}
|
||||
CARD_PROPS={CARD_PROPS}
|
||||
CHART_CONFIG={CHART_CONFIG}
|
||||
/>
|
||||
|
||||
{/* API信息和图表面板 */}
|
||||
<div className='mb-4'>
|
||||
<div
|
||||
className={`grid grid-cols-1 gap-4 ${dashboardData.hasApiInfoPanel ? 'lg:grid-cols-4' : ''}`}
|
||||
>
|
||||
<ChartsPanel
|
||||
activeChartTab={dashboardData.activeChartTab}
|
||||
setActiveChartTab={dashboardData.setActiveChartTab}
|
||||
spec_line={dashboardCharts.spec_line}
|
||||
spec_model_line={dashboardCharts.spec_model_line}
|
||||
spec_pie={dashboardCharts.spec_pie}
|
||||
spec_rank_bar={dashboardCharts.spec_rank_bar}
|
||||
CARD_PROPS={CARD_PROPS}
|
||||
CHART_CONFIG={CHART_CONFIG}
|
||||
FLEX_CENTER_GAP2={FLEX_CENTER_GAP2}
|
||||
hasApiInfoPanel={dashboardData.hasApiInfoPanel}
|
||||
t={dashboardData.t}
|
||||
/>
|
||||
|
||||
{dashboardData.hasApiInfoPanel && (
|
||||
<ApiInfoPanel
|
||||
apiInfoData={apiInfoData}
|
||||
handleCopyUrl={(url) => handleCopyUrl(url, dashboardData.t)}
|
||||
handleSpeedTest={handleSpeedTest}
|
||||
CARD_PROPS={CARD_PROPS}
|
||||
FLEX_CENTER_GAP2={FLEX_CENTER_GAP2}
|
||||
ILLUSTRATION_SIZE={ILLUSTRATION_SIZE}
|
||||
t={dashboardData.t}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 系统公告和常见问答卡片 */}
|
||||
{dashboardData.hasInfoPanels && (
|
||||
<div className='mb-4'>
|
||||
<div className='grid grid-cols-1 lg:grid-cols-4 gap-4'>
|
||||
{/* 公告卡片 */}
|
||||
{dashboardData.announcementsEnabled && (
|
||||
<AnnouncementsPanel
|
||||
announcementData={announcementData}
|
||||
announcementLegendData={ANNOUNCEMENT_LEGEND_DATA.map(
|
||||
(item) => ({
|
||||
...item,
|
||||
label: dashboardData.t(item.label),
|
||||
}),
|
||||
)}
|
||||
CARD_PROPS={CARD_PROPS}
|
||||
ILLUSTRATION_SIZE={ILLUSTRATION_SIZE}
|
||||
t={dashboardData.t}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* 常见问答卡片 */}
|
||||
{dashboardData.faqEnabled && (
|
||||
<FaqPanel
|
||||
faqData={faqData}
|
||||
CARD_PROPS={CARD_PROPS}
|
||||
FLEX_CENTER_GAP2={FLEX_CENTER_GAP2}
|
||||
ILLUSTRATION_SIZE={ILLUSTRATION_SIZE}
|
||||
t={dashboardData.t}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* 服务可用性卡片 */}
|
||||
{dashboardData.uptimeEnabled && (
|
||||
<UptimePanel
|
||||
uptimeData={dashboardData.uptimeData}
|
||||
uptimeLoading={dashboardData.uptimeLoading}
|
||||
activeUptimeTab={dashboardData.activeUptimeTab}
|
||||
setActiveUptimeTab={dashboardData.setActiveUptimeTab}
|
||||
loadUptimeData={dashboardData.loadUptimeData}
|
||||
uptimeLegendData={uptimeLegendData}
|
||||
renderMonitorList={(monitors) =>
|
||||
renderMonitorList(
|
||||
monitors,
|
||||
(status) => getUptimeStatusColor(status, UPTIME_STATUS_MAP),
|
||||
(status) =>
|
||||
getUptimeStatusText(
|
||||
status,
|
||||
UPTIME_STATUS_MAP,
|
||||
dashboardData.t,
|
||||
),
|
||||
dashboardData.t,
|
||||
)
|
||||
}
|
||||
CARD_PROPS={CARD_PROPS}
|
||||
ILLUSTRATION_SIZE={ILLUSTRATION_SIZE}
|
||||
t={dashboardData.t}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Dashboard;
|
||||
@@ -0,0 +1,217 @@
|
||||
/*
|
||||
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, { useRef } from 'react';
|
||||
import { Modal, Form, Button } from '@douyinfe/semi-ui';
|
||||
import { Filter, Calendar, Clock, User, Search, X } from 'lucide-react';
|
||||
|
||||
const SearchModal = ({
|
||||
searchModalVisible,
|
||||
handleSearchConfirm,
|
||||
handleCloseModal,
|
||||
isMobile,
|
||||
isAdminUser,
|
||||
inputs,
|
||||
dataExportDefaultTime,
|
||||
timeOptions,
|
||||
handleInputChange,
|
||||
t,
|
||||
}) => {
|
||||
const formRef = useRef();
|
||||
|
||||
const { start_timestamp, end_timestamp, username } = inputs;
|
||||
|
||||
// 自定义标题
|
||||
const customTitle = (
|
||||
<div className='flex items-center gap-3 pt-2'>
|
||||
<div className='relative'>
|
||||
<div className='absolute inset-0 bg-gradient-to-br from-blue-500 to-brand-to rounded-xl blur opacity-50' />
|
||||
<div className='relative p-2.5 bg-gradient-to-br from-blue-500 to-brand-to rounded-xl shadow-lg shadow-blue-500/25'>
|
||||
<Filter size={18} className='text-white' />
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<h3 className='text-lg font-bold bg-clip-text text-transparent bg-gradient-to-r from-gray-900 to-gray-600 dark:from-white dark:to-gray-300'>
|
||||
{t('筛选数据')}
|
||||
</h3>
|
||||
<p className='text-xs text-gray-400 dark:text-gray-500'>
|
||||
{t('设置查询条件以筛选数据')}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
// 自定义底部按钮
|
||||
const customFooter = (
|
||||
<div className='flex items-center justify-end gap-3'>
|
||||
<Button
|
||||
type='tertiary'
|
||||
onClick={handleCloseModal}
|
||||
className='!rounded-xl !px-5 !h-10 !bg-gray-100 dark:!bg-gray-700 !border-0 hover:!bg-gray-200 dark:hover:!bg-gray-600 !transition-all'
|
||||
style={{ color: '#4b5563' }}
|
||||
icon={<X size={16} style={{ color: '#4b5563' }} />}
|
||||
>
|
||||
{t('取消')}
|
||||
</Button>
|
||||
<Button
|
||||
type='tertiary'
|
||||
onClick={handleSearchConfirm}
|
||||
className='!rounded-xl !px-5 !h-10 !bg-gradient-to-r !from-blue-500 !to-brand-to !border-0 hover:!opacity-90 !transition-all !shadow-lg !shadow-blue-500/25'
|
||||
style={{ color: '#ffffff' }}
|
||||
icon={<Search size={16} style={{ color: '#ffffff' }} />}
|
||||
>
|
||||
{t('查询')}
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
|
||||
// 表单字段包装器 - 紧凑版
|
||||
const FormFieldWrapper = ({ icon: Icon, label, children, gradient }) => (
|
||||
<div className='mb-3 last:mb-0'>
|
||||
<div className='flex items-center gap-2 mb-1.5'>
|
||||
<div
|
||||
className={`w-5 h-5 rounded-md bg-gradient-to-br ${gradient} flex items-center justify-center`}
|
||||
>
|
||||
<Icon size={10} className='text-white' />
|
||||
</div>
|
||||
<span className='text-xs font-medium text-gray-600 dark:text-gray-400'>
|
||||
{label}
|
||||
</span>
|
||||
</div>
|
||||
<div className='relative'>{children}</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<Modal
|
||||
visible={searchModalVisible}
|
||||
onCancel={handleCloseModal}
|
||||
closeOnEsc={true}
|
||||
size={isMobile ? 'full-width' : 'medium'}
|
||||
centered
|
||||
header={customTitle}
|
||||
footer={customFooter}
|
||||
className='search-modal-enhanced'
|
||||
style={{ maxWidth: isMobile ? '100%' : '480px' }}
|
||||
bodyStyle={{
|
||||
padding: '16px 20px',
|
||||
}}
|
||||
>
|
||||
<Form ref={formRef} layout='vertical' className='w-full'>
|
||||
{/* 时间范围区域 */}
|
||||
<div className='p-3 bg-gradient-to-br from-gray-50 to-gray-100/50 dark:from-gray-800/50 dark:to-gray-700/30 rounded-xl mb-3 border border-gray-100 dark:border-gray-700/50'>
|
||||
<div className='flex items-center gap-2 mb-2'>
|
||||
<div className='w-1 h-3 bg-gradient-to-b from-blue-500 to-brand-to rounded-full' />
|
||||
<span className='text-xs font-semibold text-gray-600 dark:text-gray-300'>
|
||||
{t('时间范围')}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* 时间选择器 - 单列布局确保宽度足够 */}
|
||||
<FormFieldWrapper
|
||||
icon={Calendar}
|
||||
label={t('起始时间')}
|
||||
gradient='from-emerald-500 to-teal-500'
|
||||
>
|
||||
<Form.DatePicker
|
||||
field='start_timestamp'
|
||||
noLabel
|
||||
initValue={start_timestamp}
|
||||
value={start_timestamp}
|
||||
type='dateTime'
|
||||
name='start_timestamp'
|
||||
onChange={(value) => handleInputChange(value, 'start_timestamp')}
|
||||
style={{ width: '100%' }}
|
||||
className='[&_.semi-input-wrapper]:!rounded-lg [&_.semi-input]:!text-sm'
|
||||
/>
|
||||
</FormFieldWrapper>
|
||||
|
||||
<FormFieldWrapper
|
||||
icon={Calendar}
|
||||
label={t('结束时间')}
|
||||
gradient='from-orange-500 to-amber-500'
|
||||
>
|
||||
<Form.DatePicker
|
||||
field='end_timestamp'
|
||||
noLabel
|
||||
initValue={end_timestamp}
|
||||
value={end_timestamp}
|
||||
type='dateTime'
|
||||
name='end_timestamp'
|
||||
onChange={(value) => handleInputChange(value, 'end_timestamp')}
|
||||
style={{ width: '100%' }}
|
||||
className='[&_.semi-input-wrapper]:!rounded-lg [&_.semi-input]:!text-sm'
|
||||
/>
|
||||
</FormFieldWrapper>
|
||||
</div>
|
||||
|
||||
{/* 其他选项区域 */}
|
||||
<div className='p-3 bg-gradient-to-br from-gray-50 to-gray-100/50 dark:from-gray-800/50 dark:to-gray-700/30 rounded-xl border border-gray-100 dark:border-gray-700/50'>
|
||||
<div className='flex items-center gap-2 mb-2'>
|
||||
<div className='w-1 h-3 bg-gradient-to-b from-brand-from to-pink-500 rounded-full' />
|
||||
<span className='text-xs font-semibold text-gray-600 dark:text-gray-300'>
|
||||
{t('查询选项')}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<FormFieldWrapper
|
||||
icon={Clock}
|
||||
label={t('时间粒度')}
|
||||
gradient='from-blue-500 to-brand-to'
|
||||
>
|
||||
<Form.Select
|
||||
field='data_export_default_time'
|
||||
noLabel
|
||||
initValue={dataExportDefaultTime}
|
||||
placeholder={t('时间粒度')}
|
||||
name='data_export_default_time'
|
||||
optionList={timeOptions}
|
||||
onChange={(value) =>
|
||||
handleInputChange(value, 'data_export_default_time')
|
||||
}
|
||||
style={{ width: '100%' }}
|
||||
className='[&_.semi-select]:!rounded-lg'
|
||||
/>
|
||||
</FormFieldWrapper>
|
||||
|
||||
{isAdminUser && (
|
||||
<FormFieldWrapper
|
||||
icon={User}
|
||||
label={t('用户名称')}
|
||||
gradient='from-brand-from to-pink-500'
|
||||
>
|
||||
<Form.Input
|
||||
field='username'
|
||||
noLabel
|
||||
value={username}
|
||||
placeholder={t('可选值')}
|
||||
name='username'
|
||||
onChange={(value) => handleInputChange(value, 'username')}
|
||||
style={{ width: '100%' }}
|
||||
className='[&_.semi-input-wrapper]:!rounded-lg'
|
||||
/>
|
||||
</FormFieldWrapper>
|
||||
)}
|
||||
</div>
|
||||
</Form>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export default SearchModal;
|
||||
Reference in New Issue
Block a user