diff --git a/src/api/index.ts b/src/api/index.ts index 4b058c8..7355a6d 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -79,6 +79,7 @@ service.interceptors.request.use(requestInterceptor, requestErrorInterceptor) const responseInterceptor = (response: AxiosResponse>) => { //关闭loading(无论成功失败都要关) hideLoading() + const config = response.config if (response.headers['new_token'] !== undefined) { setStorage('token', response.headers['new_token'] as string) } @@ -87,13 +88,14 @@ const responseInterceptor = (response: AxiosResponse console.log('响应数据data', data) // 判断业务状态码 if (data.code == 200 || data.code == 0) { - // 仅当业务成功时,才弹成功提示 - ElNotification({ - message: data.msg || '操作成功!', - type: 'success', - duration: 2000, - customClass: 'global-notification', - }) + if (config.showMessage !== false) { + ElNotification({ + message: data.msg || '操作成功!', + type: 'success', + duration: 2000, + customClass: 'global-notification' + }) + } return data.data } else { switch (data.code) { @@ -156,12 +158,14 @@ const responseErrorInterceptor = (error: AxiosError) => { errMsg = error.message || '服务器错误' } - ElNotification({ - message: errMsg, - type: 'error', - duration: 2000, - customClass: 'global-notification', - }) + if (error.config?.showMessage !== false) { + ElNotification({ + message: errMsg, + type: 'error', + duration: 2000, + customClass: 'global-notification' + }) + } return Promise.reject(error) } @@ -170,14 +174,14 @@ service.interceptors.response.use(responseInterceptor, responseErrorInterceptor) // 5. 封装通用请求方法 export const request = { get(url: string, params?: unknown, config?: InternalAxiosRequestConfig): Promise { - return service.get>(url, { params, ...config }).then((res) => { - return res as T - }) + return service.get>(url, { params, ...config,showMessage:false }).then((res) => { + return res as T; + }); }, post(url: string, data?: unknown, config?: InternalAxiosRequestConfig): Promise { - return service.post>(url, data, config).then((res) => { - return res as T - }) + return service.post>(url, data, {config,showMessage: true,}).then((res) => { + return res as T; + }); }, } diff --git a/src/components/layout/Sidebar.vue b/src/components/layout/Sidebar.vue index 0691b59..6106b2a 100644 --- a/src/components/layout/Sidebar.vue +++ b/src/components/layout/Sidebar.vue @@ -7,16 +7,16 @@ - - -