text: import store from '@/store'
  import {
    ACCESS_TOKEN
  } from '@/store/mutation-types'
  import notification from 'ant-design-vue/es/notification'
  import axios from 'axios'
  import Cookies from 'js-cookie'
  import {
    VueAxios
  } from './axios'
  
  // 创建 axios 实例
  const request = axios.create({
    // API 请求的默认前缀
    baseURL: '/hua',
    timeout: 30000 // 请求超时时间
  })
  
  // 异常拦截处理器
  const errorHandler = (error) => {
    if (error.response) {
      const data = error.response.data
      // 从 Cookies 获取 token
      const token = Cookies.get(ACCESS_TOKEN)
      if (error.response.status === 401 && !(data.result && data.result.isLogin)) {
        notification.error({
          message: 'Unauthorized',
          description: 'Authorization verification failed'
        })
        if (token) {
          store.dispatch('Logout').then(() => {
            setTimeout(() => {
              window.location.reload()
            }, 1500)
          })
        }
      } else if (error.response.status === 403) {
        notification.error({
          message: 'Forbidden',
          description: data.message
        })
      } else {
        // console.log(error.response)
        notification.error({
          message: data.status,
          description: data.error
        })
      }
      return Promise.reject(error)
    } else {
      notification.warning({
        message: 'warning',
        description: error.message
      })
      return Promise.reject(error)
    }
  }
  
  // request interceptor
  request.interceptors.request.use(config => {
    const token = Cookies.get(ACCESS_TOKEN)
    // 如果 token 存在
    // 让每个请求携带自定义 token 请根据实际情况自行修改
    // if (token) {
    //   config.headers['SessionKey'] = token
    // }
    return config
  }, errorHandler)
  
  // response interceptor
  request.interceptors.response.use((response) => {
    const data = response.data
    if (response.status === 200) {
      // if (data.status===200){
        return response.data
      // }else{
      //   notification.warning({
      //     message: 'warning',
      //     description: data.message
      //   })
      // }
    } else {
      notification.warning({
        message: 'warning',
        description: response.message
      })
    }
  }, errorHandler)
  
  const installer = {
    vm: {},
    install(Vue) {
      Vue.use(VueAxios, request)
    }
  }
  
  export default request
  
  export {
    installer as VueAxios,
    request as axios
  }