|
@@ -1,5 +1,5 @@
|
|
|
import axios from 'axios'
|
|
|
-//import store from '@/store'
|
|
|
+import store from '@/store'
|
|
|
import { MessageBox } from 'element-ui'
|
|
|
|
|
|
var CancelToken = axios.CancelToken
|
|
@@ -17,55 +17,55 @@ const axiosservice = axios.create({
|
|
|
})
|
|
|
})
|
|
|
|
|
|
-// axiosservice.interceptors.request.use(
|
|
|
-// config => {
|
|
|
-// config.withCredentials = true // 允许携带token ,这个是解决跨域产生的相关问题
|
|
|
-// let token = store.getters['ssoToken']
|
|
|
-// if (token) {
|
|
|
-// config.headers = {
|
|
|
-// 'sso-token': token
|
|
|
-// }
|
|
|
-// }
|
|
|
-// return config
|
|
|
-// },
|
|
|
-// error => {
|
|
|
-// return Promise.reject(error)
|
|
|
-// }
|
|
|
-// )
|
|
|
+axiosservice.interceptors.request.use(
|
|
|
+ config => {
|
|
|
+ config.withCredentials = true // 允许携带token ,这个是解决跨域产生的相关问题
|
|
|
+ let token = store.getters['token']
|
|
|
+ if (token) {
|
|
|
+ config.headers = {
|
|
|
+ 'sso-token': token
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return config
|
|
|
+ },
|
|
|
+ error => {
|
|
|
+ return Promise.reject(error)
|
|
|
+ }
|
|
|
+)
|
|
|
|
|
|
-// axiosservice.interceptors.response.use(
|
|
|
-// function(res) {
|
|
|
-// //在这里对返回的数据进行处理
|
|
|
-// //console.log('axios interceptors res = ', res.status, res)
|
|
|
-// let resp = res.data
|
|
|
-// if (resp.result === 'unauthc') {
|
|
|
-// store.commit('logined', false)
|
|
|
-// MessageBox.confirm('未登陆或登陆信息已失效, 是否重新登陆?', '提示', {
|
|
|
-// confirmButtonText: '确定',
|
|
|
-// cancelButtonText: '取消',
|
|
|
-// type: 'error'
|
|
|
-// })
|
|
|
-// .then(resp => {
|
|
|
-// //console.log('--------------------------- confirm', resp)
|
|
|
-// //router.push('/login')
|
|
|
-// window.location.reload()
|
|
|
-// })
|
|
|
-// .catch(error => {
|
|
|
-// //console.log('--------------------------- cancel', error)
|
|
|
-// console.log('')
|
|
|
-// })
|
|
|
-// } else if (resp.result == 'unauthorization') {
|
|
|
-// MessageBox.alert('无权操作', { title: '警告', type: 'error' })
|
|
|
-// }
|
|
|
-// //console.log('axios interceptors resp2 = ', resp.success, resp.errorCode, resp.errorMessage, res)
|
|
|
-// return res
|
|
|
-// },
|
|
|
-// function(err) {
|
|
|
-// //Do something with response error
|
|
|
-// console.log('axios interceptors err = ', err)
|
|
|
-// return Promise.reject(err)
|
|
|
-// }
|
|
|
-// )
|
|
|
+axiosservice.interceptors.response.use(
|
|
|
+ function(res) {
|
|
|
+ //在这里对返回的数据进行处理
|
|
|
+ //console.log('axios interceptors res = ', res.status, res)
|
|
|
+ let resp = res.data
|
|
|
+ if (resp.result === 'unauthc') {
|
|
|
+ store.commit('logined', false)
|
|
|
+ MessageBox.confirm('未登陆或登陆信息已失效, 是否重新登陆?', '提示', {
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ type: 'error'
|
|
|
+ })
|
|
|
+ .then(resp => {
|
|
|
+ //console.log('--------------------------- confirm', resp)
|
|
|
+ //router.push('/login')
|
|
|
+ window.location.reload()
|
|
|
+ })
|
|
|
+ .catch(error => {
|
|
|
+ //console.log('--------------------------- cancel', error)
|
|
|
+ console.log('')
|
|
|
+ })
|
|
|
+ } else if (resp.result == 'unauthorization') {
|
|
|
+ MessageBox.alert('无权操作', { title: '警告', type: 'error' })
|
|
|
+ }
|
|
|
+ //console.log('axios interceptors resp2 = ', resp.success, resp.errorCode, resp.errorMessage, res)
|
|
|
+ return res
|
|
|
+ },
|
|
|
+ function(err) {
|
|
|
+ //Do something with response error
|
|
|
+ console.log('axios interceptors err = ', err)
|
|
|
+ return Promise.reject(err)
|
|
|
+ }
|
|
|
+)
|
|
|
|
|
|
/* 下载方法 */
|
|
|
function downFile(blob, fileName) {
|