sync: soul-admin 前端 | 原因: 前端代码修改

This commit is contained in:
卡若
2026-03-08 09:57:28 +08:00
parent d6344d4e62
commit fe57db4462

View File

@@ -9,6 +9,9 @@ import { getAdminToken } from './auth'
/** 未设置环境变量时使用的默认 API 地址(零配置部署) */
const DEFAULT_API_BASE = 'https://soulapi.quwanzhi.com'
/** 请求超时(毫秒),避免接口无响应时一直卡在加载中 */
const REQUEST_TIMEOUT = 15000
const getBaseUrl = (): string => {
const url = import.meta.env.VITE_API_BASE_URL
if (typeof url === 'string' && url.length > 0) return url.replace(/\/$/, '')
@@ -43,12 +46,15 @@ export async function request<T = unknown>(
headers.set('Content-Type', 'application/json')
}
const body = data !== undefined && data !== null ? JSON.stringify(data) : init.body
const controller = new AbortController()
const timeoutId = setTimeout(() => controller.abort(), REQUEST_TIMEOUT)
const res = await fetch(url, {
...init,
headers,
body,
credentials: 'include',
})
signal: init.signal ?? controller.signal,
}).finally(() => clearTimeout(timeoutId))
const contentType = res.headers.get('Content-Type') || ''
const json: T = contentType.includes('application/json')
? ((await res.json()) as T)