|
|
@@ -4,6 +4,8 @@ import qs from 'qs' |
|
|
|
import 'vue2-toast/lib/toast.css' |
|
|
|
import Toast from 'vue2-toast' |
|
|
|
import store from '@/store' |
|
|
|
import {guid} from "./util"; |
|
|
|
import md5 from 'js-md5'; |
|
|
|
|
|
|
|
// import { Spin } from 'iview' |
|
|
|
Vue.use(Toast) |
|
|
@@ -41,10 +43,18 @@ class HttpRequest { |
|
|
|
if (!Object.keys(this.queue).length) { |
|
|
|
// Spin.show() // 不建议开启,因为界面不友好 |
|
|
|
} |
|
|
|
let accesstoken = 'aaaa09f1bc6305d06a7307c698ca2403' |
|
|
|
let timestamp = new Date().getTime() |
|
|
|
let nonce = guid() |
|
|
|
let secret = 'a7d1c64a82e5105e7a9e6713478a2a66' |
|
|
|
config.headers['x-dj-accesstoken'] = accesstoken |
|
|
|
config.headers['x-dj-timestamp'] = timestamp |
|
|
|
config.headers['x-dj-nonce'] = nonce |
|
|
|
config.headers['x-dj-signature'] = md5(accesstoken+secret+timestamp+nonce) |
|
|
|
config.headers['X-Requested-With'] = 'XMLHttpRequest' |
|
|
|
if (store.state.user.id_token) { |
|
|
|
/*if (store.state.user.id_token) { |
|
|
|
config.headers['Authorization'] = 'Bearer ' + store.state.user.id_token |
|
|
|
} |
|
|
|
}*/ |
|
|
|
this.queue[url] = true |
|
|
|
return config |
|
|
|
}, error => { |
|
|
@@ -53,6 +63,7 @@ class HttpRequest { |
|
|
|
// 响应拦截 |
|
|
|
instance.interceptors.response.use(res => { |
|
|
|
this.distroy(url) |
|
|
|
console.log(res) |
|
|
|
if (res.status === 200 || res.data.success) { |
|
|
|
return Promise.resolve(res.data) |
|
|
|
} else { |
|
|
@@ -60,7 +71,7 @@ class HttpRequest { |
|
|
|
} |
|
|
|
}, error => { |
|
|
|
this.distroy(url) |
|
|
|
console.log(JSON.stringify(error)) |
|
|
|
console.log(error) |
|
|
|
if (error && error.response) { |
|
|
|
switch (error.response.status) { |
|
|
|
case 400: |
|
|
|