aRequest.js 2 KB
Newer Older
1 2
import axios from 'axios'
import { Message, MessageBox } from 'element-ui'
Z's avatar
Z committed
3
import Router from '../router'
xulili's avatar
xulili committed
4
import envConfig from '@/config/env-config'
5 6 7
// import store from '../store'
// import { getToken } from '@/utils/auth'

Z's avatar
Z committed
8 9 10
// const testEnv = require('../../config/dev.env')
// Z-BasicInfo
let INFO = {
11 12 13 14
  // corpId: 'wwd1cdbca7b8b2b6c4',
  // agentId: '1000015',
  corpId: 'ww4df265003b43fa0d',
  agentId: '1000032',
xulili's avatar
xulili committed
15 16
  // url: 'http://139.155.48.151:8085',
  url: envConfig.appBaseUrlA,
Z's avatar
Z committed
17 18
}

19 20
// 创建axios实例
const service = axios.create({
Z's avatar
Z committed
21
  baseURL: INFO.url, // api 的 base_url
22 23 24 25 26 27 28 29
  timeout: 50000 // 请求超时时间
})

// request拦截器
service.interceptors.request.use(
  (config) => {
    if (sessionStorage['token']) {
      config.headers['token'] = sessionStorage['token']
Z's avatar
Z committed
30
      config.headers['businessId'] = sessionStorage['businessId']
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
    } else {
      config.headers['businessId'] = '10'
    }
    return config;
  },
  (error) => {
    Promise.reject(error)
  }
)

// response 拦截器
service.interceptors.response.use(
  response => {
    console.log(response)
    if(response.status == 200) {
      return response.data
    } else {
      Message({
        message: response.data.msg,
        type: 'error',
        duration: 5 * 1000
      })
    }
    // let loadingSetting = Loading.service({
    //   fullscreen: true,
    //   lock: true,
    //   background: 'rgba(0,0,0,0.4)',
    //   text: '正在加载',
    //   spinner: 'el-icon-loading'
    // })
    // endLoading(loadingSetting)
    // if (response.errorCode == '1001') {
    //   Router.push({ path: "/login" });
    // }
  },
  error => {
    console.log(error)
    // console.log('err' + error) // for debug
    // Message({
    //   message: error.message,
    //   type: 'error',
    //   duration: 50 * 1000
    // })
    // return Promise.reject(error)
  }
)
// function endLoading (loading) {
//   store.commit('LOADING', false)
//   loading.close()
// }

// function startLoding () {
//   store.commit('LOADING', true)
// }
export default service