mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-02-03 03:10:50 +08:00
fix(dashboard): improve stats loading and i18n date formatting
This commit is contained in:
@@ -28,7 +28,7 @@ interface ProviderStats {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function DashboardPage() {
|
export function DashboardPage() {
|
||||||
const { t } = useTranslation();
|
const { t, i18n } = useTranslation();
|
||||||
const connectionStatus = useAuthStore((state) => state.connectionStatus);
|
const connectionStatus = useAuthStore((state) => state.connectionStatus);
|
||||||
const serverVersion = useAuthStore((state) => state.serverVersion);
|
const serverVersion = useAuthStore((state) => state.serverVersion);
|
||||||
const serverBuildDate = useAuthStore((state) => state.serverBuildDate);
|
const serverBuildDate = useAuthStore((state) => state.serverBuildDate);
|
||||||
@@ -58,6 +58,10 @@ export function DashboardPage() {
|
|||||||
|
|
||||||
const apiKeysCache = useRef<string[]>([]);
|
const apiKeysCache = useRef<string[]>([]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
apiKeysCache.current = [];
|
||||||
|
}, [apiBase, config?.apiKeys]);
|
||||||
|
|
||||||
const normalizeApiKeyList = (input: any): string[] => {
|
const normalizeApiKeyList = (input: any): string[] => {
|
||||||
if (!Array.isArray(input)) return [];
|
if (!Array.isArray(input)) return [];
|
||||||
const seen = new Set<string>();
|
const seen = new Set<string>();
|
||||||
@@ -143,15 +147,28 @@ export function DashboardPage() {
|
|||||||
if (connectionStatus === 'connected') {
|
if (connectionStatus === 'connected') {
|
||||||
fetchStats();
|
fetchStats();
|
||||||
fetchModels();
|
fetchModels();
|
||||||
|
} else {
|
||||||
|
setLoading(false);
|
||||||
}
|
}
|
||||||
}, [connectionStatus, fetchModels]);
|
}, [connectionStatus, fetchModels]);
|
||||||
|
|
||||||
// Calculate total provider keys
|
// Calculate total provider keys only when all provider stats are available.
|
||||||
const totalProviderKeys =
|
const providerStatsReady =
|
||||||
(providerStats.gemini ?? 0) +
|
providerStats.gemini !== null &&
|
||||||
|
providerStats.codex !== null &&
|
||||||
|
providerStats.claude !== null &&
|
||||||
|
providerStats.openai !== null;
|
||||||
|
const hasProviderStats =
|
||||||
|
providerStats.gemini !== null ||
|
||||||
|
providerStats.codex !== null ||
|
||||||
|
providerStats.claude !== null ||
|
||||||
|
providerStats.openai !== null;
|
||||||
|
const totalProviderKeys = providerStatsReady
|
||||||
|
? (providerStats.gemini ?? 0) +
|
||||||
(providerStats.codex ?? 0) +
|
(providerStats.codex ?? 0) +
|
||||||
(providerStats.claude ?? 0) +
|
(providerStats.claude ?? 0) +
|
||||||
(providerStats.openai ?? 0);
|
(providerStats.openai ?? 0)
|
||||||
|
: 0;
|
||||||
|
|
||||||
const quickStats: QuickStat[] = [
|
const quickStats: QuickStat[] = [
|
||||||
{
|
{
|
||||||
@@ -164,16 +181,18 @@ export function DashboardPage() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: t('nav.ai_providers'),
|
label: t('nav.ai_providers'),
|
||||||
value: loading ? '-' : totalProviderKeys,
|
value: loading ? '-' : providerStatsReady ? totalProviderKeys : '-',
|
||||||
icon: <IconBot size={24} />,
|
icon: <IconBot size={24} />,
|
||||||
path: '/ai-providers',
|
path: '/ai-providers',
|
||||||
loading: loading,
|
loading: loading,
|
||||||
sublabel: t('dashboard.provider_keys_detail', {
|
sublabel: hasProviderStats
|
||||||
gemini: providerStats.gemini ?? 0,
|
? t('dashboard.provider_keys_detail', {
|
||||||
codex: providerStats.codex ?? 0,
|
gemini: providerStats.gemini ?? '-',
|
||||||
claude: providerStats.claude ?? 0,
|
codex: providerStats.codex ?? '-',
|
||||||
openai: providerStats.openai ?? 0
|
claude: providerStats.claude ?? '-',
|
||||||
|
openai: providerStats.openai ?? '-'
|
||||||
})
|
})
|
||||||
|
: undefined
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: t('nav.auth_files'),
|
label: t('nav.auth_files'),
|
||||||
@@ -226,7 +245,7 @@ export function DashboardPage() {
|
|||||||
{serverVersion && <span className={styles.serverVersion}>v{serverVersion}</span>}
|
{serverVersion && <span className={styles.serverVersion}>v{serverVersion}</span>}
|
||||||
{serverBuildDate && (
|
{serverBuildDate && (
|
||||||
<span className={styles.buildDate}>
|
<span className={styles.buildDate}>
|
||||||
{new Date(serverBuildDate).toLocaleDateString()}
|
{new Date(serverBuildDate).toLocaleDateString(i18n.language)}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user