feat: 管理界面报刊风统一改造 — 移除独立暗色主题,预测/回测/监控/配置页增强

This commit is contained in:
shangfangjian
2026-09-18 10:42:14 +08:00
parent 91e406f5ee
commit cf0751d1ff
15 changed files with 1275 additions and 828 deletions
+32 -5
View File
@@ -1,10 +1,34 @@
/**
* Admin 后台管理系统 - 统一 API 客户端
*
* 写入型/高成本接口(采集、回测、结算)受 X-API-Key 保护:
* 密钥在「系统配置」页设置,存于本机 localStorage,每次请求自动附带。
*/
const API_BASE = '/api/v1'
const TIMEOUT_MS = 30_000
const ADMIN_KEY_STORAGE = 'profeto_admin_key'
/** 读取本机保存的管理员密钥 */
export function getAdminKey(): string {
try {
return localStorage.getItem(ADMIN_KEY_STORAGE) ?? ''
} catch {
return ''
}
}
/** 保存/清除管理员密钥(传空字符串即清除) */
export function setAdminKey(key: string): void {
try {
if (key) localStorage.setItem(ADMIN_KEY_STORAGE, key)
else localStorage.removeItem(ADMIN_KEY_STORAGE)
} catch {
/* 隐私模式等场景下不可用,静默忽略 */
}
}
export class ApiError extends Error {
constructor(
message: string,
@@ -28,11 +52,13 @@ async function request<T>(path: string, options: RequestInit = {}): Promise<T> {
const timer = setTimeout(() => controller.abort(), TIMEOUT_MS)
try {
const adminKey = getAdminKey()
const res = await fetch(url, {
...options,
signal: controller.signal,
headers: {
'Content-Type': 'application/json',
...(adminKey ? { 'X-API-Key': adminKey } : {}),
...options.headers,
},
})
@@ -44,13 +70,14 @@ async function request<T>(path: string, options: RequestInit = {}): Promise<T> {
} catch {
detail = await res.text()
}
throw new ApiError(
let message =
detail && typeof detail === 'object' && 'detail' in detail
? String((detail as { detail: unknown }).detail)
: `HTTP ${res.status}: ${res.statusText}`,
res.status,
detail,
)
: `HTTP ${res.status}: ${res.statusText}`
if (res.status === 401) {
message += '\n请在「系统配置」页填写管理员密钥后重试。'
}
throw new ApiError(message, res.status, detail)
}
// 修复: 正确判断 204 No Content