@@ -162,6 +162,12 @@ export default function EndpointsPage() {
162162 return "card" ;
163163 } ) ;
164164
165+ // 表格排序状态 - 默认不排序
166+ const [ sortDescriptor , setSortDescriptor ] = useState < {
167+ column : string | React . Key ;
168+ direction : "ascending" | "descending" ;
169+ } | null > ( null ) ;
170+
165171 // 组件挂载和卸载管理
166172 useEffect ( ( ) => {
167173 isMountedRef . current = true ;
@@ -234,6 +240,29 @@ export default function EndpointsPage() {
234240 return formatUrlWithPrivacy ( url , apiPath , settings . isPrivacyMode ) ;
235241 } ;
236242
243+ // 获取排序后的端点列表 - 仅当有排序条件时才排序
244+ const sortedEndpoints = sortDescriptor
245+ ? endpoints . slice ( ) . sort ( ( a , b ) => {
246+ const key = sortDescriptor . column as keyof FormattedEndpoint ;
247+ let aValue : any = a [ key ] ;
248+ let bValue : any = b [ key ] ;
249+
250+ // 处理不同数据类型的比较
251+ if ( typeof aValue === "string" ) {
252+ aValue = aValue . toLowerCase ( ) ;
253+ bValue = ( bValue as string ) . toLowerCase ( ) ;
254+ }
255+
256+ if ( aValue < bValue ) {
257+ return sortDescriptor . direction === "ascending" ? - 1 : 1 ;
258+ }
259+ if ( aValue > bValue ) {
260+ return sortDescriptor . direction === "ascending" ? 1 : - 1 ;
261+ }
262+ return 0 ;
263+ } )
264+ : endpoints ;
265+
237266 const handleAddEndpoint = async ( data : EndpointFormData ) => {
238267 try {
239268 const response = await fetch ( buildApiUrl ( "/api/endpoints" ) , {
@@ -1289,16 +1318,28 @@ export default function EndpointsPage() {
12891318 </ div >
12901319 ) : (
12911320 /* 表格布局 */
1292- < Table aria-label = "API 主控列表" className = "mt-4" >
1321+ < Table
1322+ aria-label = "API 主控列表"
1323+ className = "mt-4"
1324+ sortDescriptor = { sortDescriptor ?? undefined }
1325+ onSortChange = { ( descriptor ) => {
1326+ if ( descriptor . column ) {
1327+ setSortDescriptor ( {
1328+ column : descriptor . column ,
1329+ direction : descriptor . direction ?? "ascending" ,
1330+ } ) ;
1331+ }
1332+ } }
1333+ >
12931334 < TableHeader >
12941335 < TableColumn key = "id" > ID</ TableColumn >
1295- < TableColumn key = "name" className = "min-w-[140px]" >
1336+ < TableColumn allowsSorting key = "name" className = "min-w-[140px]" >
12961337 名称
12971338 </ TableColumn >
12981339 < TableColumn key = "version" className = "w-24" >
12991340 版本
13001341 </ TableColumn >
1301- < TableColumn key = "url" className = "min-w-[200px]" >
1342+ < TableColumn allowsSorting key = "url" className = "min-w-[200px]" >
13021343 URL
13031344 </ TableColumn >
13041345 < TableColumn key = "apikey" className = "min-w-[220px]" >
@@ -1331,7 +1372,7 @@ export default function EndpointsPage() {
13311372 </ >
13321373 ) : (
13331374 < >
1334- { endpoints . map ( ( ep ) => {
1375+ { sortedEndpoints . map ( ( ep ) => {
13351376 const realTimeData = getEndpointDisplayData ( ep ) ;
13361377
13371378 return (
0 commit comments