diff --git a/src/App.tsx b/src/App.tsx index 6d5a90c..a18136f 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -134,6 +134,7 @@ function App() { const newProvider: Provider = { ...provider, id: generateId(), + createdAt: Date.now(), // 添加创建时间戳 }; await window.api.addProvider(newProvider, activeApp); await loadProviders(); diff --git a/src/components/ProviderList.tsx b/src/components/ProviderList.tsx index 1eac355..3ec1d4b 100644 --- a/src/components/ProviderList.tsx +++ b/src/components/ProviderList.tsx @@ -44,9 +44,30 @@ const ProviderList: React.FC = ({ } }; + // 对供应商列表进行排序 + const sortedProviders = Object.values(providers).sort((a, b) => { + // 按添加时间排序 + // 没有时间戳的视为最早添加的(排在最前面) + // 有时间戳的按时间升序排列 + const timeA = a.createdAt || 0; + const timeB = b.createdAt || 0; + + // 如果都没有时间戳,按名称排序 + if (timeA === 0 && timeB === 0) { + return a.name.localeCompare(b.name, 'zh-CN'); + } + + // 如果只有一个没有时间戳,没有时间戳的排在前面 + if (timeA === 0) return -1; + if (timeB === 0) return 1; + + // 都有时间戳,按时间升序 + return timeA - timeB; + }); + return (
- {Object.values(providers).length === 0 ? ( + {sortedProviders.length === 0 ? (
@@ -60,7 +81,7 @@ const ProviderList: React.FC = ({
) : (
- {Object.values(providers).map((provider) => { + {sortedProviders.map((provider) => { const isCurrent = provider.id === currentProviderId; const apiUrl = getApiUrl(provider); diff --git a/src/types.ts b/src/types.ts index 8ec7dd5..b6d0145 100644 --- a/src/types.ts +++ b/src/types.ts @@ -3,6 +3,7 @@ export interface Provider { name: string; settingsConfig: Record; // 应用配置对象:Claude 为 settings.json;Codex 为 { auth, config } websiteUrl?: string; + createdAt?: number; // 添加时间戳(毫秒) } export interface AppConfig {