export function BelDownload ( data) { return request ( { url: '/url' , method: 'post' , responseType: 'blob' , data, } )
}
import axios from 'axios' ;
import qs from 'qs' ;
const request = axios. create ( { baseURL: process. env. VUE_APP_API_BASE_URL, timeout: 40000000 , paramsSerializer: ( params) = > qs. stringify ( params, { indices: false } ) ,
} ) ;
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 ) ; } ) ; } } Message. error ( error. message) ; } return Promise. reject ( error) ;
} ;
request. interceptors. request. use ( config = > { const token = storage. get ( ACCESS_TOKEN) ; config. headers[ 'userId' ] = "10510000" ; if ( token) { config. headers[ ACCESS_TOKEN] = token; } return config;
} , errorHandler) ; function getSSOUrl ( ssoUrl, targetUrl) { const ssoArr = ssoUrl. split ( '?' ) ; return ssoArr. length > 1 ? `${ ssoUrl} & target_url= ${ targetUrl} ` : `${ ssoUrl} ? target_url= ${ targetUrl} `;
}
request. interceptors. response. use ( ( response) = > { const { data = { } } = response. data; const { $message } = Vue. prototype; let ssoUrl = null; let modal = null; const interval = null; const secondsToGo = 3 ; if ( data) { switch ( data. code) { case '403' : if ( window. isSSO ( ) ) { if ( ! Cookies. get ( 'BW_LOCAL_COOKIE_KEY' ) ) { window. location. href = getSSOUrl ( data. ssoUrl, window. location. href) ; } else { ssoUrl = getSSOUrl ( data. ssoUrl, window. location. href) ; notification. error ( { message: '未授权' , description: '用户权限已过期' } ) ; window. location. href = ssoUrl; } } break ; } } return response. data;
} , errorHandler) ; const installer = { vm: { } , install ( Vue) { Vue. use ( VueAxios, request) ; }
} ; export default request; export { installer as VueAxios, request as axios
} ;