1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- import Vue from 'vue'
- import axios from 'axios'
- import store from '@/store'
- import notification from 'ant-design-vue/es/notification'
- import { VueAxios } from './axios'
- import { ACCESS_TOKEN } from '@/store/mutation-types'
- console.log(process.env.VUE_APP_PRO_NAME)
- const service = axios.create({
- baseURL: process.env.VUE_APP_API_BASE_URL,
- timeout: 60000
- })
- const err = (error) => {
- if (error.response) {
- const data = error.response.data
- if ((error.response.status == 403 || error.response.status == 401) && window.location.pathname != '/user/login') {
- notification.error({
- message: '提示',
- description: data.message
- })
- setTimeout(function () {
- store.dispatch('Logout').then(() => {
- window.location.reload()
- })
- }, 2000)
- }
- }
-
- if (error.message.indexOf('timeout') >= 0 && window.location.pathname != '/user/login') {
- notification.error({
- message: '提示',
- description: error.message
- })
- setTimeout(function () {
- store.dispatch('Logout').then(() => {
- window.location.reload()
- })
- }, 2000)
- }
- return Promise.reject(error)
- }
- service.interceptors.request.use(config => {
- const token = Vue.ls.get(ACCESS_TOKEN)
- if (token) {
-
- }
- return config
- }, err)
- service.interceptors.response.use((response) => {
-
- if (window.location.pathname != '/user/login') {
- if (response.data.status == '900') {
- notification.destroy()
- notification.error({
- message: '提示',
- description: response.data.message
- })
- }
- } else {
- if (response.data.status == '500') {
- notification.destroy()
- notification.error({
- message: '提示',
- description: response.data.message
- })
- }
- }
- return response.data
- }, err)
- const installer = {
- vm: {},
- install (Vue) {
- Vue.use(VueAxios, service)
- }
- }
- export {
- installer as VueAxios,
- service as axios
- }
|