|
@@ -7,6 +7,31 @@ import store from '@/store'
|
|
|
import {
|
|
import {
|
|
|
getToken
|
|
getToken
|
|
|
} from '@/utils/auth'
|
|
} from '@/utils/auth'
|
|
|
|
|
+import {Loading} from 'element-ui'
|
|
|
|
|
+const loading={
|
|
|
|
|
+ loadingInstance:null,
|
|
|
|
|
+ // 打开加载
|
|
|
|
|
+ open(){
|
|
|
|
|
+ if(this.loadingInstance===null){
|
|
|
|
|
+ this.loadingInstance=Loading.service({
|
|
|
|
|
+ text:'加载中...', //加载图标下的文字
|
|
|
|
|
+ spinner:'el-icon-loading', //加载图标
|
|
|
|
|
+ // background:'rgba(0,0,0,0.8)', //背景色
|
|
|
|
|
+ customClass:'loading' //自定义样式的类名
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ // 关闭加载
|
|
|
|
|
+ close(){
|
|
|
|
|
+ if(this.loadingInstance!==null){
|
|
|
|
|
+ this.loadingInstance.close()
|
|
|
|
|
+ }
|
|
|
|
|
+ this.loadingInstance=null
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
|
|
|
// create an axios instance
|
|
// create an axios instance
|
|
|
const service = axios.create({
|
|
const service = axios.create({
|
|
@@ -20,6 +45,7 @@ const service = axios.create({
|
|
|
})
|
|
})
|
|
|
service.interceptors.request.use(
|
|
service.interceptors.request.use(
|
|
|
config => {
|
|
config => {
|
|
|
|
|
+ loading.open()
|
|
|
const token = getToken()
|
|
const token = getToken()
|
|
|
if (token) {
|
|
if (token) {
|
|
|
config.headers.Authorization = token
|
|
config.headers.Authorization = token
|
|
@@ -75,6 +101,7 @@ service.interceptors.response.use(
|
|
|
* You can also judge the status by HTTP Status Code
|
|
* You can also judge the status by HTTP Status Code
|
|
|
*/
|
|
*/
|
|
|
response => {
|
|
response => {
|
|
|
|
|
+ loading.close()
|
|
|
const res = response.data
|
|
const res = response.data
|
|
|
// if the custom code is not 20000, it is judged as an error.
|
|
// if the custom code is not 20000, it is judged as an error.
|
|
|
// if (res.code !== 200) {
|
|
// if (res.code !== 200) {
|