派生自 wuyushui/SewerAndRainNetwork

徐旺旺
2021-05-30 a312e0dd96d8f7e96fb3341f1a55561b12394405
src/utils/axios.js
@@ -2,7 +2,7 @@
import axios from 'axios'
import * as $CONST from '@/utils/constant'
import * as $T from '@/utils/tools'
import $store from '@/store'
// import $store from '@/store'
/**
 * 定义传入参数数据格式
@@ -83,7 +83,7 @@
// 创建axios实例
const Service = axios.create({
  timeout: 1000
  timeout: 1000 * 30
})
const CancelToken = axios.CancelToken
@@ -112,16 +112,16 @@
 }
 }
 return config
 }*/
 } */
// request拦截器
Service.interceptors.request.use(
  config => {
    // 临时追加
    if ($store.state.user.account) {
      config.headers.account = $store.state.user.account
    }
    let copyConfig = Object.assign({}, config)
    //   if ($store.state.user.account) {
    //     config.headers.account = $store.state.user.account
    //   }
    const copyConfig = Object.assign({}, config)
    // copyConfig = filterOauthData(copyConfig)
    // showDebugInfo(copyConfig)
    copyConfig.cancelToken = new CancelToken((c) => {
@@ -140,12 +140,13 @@
Service.interceptors.response.use(
  response => {
    const res = response.data
    if (Number(res.code) !== 200 && Number(res.code) !== 0) {
    /* if (Number(res.code) !== 200 && Number(res.code) !== 0) {
      $T.warning(res.message)
      return res
      return Promise.reject(res.message)
    } else {
      return res
    }
    } */
    return res
  },
  error => {
    if (error.message && error.message.includes('timeout')) {
@@ -178,7 +179,7 @@
const $http = {}
$http.$service = Service
$http.$axios = axios
$http.get = function(url, params = {}) {
$http.get = function (url, params = {}) {
  if ($T.isInlineParams(url)) {
    // 严格遵循restful标准的url的场景
    url = $T.replaceUrlParams(url, params)
@@ -190,21 +191,22 @@
    params: $T.filterParams(params)
  })
}
$http.post = function(url, data = {}) {
$http.post = function (url, data = {}, setHeaders) {
  return Service({
    url: url,
    method: 'post',
    data: data
    data: data,
    headers: setHeaders || { 'Content-Type': 'application/json; charset=UTF-8' }
  })
}
$http.put = function(url, data = {}) {
$http.put = function (url, data = {}) {
  return Service({
    url: url,
    method: 'put',
    data: data
  })
}
$http.delete = function(url, data = {}) {
$http.delete = function (url, data = {}) {
  return Service({
    url: url,
    method: 'delete',