12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- import Vue from 'vue';
- import axios from 'axios';
- import VueAxios from 'vue-axios';
- // axios.defaults.headers.post['Content-Type'] = 'application/json';
- axios.defaults.transformRequest = [function (data) {
- if (data instanceof Object && !(data instanceof FormData)) {
- data = JSON.stringify(data)
- }
- return data;
- }],
- // 添加请求拦截器
- axios.interceptors.request.use(function (config) {
- let localhost = ''
- if (process.env.NODE_ENV == "production") {
- localhost = window.staticHost ? window.staticHost : "/spfm/"
- }
- config.url = localhost + config.url
- let url = localhost + config.url
- if (url.indexOf('/sysmgr/sys/login/auth/captcha') == -1 && url.indexOf('/sysmgr/sys/login/auth/token') == -1) {
- let token = window.sessionStorage.agileauthtoken;
- if (token != undefined && token != 'undefined') {
- token = JSON.parse(token);
- config.headers['agileauthtoken'] = token
- } else {
- global.$vm.$notify.error({
- title: '提示',
- message: '登录超时'
- })
- global.$vm.$router.push('/login')
- }
- }
- // 在发送请求之前做些什么
- return config;
- }, function (error) {
- // 对请求错误做些什么
- return Promise.reject(error);
- });
- // // 添加响应拦截器
- // axios.interceptors.response.use(function(response) {
- // if(response.data.ret != 0){
- // global.$vm.$notify.error({
- // title:'提示',
- // message:response.data.msg
- // })
- // }
- // // 对响应数据做点什么
- // return response;
- // }, function(error) {
- // try{
- // if(error.response.status==401){
- // global.$vm.$notify.error({
- // title:'提示',
- // message:'登录超时'
- // })
- // global.$vm.$router.push('/login')
- // }else if(error.response.status==404){
- // global.$vm.$notify.error({
- // title:'提示',
- // message:'请求接口不存在'
- // })
- // }else{
- // global.$vm.$notify.error({
- // title:'提示',
- // message:'服务器异常'
- // })
- // }
- // }catch{
- // //TODO handle the exception
- // }
- // // 对响应错误做点什么
- // return {
- // data:{
- // ret:-1,
- // msg:error.message,
- // data:error.response.data
- // },
- // status: error.response.status
- // };
- // });
- Vue.use(VueAxios, axios)
- export default axios;
|