From 157fd4878acf1b99c0ed50ef35e733010f628ce2 Mon Sep 17 00:00:00 2001 From: xion Date: Wed, 16 Oct 2024 19:16:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96client=E5=92=8Ctimeout=E4=B8=BA3=E5=88=86=E9=92=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/adapter.ts | 2 +- src/index.ts | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/adapter.ts b/src/adapter.ts index 6ded4e4..4968e96 100644 --- a/src/adapter.ts +++ b/src/adapter.ts @@ -7,7 +7,7 @@ type AdapterOpts = { export const adapter = async (opts: AdapterOpts) => { const controller = new AbortController(); const signal = controller.signal; - const timeout = opts.timeout || 60000; // 默认超时时间为 60s + const timeout = opts.timeout || 60000 * 3; // 默认超时时间为 60s * 3 const timer = setTimeout(() => { controller.abort(); }, timeout); diff --git a/src/index.ts b/src/index.ts index 16fd673..8de0d7d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -54,7 +54,7 @@ export class Query { this.headers = opts?.headers || { 'Content-Type': 'application/json', }; - this.timeout = opts?.timeout || 60000; // 默认超时时间为 60s + this.timeout = opts?.timeout || 60000 * 3; // 默认超时时间为 60s * 3 } async get(params: Record & Data & U & T, options?: DataOpts): Promise> { return this.post(params, options); @@ -117,7 +117,7 @@ export class QueryClient extends Query { } } createWs(opts?: QueryWsOpts) { - this.qws = new QueryWs({ url: this.url }); + this.qws = new QueryWs({ url: this.url, ...opts }); } getToken() { return this.storage.getItem(this.tokenName); @@ -129,5 +129,6 @@ export class QueryClient extends Query { this.storage.removeItem(this.tokenName); } } +export const client = new QueryClient(); export { adapter };