From ba4fb6b45e05fc2b732be818f4337863d6b38ffb Mon Sep 17 00:00:00 2001 From: YoVinchen Date: Sun, 26 Oct 2025 09:03:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=B1=95=E7=A4=BA=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/SortableStationItem.tsx | 286 ++++++++++++++----------- 1 file changed, 161 insertions(+), 125 deletions(-) diff --git a/src/components/SortableStationItem.tsx b/src/components/SortableStationItem.tsx index e361633..b16bfec 100644 --- a/src/components/SortableStationItem.tsx +++ b/src/components/SortableStationItem.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useState, useEffect } from 'react'; import { useSortable } from '@dnd-kit/sortable'; import { CSS } from '@dnd-kit/utilities'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; @@ -9,6 +9,8 @@ import { Trash2, Globe, GripVertical, + ChevronDown, + ChevronRight, } from 'lucide-react'; import { RelayStation, @@ -50,12 +52,26 @@ export const SortableStationItem: React.FC = ({ isDragging, } = useSortable({ id: station.id }); + // 展开/收起状态,从 localStorage 读取 + const [isExpanded, setIsExpanded] = useState(() => { + const saved = localStorage.getItem(`relay-station-expanded-${station.id}`); + return saved !== null ? JSON.parse(saved) : true; // 默认展开 + }); + + // 保存展开状态到 localStorage + useEffect(() => { + localStorage.setItem(`relay-station-expanded-${station.id}`, JSON.stringify(isExpanded)); + }, [isExpanded, station.id]); + const style = { transform: CSS.Transform.toString(transform), transition, opacity: isDragging ? 0.5 : 1, }; + // 是否有详情内容需要显示 + const hasDetails = station.description || station.adapter === 'packycode'; + return ( @@ -105,141 +121,161 @@ export const SortableStationItem: React.FC = ({
-
- - {station.api_url} +
+
+ + {station.api_url} +
+ {hasDetails && ( + + )}
- {station.description && ( -

- {station.description} -

- )} + {/* 详情内容(可折叠) */} + {isExpanded && hasDetails && ( + <> + {station.description && ( +

+ {station.description} +

+ )} - {/* PackyCode 额度显示 */} - {station.adapter === 'packycode' && ( -
- {loadingQuota[station.id] ? ( -
-
- 加载中... -
- ) : quotaData[station.id] ? ( -
- {/* 用户信息和计划 */} -
-
- {quotaData[station.id].username && ( - {quotaData[station.id].username} - )} - - {quotaData[station.id].plan_type.toUpperCase()} - - {quotaData[station.id].opus_enabled && ( - - Opus - - )} + {/* PackyCode 额度显示 */} + {station.adapter === 'packycode' && ( +
+ {loadingQuota[station.id] ? ( +
+
+ 加载中...
-
+ ) : quotaData[station.id] ? ( +
+ {/* 用户信息和计划 */} +
+
+ {quotaData[station.id].username && ( + {quotaData[station.id].username} + )} + + {quotaData[station.id].plan_type.toUpperCase()} + + {quotaData[station.id].opus_enabled && ( + + Opus + + )} +
+
- {/* 账户余额 */} -
- 余额: - - ${Number(quotaData[station.id].balance_usd).toFixed(2)} - -
+ {/* 账户余额 */} +
+ 余额: + + ${Number(quotaData[station.id].balance_usd).toFixed(2)} + +
- {/* 日额度 */} -
-
- 日额度: -
- {(() => { - const daily_spent = Number(quotaData[station.id].daily_spent_usd); - const daily_budget = Number(quotaData[station.id].daily_budget_usd); - return ( - <> - daily_budget * 0.8 ? 'text-orange-600' : 'text-green-600'}> - ${daily_spent.toFixed(2)} - - / ${daily_budget.toFixed(2)} - - ); - })()} + {/* 日额度 */} +
+
+ 日额度: +
+ {(() => { + const daily_spent = Number(quotaData[station.id].daily_spent_usd); + const daily_budget = Number(quotaData[station.id].daily_budget_usd); + return ( + <> + daily_budget * 0.8 ? 'text-orange-600' : 'text-green-600'}> + ${daily_spent.toFixed(2)} + + / ${daily_budget.toFixed(2)} + + ); + })()} +
+
+
+
{ + const daily_spent = Number(quotaData[station.id].daily_spent_usd); + const daily_budget = Number(quotaData[station.id].daily_budget_usd); + return daily_spent / daily_budget > 0.8; + })() ? 'bg-orange-500' : 'bg-green-500' + }`} + style={{ width: `${Math.min( + (() => { + const daily_spent = Number(quotaData[station.id].daily_spent_usd); + const daily_budget = Number(quotaData[station.id].daily_budget_usd); + return (daily_spent / daily_budget) * 100; + })(), 100)}%` }} + /> +
+
+ + {/* 月额度 */} +
+
+ 月额度: +
+ {(() => { + const monthly_spent = Number(quotaData[station.id].monthly_spent_usd); + const monthly_budget = Number(quotaData[station.id].monthly_budget_usd); + return ( + <> + monthly_budget * 0.8 ? 'text-orange-600' : 'text-green-600'}> + ${monthly_spent.toFixed(2)} + + / + ${monthly_budget.toFixed(2)} + + ); + })()} +
+
+
+
{ + const monthly_spent = Number(quotaData[station.id].monthly_spent_usd); + const monthly_budget = Number(quotaData[station.id].monthly_budget_usd); + return monthly_spent / monthly_budget > 0.8; + })() ? 'bg-orange-500' : 'bg-green-500' + }`} + style={{ width: `${Math.min( + (() => { + const monthly_spent = Number(quotaData[station.id].monthly_spent_usd); + const monthly_budget = Number(quotaData[station.id].monthly_budget_usd); + return (monthly_spent / monthly_budget) * 100; + })(), 100)}%` }} + /> +
+
+ + {/* 总消费 */} +
+ 总消费: + ${Number(quotaData[station.id].total_spent_usd).toFixed(2)}
-
-
{ - const daily_spent = Number(quotaData[station.id].daily_spent_usd); - const daily_budget = Number(quotaData[station.id].daily_budget_usd); - return daily_spent / daily_budget > 0.8; - })() ? 'bg-orange-500' : 'bg-green-500' - }`} - style={{ width: `${Math.min( - (() => { - const daily_spent = Number(quotaData[station.id].daily_spent_usd); - const daily_budget = Number(quotaData[station.id].daily_budget_usd); - return (daily_spent / daily_budget) * 100; - })(), 100)}%` }} - /> + ) : ( +
+ 额度信息加载失败
-
- - {/* 月额度 */} -
-
- 月额度: -
- {(() => { - const monthly_spent = Number(quotaData[station.id].monthly_spent_usd); - const monthly_budget = Number(quotaData[station.id].monthly_budget_usd); - return ( - <> - monthly_budget * 0.8 ? 'text-orange-600' : 'text-green-600'}> - ${monthly_spent.toFixed(2)} - - / - ${monthly_budget.toFixed(2)} - - ); - })()} -
-
-
-
{ - const monthly_spent = Number(quotaData[station.id].monthly_spent_usd); - const monthly_budget = Number(quotaData[station.id].monthly_budget_usd); - return monthly_spent / monthly_budget > 0.8; - })() ? 'bg-orange-500' : 'bg-green-500' - }`} - style={{ width: `${Math.min( - (() => { - const monthly_spent = Number(quotaData[station.id].monthly_spent_usd); - const monthly_budget = Number(quotaData[station.id].monthly_budget_usd); - return (monthly_spent / monthly_budget) * 100; - })(), 100)}%` }} - /> -
-
- - {/* 总消费 */} -
- 总消费: - ${Number(quotaData[station.id].total_spent_usd).toFixed(2)} -
-
- ) : ( -
- 额度信息加载失败 + )}
)} -
+ )}