| 
					
				 | 
			
			
				@@ -1,15 +1,26 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import axios from 'axios' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import type { AxiosInstance, AxiosError, AxiosRequestConfig, InternalAxiosRequestConfig, AxiosResponse } from 'axios' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import { ElMessage } from 'element-plus' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import { ResultEnum, ResultData } from './interface/index' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import { ElMessage, ElLoading } from 'element-plus' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import { ResultEnum, ResultData, ContentType } from './interface/index' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import { GlobalStore } from '@/stores/index' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import { useRouter } from 'vue-router' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+const router = useRouter() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+const globalStore = GlobalStore() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+type LoadingType = { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  close?: () => void 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+let loadingInstance: LoadingType = {} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 const config = { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   // 默认地址请求地址,可在 .env.*** 文件中修改 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  baseURL: import.meta.env.VITE_API_URL as string, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  // baseURL: import.meta.env.VITE_BZD_ERP_APP_API as string, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   // 设置超时时间(10s) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   timeout: ResultEnum.TIMEOUT as number, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   // 跨域时候允许携带凭证 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  withCredentials: true 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  withCredentials: true, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  headers: { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    'Content-Type': ContentType.URLENCODED 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 class RequestHttp { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -25,6 +36,16 @@ class RequestHttp { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     this.service.interceptors.request.use( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       (config: InternalAxiosRequestConfig) => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 开始loading 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        loadingInstance = ElLoading.service({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          lock: true, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          text: 'Loading', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          background: 'rgba(0, 0, 0, 0.7)' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 加入token 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (globalStore.GET_User_tokey) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          config.headers['User_tokey'] = globalStore.GET_User_tokey 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return config 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       (err: any) => err 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -37,16 +58,16 @@ class RequestHttp { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     this.service.interceptors.response.use( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       (response: AxiosResponse) => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         const { data } = response 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        // const globalStore = GlobalStore() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // * 在请求结束后,并关闭请求 loading 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        // tryHideFullScreenLoading() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        loadingInstance.close && loadingInstance.close() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // * 登陆失效(code == 401) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        // if (data.code == ResultEnum.OVERDUE) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        //   ElMessage.error(data.msg) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        //   globalStore.setToken('') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        //   router.replace(LOGIN_URL) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        //   return Promise.reject(data) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        // } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (data.code == ResultEnum.OVERDUE) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          ElMessage.error(data.msg) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          globalStore.SET_User_Tokey('') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          router.replace('/login') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+          return Promise.reject(data) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // * 全局错误信息拦截(防止下载文件得时候返回数据流,没有code,直接报错) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (data.code && data.code !== ResultEnum.SUCCESS) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				           ElMessage.error(data.msg) 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -56,15 +77,10 @@ class RequestHttp { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return data 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       async (error: AxiosError) => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        // const { response } = error 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        // tryHideFullScreenLoading() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        loadingInstance.close && loadingInstance.close() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // 请求超时 && 网络错误单独判断,没有 response 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (error.message.indexOf('timeout') !== -1) ElMessage.error('请求超时!请您稍后重试') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (error.message.indexOf('Network Error') !== -1) ElMessage.error('网络错误!请您稍后重试') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        // 根据响应的错误状态码,做不同的处理 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        // if (response) checkStatus(response.status) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        // 服务器结果都没有返回(可能服务器错误可能客户端断网),断网处理:可以跳转到断网页面 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        // if (!window.navigator.onLine) router.replace('/500') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return Promise.reject(error) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     ) 
			 |