123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- import axios from 'axios'
- import store from '@/store'
- import storage from 'store'
- import notification from 'ant-design-vue/es/notification'
- import { VueAxios } from './axios'
- import { ACCESS_TOKEN } from '@/store/mutation-types'
- const request = axios.create({
-
-
- baseURL: '/api',
- timeout: 6000
- })
- const errorHandler = (error) => {
- if (error.response) {
- const data = error.response.data
-
- const token = storage.get(ACCESS_TOKEN)
- if (error.response.status === 403) {
- notification.error({
- message: 'Forbidden',
- description: data.message
- })
- }
- 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)
- })
- }
- }
- }
- return Promise.reject(error)
- }
- request.interceptors.request.use(config => {
-
- const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b3duSWQiOiIyMTMyMTIxMjMyNDVMIiwiZXhwIjoxNjA5MzE4MzI3LCJ1c2VySWQiOiI4NTUxMjU0NDE1NTRMIn0.89pzAikvF29pRiIl0iF4FhGL1HK-K8l13NzIWF1VkwA'
-
-
- if (token) {
- config.headers['access_token'] = token
- }
- return config
- }, errorHandler)
- request.interceptors.response.use((response) => {
- return response.data
- }, errorHandler)
- const installer = {
- vm: {},
- install (Vue) {
- Vue.use(VueAxios, request)
- }
- }
- export default request
- export {
- installer as VueAxios,
- request as axios
- }
|