From 2d841c0a2fbb899763fe1985387ff89cd0757c4e Mon Sep 17 00:00:00 2001 From: Supra4E8C Date: Thu, 12 Feb 2026 16:36:44 +0800 Subject: [PATCH] fix(provider-list): Modify the keyField function to support index parameters and ensure uniqueness fix(ai-providers): Optimize configuration synchronization logic in OpenAI editing layout --- .../providers/OpenAISection/OpenAISection.tsx | 2 +- src/components/providers/ProviderList.tsx | 4 ++-- src/pages/AiProvidersOpenAIEditLayout.tsx | 20 ++++++++++++------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/components/providers/OpenAISection/OpenAISection.tsx b/src/components/providers/OpenAISection/OpenAISection.tsx index 1d46761..e402da2 100644 --- a/src/components/providers/OpenAISection/OpenAISection.tsx +++ b/src/components/providers/OpenAISection/OpenAISection.tsx @@ -87,7 +87,7 @@ export function OpenAISection({ items={configs} loading={loading} - keyField={(item) => item.name} + keyField={(_, index) => `openai-provider-${index}`} emptyTitle={t('ai_providers.openai_empty_title')} emptyDescription={t('ai_providers.openai_empty_desc')} onEdit={onEdit} diff --git a/src/components/providers/ProviderList.tsx b/src/components/providers/ProviderList.tsx index 856e6b2..9d1a1f7 100644 --- a/src/components/providers/ProviderList.tsx +++ b/src/components/providers/ProviderList.tsx @@ -6,7 +6,7 @@ import { EmptyState } from '@/components/ui/EmptyState'; interface ProviderListProps { items: T[]; loading: boolean; - keyField: (item: T) => string; + keyField: (item: T, index: number) => string; renderContent: (item: T, index: number) => ReactNode; onEdit: (index: number) => void; onDelete: (index: number) => void; @@ -48,7 +48,7 @@ export function ProviderList({ const rowDisabled = getRowDisabled ? getRowDisabled(item, index) : false; return (
diff --git a/src/pages/AiProvidersOpenAIEditLayout.tsx b/src/pages/AiProvidersOpenAIEditLayout.tsx index 22614b7..8914a52 100644 --- a/src/pages/AiProvidersOpenAIEditLayout.tsx +++ b/src/pages/AiProvidersOpenAIEditLayout.tsx @@ -77,8 +77,6 @@ export function AiProvidersOpenAIEditLayout() { const config = useConfigStore((state) => state.config); const fetchConfig = useConfigStore((state) => state.fetchConfig); - const updateConfigValue = useConfigStore((state) => state.updateConfigValue); - const clearCache = useConfigStore((state) => state.clearCache); const isCacheValid = useConfigStore((state) => state.isCacheValid); const [providers, setProviders] = useState( @@ -335,9 +333,18 @@ export function AiProvidersOpenAIEditLayout() { : [...providers, payload]; await providersApi.saveOpenAIProviders(nextList); - setProviders(nextList); - updateConfigValue('openai-compatibility', nextList); - clearCache('openai-compatibility'); + + let syncedProviders = nextList; + try { + const latest = await fetchConfig('openai-compatibility', true); + if (Array.isArray(latest)) { + syncedProviders = latest as OpenAIProviderConfig[]; + } + } catch { + // 保存成功后刷新失败时,回退到本地计算结果,避免页面数据为空或回退 + } + + setProviders(syncedProviders); showNotification( editIndex !== null ? t('notification.openai_provider_updated') @@ -351,15 +358,14 @@ export function AiProvidersOpenAIEditLayout() { setSaving(false); } }, [ - clearCache, editIndex, + fetchConfig, form, handleBack, providers, testModel, showNotification, t, - updateConfigValue, ]); const resolvedLoading = !draft?.initialized;