修复平铺模式用户切换与图表TS构建

This commit is contained in:
root
2026-02-02 04:50:22 +00:00
parent 531ba0bfed
commit ac30f0172f
3 changed files with 56 additions and 30 deletions
+40 -26
View File
@@ -741,31 +741,45 @@ export default function DashboardPage() {
tickLine={false} tickLine={false}
axisLine={{ stroke: '#e5e7eb', strokeWidth: 1 }} axisLine={{ stroke: '#e5e7eb', strokeWidth: 1 }}
/> />
<YAxis <YAxis
tick={{ fontSize: 12 }} tick={{ fontSize: 12 }}
tickLine={false} tickLine={false}
axisLine={{ stroke: '#e5e7eb', strokeWidth: 1 }} axisLine={{ stroke: '#e5e7eb', strokeWidth: 1 }}
tickFormatter={(value) => { tickFormatter={(value: number | string) => {
if (value === 0) return '0'; const v = typeof value === 'number' ? value : Number(value);
if (value < 1024) return `${value}B`; if (!Number.isFinite(v)) return String(value);
if (value < 1024 * 1024) return `${(value / 1024).toFixed(1)}K`; if (v === 0) return '0';
if (value < 1024 * 1024 * 1024) return `${(value / (1024 * 1024)).toFixed(1)}M`; if (v < 1024) return `${v}B`;
return `${(value / (1024 * 1024 * 1024)).toFixed(1)}G`; if (v < 1024 * 1024) return `${(v / 1024).toFixed(1)}K`;
}} if (v < 1024 * 1024 * 1024) return `${(v / (1024 * 1024)).toFixed(1)}M`;
/> return `${(v / (1024 * 1024 * 1024)).toFixed(1)}G`;
<Tooltip }}
content={({ active, payload, label }) => { />
if (active && payload && payload.length) { <Tooltip
return ( content={({
<div className="bg-white dark:bg-default-100 border border-default-200 rounded-lg shadow-lg p-3"> active,
<p className="font-medium text-foreground">{`时间: ${label}`}</p> payload,
<p className="text-primary"> label,
{`流量: ${formatFlow(payload[0]?.value as number || 0)}`} }: {
</p> active?: boolean;
</div> payload?: Array<{ value?: number | string }>;
); label?: string | number;
} }) => {
return null; if (active && payload && payload.length) {
const firstValue = payload[0]?.value;
const numericValue = typeof firstValue === 'number' ? firstValue : Number(firstValue);
const flowValue = Number.isFinite(numericValue) ? numericValue : 0;
return (
<div className="bg-white dark:bg-default-100 border border-default-200 rounded-lg shadow-lg p-3">
<p className="font-medium text-foreground">{`时间: ${label ?? ''}`}</p>
<p className="text-primary">
{`流量: ${formatFlow(flowValue)}`}
</p>
</div>
);
}
return null;
}} }}
/> />
<Line <Line
@@ -983,4 +997,4 @@ export default function DashboardPage() {
</div> </div>
); );
} }
+5 -4
View File
@@ -1117,6 +1117,8 @@ export default function ForwardPage() {
}) })
); );
const tokenUserId = JwtUtil.getUserIdFromToken();
// 根据排序顺序获取转发列表 // 根据排序顺序获取转发列表
const sortedForwards = useMemo((): Forward[] => { const sortedForwards = useMemo((): Forward[] => {
// 确保 forwards 数组存在且有效 // 确保 forwards 数组存在且有效
@@ -1127,9 +1129,8 @@ export default function ForwardPage() {
// 在平铺模式下,只显示当前用户的转发 // 在平铺模式下,只显示当前用户的转发
let filteredForwards = forwards; let filteredForwards = forwards;
if (viewMode === 'direct') { if (viewMode === 'direct') {
const currentUserId = JwtUtil.getUserIdFromToken(); if (tokenUserId !== null) {
if (currentUserId !== null) { filteredForwards = forwards.filter(forward => forward.userId === tokenUserId);
filteredForwards = forwards.filter(forward => forward.userId === currentUserId);
} }
} }
@@ -1168,7 +1169,7 @@ export default function ForwardPage() {
} }
return sortedByDb; return sortedByDb;
}, [forwards, forwardOrder, viewMode]); }, [forwards, forwardOrder, viewMode, tokenUserId]);
const sortableForwardIds = useMemo( const sortableForwardIds = useMemo(
() => sortedForwards.map(f => f.id).filter(id => id > 0), () => sortedForwards.map(f => f.id).filter(id => id > 0),
+11
View File
@@ -0,0 +1,11 @@
declare module 'recharts' {
import * as React from 'react';
export const LineChart: React.ComponentType<Record<string, unknown>>;
export const Line: React.ComponentType<Record<string, unknown>>;
export const XAxis: React.ComponentType<Record<string, unknown>>;
export const YAxis: React.ComponentType<Record<string, unknown>>;
export const CartesianGrid: React.ComponentType<Record<string, unknown>>;
export const Tooltip: React.ComponentType<Record<string, unknown>>;
export const ResponsiveContainer: React.ComponentType<Record<string, unknown>>;
}