From 7368321bad19eb1c774b8d5e8f70cb683c95f64a Mon Sep 17 00:00:00 2001 From: mingchiuli Date: Tue, 14 Jan 2025 23:08:17 +0800 Subject: [PATCH] add long http --- src/http/axios.ts | 10 ++++++++-- src/http/http.ts | 10 +++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/http/axios.ts b/src/http/axios.ts index 11fffa7..05f4542 100644 --- a/src/http/axios.ts +++ b/src/http/axios.ts @@ -6,7 +6,11 @@ import { loginStateStore } from '@/stores/store' const http = axios.create({ baseURL: import.meta.env.VITE_BASE_URL, - timeout: 20000 + timeout: 10000 +}) + +const longHttp = axios.create({ + baseURL: import.meta.env.VITE_BASE_URL }) const requestInterceptor = async (config: any) => { @@ -50,5 +54,7 @@ const errorInterceptor = (error: AxiosError) => { http.interceptors.request.use(requestInterceptor) http.interceptors.response.use(responseInterceptor, errorInterceptor) +longHttp.interceptors.request.use(requestInterceptor) +longHttp.interceptors.response.use(responseInterceptor, errorInterceptor) -export default http +export default { http, longHttp } diff --git a/src/http/http.ts b/src/http/http.ts index d5021eb..b4b7034 100644 --- a/src/http/http.ts +++ b/src/http/http.ts @@ -1,14 +1,14 @@ -import http from '@/http/axios' +import client from '@/http/axios' import type { Data } from '@/type/entity' import type { AxiosProgressEvent } from 'axios' import { type Ref } from 'vue' const GET = async (url: string): Promise => { - return Promise.resolve((await http.get>(url)).data) + return Promise.resolve((await client.http.get>(url)).data) } const POST = async (url: string, params: any): Promise => { - return Promise.resolve((await http.post>(url, params)).data) + return Promise.resolve((await client.http.post>(url, params)).data) } const handleProgress = ( @@ -28,7 +28,7 @@ const DOWNLOAD_DATA = async ( let data: any percentageShow.value = true percentage.value = 0 - await http + await client.longHttp .get(url, { onDownloadProgress: (progressEvent) => handleProgress(percentage, percentageShow, progressEvent) @@ -57,7 +57,7 @@ const UPLOAD = async ( percentageShow.value = true percentage.value = 0 let url = '' - await http + await client.longHttp .post(dest, formData, { onUploadProgress: (progressEvent) => handleProgress(percentage, percentageShow, progressEvent) })