From fe57db4462cec9546416f7ee0b06a9727cf3a732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A1=E8=8B=A5?= Date: Sun, 8 Mar 2026 09:57:28 +0800 Subject: [PATCH] =?UTF-8?q?sync:=20soul-admin=20=E5=89=8D=E7=AB=AF=20|=20?= =?UTF-8?q?=E5=8E=9F=E5=9B=A0:=20=E5=89=8D=E7=AB=AF=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- soul-admin/src/api/client.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/soul-admin/src/api/client.ts b/soul-admin/src/api/client.ts index d28af2fd..b975d111 100644 --- a/soul-admin/src/api/client.ts +++ b/soul-admin/src/api/client.ts @@ -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( 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)