MrShi
2025-08-19 30e858fa504b268b9b436afca0a1259cf6e8c488
admin/src/utils/request/index.js
@@ -3,13 +3,14 @@
import pkg from '../../../package'
import { trim } from '@/utils/util'
import extendsMethods from './extends.methods'
import { decryptedData } from './decryption.js'
// 默认配置
axios.defaults.headers.common['Content-Type'] = 'application/json;charset=UTF-8'
const axiosInstance = axios.create({
  baseURL: process.env.VUE_APP_API_PREFIX,
  // 请求超时时间
  timeout: 60000
  timeout: 600000
})
// 新建请求拦截器
@@ -23,6 +24,10 @@
      config.params = trim(config.params)
    }
  }
  if (config.ivKey) {
    config.headers.secretKey = config.ivKey
  }
  // config.headers['Content-Type'] = config.contentType || 'application/json;charset=UTF-8'
  // 导出处理
  if (config.download === true) {
    config.responseType = 'blob'
@@ -52,7 +57,7 @@
  // 未登录
  if (response.data.code === 401) {
    if (response.config.autoLogin !== false) {
      window.location.href = process.env.VUE_APP_ROUTER_MODE === 'history' ? '/#/login' : '/login'
      window.location.href = process.env.VUE_APP_ROUTER_MODE === 'hash' ? (process.env.VUE_APP_CONTEXT_PATH + '/#/login') : (process.env.VUE_APP_CONTEXT_PATH + '/login')
    }
    return Promise.reject(response.data)
  }
@@ -60,6 +65,16 @@
  if (!response.data.success) {
    return Promise.reject(response.data)
  }
  if (response.data.message) {
    const tm = response.data.message
    const list = tm.split(' ')
    let msg = list[0]
    if (list.length > 1 && response.data.data) {
      msg = decryptedData(list[1], list[0])
      response.data.data = decryptedData(list[1], response.data.data)
      response.data.message = msg
    }
  }
  return response.data.data
}, function (error) {
  console.log('error', error)