| | |
| | | // 创建 |
| | | const request = axios.create({ |
| | | baseURL: baseUrl, |
| | | timeout: 8000, // 超时时间 |
| | | timeout: 8000000, // 超时时间 |
| | | // withCredentials: true, |
| | | headers: { |
| | | 'Content-Type': 'application/json;charset=UTF-8', |
| | |
| | | // 拦截请求 |
| | | request.interceptors.request.use(config => { |
| | | if (config.loading) { |
| | | Toast.loading({ duration: 0, forbidClick: true }) |
| | | // Toast.loading({ duration: 0, forbidClick: true }) |
| | | } |
| | | //if (store?.state?.user?.userInfo?.token) { |
| | | if (store.state.user.userInfo.token != undefined && store.state.user.userInfo.token !== '') { |
| | |
| | | // 拦截响应 |
| | | request.interceptors.response.use(res => { // 200开头的 |
| | | if (res.config.loading) { |
| | | Toast.clear() |
| | | // Toast.clear() |
| | | } |
| | | |
| | | // console.log(res); |
| | |
| | | // break; |
| | | default: |
| | | if (msg != undefined) { |
| | | Toast.fail({ |
| | | // icon: 'none', |
| | | message: i18n.t(msg) |
| | | }); |
| | | // Toast.fail({ |
| | | // // icon: 'none', |
| | | // message: i18n.t(msg) |
| | | // }); |
| | | } |
| | | //console.log('错误') |
| | | return Promise.reject(res.data) |
| | | } |
| | | }, error => { |
| | | if (error.code == 'ERR_NETWORK') { |
| | | Toast({ message: 'ERR_NETWORK', type: 'fail', duration: 1000 }) |
| | | // Toast({ message: 'ERR_NETWORK', type: 'fail', duration: 1000 }) |
| | | } else if (error.code == 'ECONNABORTED') { |
| | | //Toast({ message: 'Network Timeout', type: 'fail', duration: 2000 }) |
| | | return Promise.reject(error); |