| | |
| | | |
| | | Vue.prototype.LOCATIONVUE = "http://127.0.0.1:80/"; //前端本地端口 |
| | | Vue.prototype.HaveJson = (val) => { |
| | | return JSON.parse(JSON.stringify(val)) |
| | | return JSON.parse(JSON.stringify(val)) |
| | | } |
| | | |
| | | Vue.use(VueAxios, axios) |
| | |
| | | Vue.use(qs); |
| | | Vue.use(api); |
| | | |
| | | // const javaApi = 'http://192.168.14.249:8001' |
| | | const javaApi = 'http://localhost:8001' |
| | | |
| | | const javaApi = 'http://127.0.0.1:8001/' |
| | | // const javaApi = 'http://127.0.0.1:8001/' |
| | | |
| | | |
| | | |
| | |
| | | Vue.prototype.$axios = axios |
| | | |
| | | import { |
| | | Message |
| | | Message |
| | | } from 'element-ui'; |
| | | axios.interceptors.request.use(function (config) { |
| | | let tk = sessionStorage.getItem("token") |
| | | let token; |
| | | if (tk != undefined && tk != '') { |
| | | token = tk |
| | | } |
| | | if (token) { |
| | | config.headers['token'] = "" + token |
| | | // config.headers['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8' |
| | | // config.headers['Content-Type'] = 'application/json' |
| | | } |
| | | // console.log(config) |
| | | if (config.method === 'post' || config.method === 'put') { |
| | | axios.interceptors.request.use(function(config) { |
| | | let tk = sessionStorage.getItem("token") |
| | | let token; |
| | | if (tk != undefined && tk != '') { |
| | | token = tk |
| | | } |
| | | if (token) { |
| | | config.headers['token'] = "" + token |
| | | // config.headers['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8' |
| | | // config.headers['Content-Type'] = 'application/json' |
| | | } |
| | | // console.log(config) |
| | | if (config.method === 'post' || config.method === 'put') { |
| | | |
| | | config.data = qs.stringify(config.data) |
| | | } |
| | | if (config.headers['Content-Type'] == 'application/json') { |
| | | config.data = qs.parse(config.data) |
| | | // console.log(config.data) |
| | | } |
| | | config.data = qs.stringify(config.data) |
| | | } |
| | | if (config.headers['Content-Type'] == 'application/json') { |
| | | config.data = qs.parse(config.data) |
| | | // console.log(config.data) |
| | | } |
| | | |
| | | |
| | | return config |
| | | }, function (error) { |
| | | return Promise.reject(error) |
| | | return config |
| | | }, function(error) { |
| | | return Promise.reject(error) |
| | | }) |
| | | |
| | | axios.interceptors.response.use(res => { |
| | | return res.data |
| | | }, async function (err) { |
| | | if (JSON.stringify(err).indexOf('timeout of') > -1) { |
| | | Message.error('请求超时,请检查网络设置') |
| | | } else if (JSON.stringify(err).indexOf('ERR_CONNECTION_RESET') > -1 || JSON.stringify(err).indexOf( |
| | | 'Network Error') > -1) { |
| | | Message.error('网络连接错误') |
| | | } else if (err.response.status == "503") { |
| | | Message.error('服务未响应') |
| | | } else if (err.response.status == "404") { |
| | | Message.error('请求失败,链接地址不存在') |
| | | } else if (err.response.status == "403") { |
| | | Message.error('token不存在') |
| | | } else if (err.response.status == "402") { |
| | | Message.error('无效签名,请重新登录') |
| | | localStorage.removeItem('autoenter') |
| | | window.location.href = '/enter' |
| | | } else if (err.response.status == "401") { |
| | | await axios.post(javaApi + "user/refresh", { |
| | | reToken: sessionStorage.getItem('reToken') |
| | | }).then(res => { |
| | | if (res.data.code == 201) { |
| | | Message.error('认证失败,需要重新登录') |
| | | localStorage.removeItem('autoenter') |
| | | window.location.href = '/enter' |
| | | return Promise.reject(err) |
| | | } |
| | | sessionStorage.setItem('token', res.data.token) |
| | | sessionStorage.setItem('reToken', res.data.reToken) |
| | | }) |
| | | return axios(err.config) |
| | | } else if (err.response.status == "500") { |
| | | Message.error('服务端出现错误') |
| | | } |
| | | return Promise.reject(err) |
| | | if(res.config.responseType === 'blob'){ |
| | | return res; |
| | | } |
| | | return res.data |
| | | }, async function(err) { |
| | | if (JSON.stringify(err).indexOf('timeout of') > -1) { |
| | | Message.error('请求超时,请检查网络设置') |
| | | } else if (JSON.stringify(err).indexOf('ERR_CONNECTION_RESET') > -1 || JSON.stringify(err).indexOf( |
| | | 'Network Error') > -1) { |
| | | Message.error('网络连接错误') |
| | | } else if (err.response.status == "503") { |
| | | Message.error('服务未响应') |
| | | } else if (err.response.status == "404") { |
| | | Message.error('请求失败,链接地址不存在') |
| | | } else if (err.response.status == "403") { |
| | | Message.error('token不存在') |
| | | } else if (err.response.status == "402") { |
| | | Message.error('无效签名,请重新登录') |
| | | localStorage.removeItem('autoenter') |
| | | window.location.href = '/enter' |
| | | } else if (err.response.status == "401") { |
| | | await axios.post(javaApi + "user/refresh", { |
| | | reToken: sessionStorage.getItem('reToken') |
| | | }).then(res => { |
| | | if (res.data.code == 201) { |
| | | Message.error('认证失败,需要重新登录') |
| | | localStorage.removeItem('autoenter') |
| | | window.location.href = '/enter' |
| | | return Promise.reject(err) |
| | | } |
| | | sessionStorage.setItem('token', res.data.token) |
| | | sessionStorage.setItem('reToken', res.data.reToken) |
| | | }) |
| | | return axios(err.config) |
| | | } else if (err.response.status == "500") { |
| | | Message.error('服务端出现错误') |
| | | } |
| | | return Promise.reject(err) |
| | | }) |
| | | |
| | | // 路由拦截器 |
| | |
| | | // }); |
| | | |
| | | new Vue({ |
| | | el: '#app', |
| | | router, |
| | | render: h => h(App) |
| | | el: '#app', |
| | | router, |
| | | render: h => h(App) |
| | | }); |