import { useCallback, useEffect, useState } from 'react'
import { adminSystem } from '@/shared/api'
import type { SystemConfig } from '@/shared/api'
import { ApiError } from '@/shared/api'
import { formatDateTime } from '@/shared/format'
import { Badge, Button, Card, ErrorBanner, Loading } from '@/shared/ui'
function Rows({ entries }: { entries: [string, string | number | boolean | null | undefined][] }) {
return (
{entries.map(([label, value]) => (
- {label}
-
{value === null || value === undefined || value === '' ? '-' : String(value)}
))}
)
}
function onOff(value: boolean | null | undefined): string {
if (value === null || value === undefined) {
return '-'
}
return value ? '开启' : '关闭'
}
export function SystemPage() {
const [config, setConfig] = useState(null)
const [error, setError] = useState(null)
const [busy, setBusy] = useState(false)
const load = useCallback(async () => {
setBusy(true)
setError(null)
try {
setConfig(await adminSystem.config())
} catch (err) {
setError(err instanceof ApiError ? err.message : '配置快照加载失败')
} finally {
setBusy(false)
}
}, [])
useEffect(() => {
void load()
}, [load])
if (!config) {
return (
)
}
return (
系统配置
adminhost v{config.version} · 快照于 {formatDateTime(config.generated_at)} · 不含任何密钥
[
host.name,
`${host.bind_addr ?? '-'}:${host.port ?? '-'} · ${host.enabled ? '启用' : '停用'}`,
] as [string, string],
),
['adminhost', `${config.admin.bind_addr}:${config.admin.port}`],
['管理端 Cookie', config.admin.session_cookie_name],
['管理端会话表', config.admin.session_table_name],
['管理端跨域来源', config.admin.cors_allow_origins.join(', ') || '未配置(同源部署)'],
['跨域携带凭据', onOff(config.admin.cors_allow_credentials)],
]}
/>
{config.import.allow_insecure_tls && (
导入允许不安全 TLS
)}
)
}