取消get请求成功后的message消息
This commit is contained in:
parent
3145335e6b
commit
98ad5d16f4
|
|
@ -78,6 +78,7 @@ service.interceptors.request.use(requestInterceptor, requestErrorInterceptor)
|
||||||
const responseInterceptor = <T = unknown>(response: AxiosResponse<ApiResponse<T>>) => {
|
const responseInterceptor = <T = unknown>(response: AxiosResponse<ApiResponse<T>>) => {
|
||||||
//关闭loading(无论成功失败都要关)
|
//关闭loading(无论成功失败都要关)
|
||||||
hideLoading()
|
hideLoading()
|
||||||
|
const config = response.config
|
||||||
if (response.headers['new_token'] !== undefined) {
|
if (response.headers['new_token'] !== undefined) {
|
||||||
setStorage('token', response.headers['new_token'] as string)
|
setStorage('token', response.headers['new_token'] as string)
|
||||||
}
|
}
|
||||||
|
|
@ -86,13 +87,14 @@ const responseInterceptor = <T = unknown>(response: AxiosResponse<ApiResponse<T>
|
||||||
console.log('响应数据data', data);
|
console.log('响应数据data', data);
|
||||||
// 判断业务状态码
|
// 判断业务状态码
|
||||||
if (data.code == 200 || data.code == 0) {
|
if (data.code == 200 || data.code == 0) {
|
||||||
// 仅当业务成功时,才弹成功提示
|
if (config.showMessage !== false) {
|
||||||
ElNotification({
|
ElNotification({
|
||||||
message: data.msg || '操作成功!',
|
message: data.msg || '操作成功!',
|
||||||
type: 'success',
|
type: 'success',
|
||||||
duration: 2000,
|
duration: 2000,
|
||||||
customClass: 'global-notification'
|
customClass: 'global-notification'
|
||||||
})
|
})
|
||||||
|
}
|
||||||
return data.data
|
return data.data
|
||||||
} else {
|
} else {
|
||||||
if (data.code === 1) {
|
if (data.code === 1) {
|
||||||
|
|
@ -155,12 +157,14 @@ const responseErrorInterceptor = (error: AxiosError) => {
|
||||||
errMsg = error.message || '服务器错误'
|
errMsg = error.message || '服务器错误'
|
||||||
}
|
}
|
||||||
|
|
||||||
ElNotification({
|
if (error.config?.showMessage !== false) {
|
||||||
message: errMsg,
|
ElNotification({
|
||||||
type: 'error',
|
message: errMsg,
|
||||||
duration: 2000,
|
type: 'error',
|
||||||
customClass: 'global-notification'
|
duration: 2000,
|
||||||
})
|
customClass: 'global-notification'
|
||||||
|
})
|
||||||
|
}
|
||||||
return Promise.reject(error)
|
return Promise.reject(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -169,12 +173,12 @@ service.interceptors.response.use(responseInterceptor, responseErrorInterceptor)
|
||||||
// 5. 封装通用请求方法
|
// 5. 封装通用请求方法
|
||||||
export const request = {
|
export const request = {
|
||||||
get<T = unknown>(url: string, params?: unknown, config?: InternalAxiosRequestConfig): Promise<T> {
|
get<T = unknown>(url: string, params?: unknown, config?: InternalAxiosRequestConfig): Promise<T> {
|
||||||
return service.get<ApiResponse<T>>(url, { params, ...config }).then((res) => {
|
return service.get<ApiResponse<T>>(url, { params, ...config,showMessage:false }).then((res) => {
|
||||||
return res as T;
|
return res as T;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
post<T = unknown>(url: string, data?: unknown, config?: InternalAxiosRequestConfig): Promise<T> {
|
post<T = unknown>(url: string, data?: unknown, config?: InternalAxiosRequestConfig): Promise<T> {
|
||||||
return service.post<ApiResponse<T>>(url, data, config).then((res) => {
|
return service.post<ApiResponse<T>>(url, data, {config,showMessage: true,}).then((res) => {
|
||||||
return res as T;
|
return res as T;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue