From c095e15d6c03bfad862496f99f89f26e1115a110 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=94=E8=B7=91=E7=9A=84=E9=9D=A2=E6=9D=A1?= <1262327911@qq.com> Date: Sat, 28 May 2022 00:40:22 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E6=96=B0=E5=A2=9Eput=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/axios.ts | 2 -- src/api/http.ts | 34 +++++++++++++++++++++++++++------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/api/axios.ts b/src/api/axios.ts index 384ef3be..2e20ebd0 100644 --- a/src/api/axios.ts +++ b/src/api/axios.ts @@ -28,8 +28,6 @@ axiosInstance.interceptors.response.use( return Promise.resolve(res.data) }, (err: AxiosResponse) => { - const { code } = err.data as { code: number } - if (ErrorPageNameMap.get(code)) redirectErrorPage(code) window['$message'].error('接口异常,请检查!') Promise.reject(err) } diff --git a/src/api/http.ts b/src/api/http.ts index 13d69659..0e1fef82 100644 --- a/src/api/http.ts +++ b/src/api/http.ts @@ -19,6 +19,17 @@ export const post = (url: string, params: object, headersType?: string) => { }) } +export const put = (url: string, data?: object, headersType?: string) => { + return axiosInstance({ + url: url, + method: RequestHttpEnum.PUT, + data: data, + headers: { + 'Content-Type': headersType || ContentTypeEnum.JSON + } + }) +} + export const del = (url: string, params: object) => { return axiosInstance({ url: url, @@ -29,11 +40,20 @@ export const del = (url: string, params: object) => { // 获取请求函数,默认get export const http = (type?: RequestHttpEnum) => { - return type === RequestHttpEnum.GET - ? get - : type === RequestHttpEnum.POST - ? post - : type === RequestHttpEnum.DELETE - ? del - : get + switch (type) { + case RequestHttpEnum.GET: + return get + + case RequestHttpEnum.POST: + return post + + case RequestHttpEnum.PUT: + return put + + case RequestHttpEnum.DELETE: + return del + + default: + return get + } }