|
|
@@ -2,7 +2,8 @@ import axios from 'axios'
|
|
2
|
2
|
import { MessageBox, Message } from 'element-ui'
|
|
3
|
3
|
import store from '@/store'
|
|
4
|
4
|
import { getToken } from '@/utils/auth'
|
|
5
|
|
-import { closenewWebSocket,newWebSocket } from '@/api/sendMessageSocket'
|
|
|
5
|
+import { closenewWebSocket, newWebSocket } from '@/api/sendMessageSocket'
|
|
|
6
|
+
|
|
6
|
7
|
|
|
7
|
8
|
// create an axios instance
|
|
8
|
9
|
const service = axios.create({
|
|
|
@@ -89,7 +90,7 @@ service.interceptors.response.use(
|
|
89
|
90
|
|
|
90
|
91
|
// 走框架接口,会先在这里拿到服务器返回的数据,如果出现请求超时,或者token获取,或者一些公共错误,可以在这里判断拦截,然后在返回
|
|
91
|
92
|
|
|
92
|
|
-
|
|
|
93
|
+
|
|
93
|
94
|
|
|
94
|
95
|
// if the custom code is not 20000, it is judged as an error.
|
|
95
|
96
|
// if (res.code !== 20000) {
|
|
|
@@ -99,18 +100,18 @@ service.interceptors.response.use(
|
|
99
|
100
|
// duration: 5 * 1000
|
|
100
|
101
|
// })
|
|
101
|
102
|
|
|
102
|
|
- // 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
|
|
103
|
|
- if (res.code === 50008 || res.code === 50012 || res.code === 50014) {
|
|
104
|
|
- // to re-login
|
|
105
|
|
- MessageBox.confirm('You have been logged out, you can cancel to stay on this page, or log in again', 'Confirm logout', {
|
|
106
|
|
- confirmButtonText: 'Re-Login',
|
|
107
|
|
- cancelButtonText: 'Cancel',
|
|
108
|
|
- type: 'warning'
|
|
109
|
|
- }).then(() => {
|
|
110
|
|
- store.dispatch('user/resetToken').then(() => {
|
|
111
|
|
- location.reload()
|
|
112
|
|
- })
|
|
|
103
|
+ // 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
|
|
|
104
|
+ if (res.code === 50008 || res.code === 50012 || res.code === 50014) {
|
|
|
105
|
+ // to re-login
|
|
|
106
|
+ MessageBox.confirm('You have been logged out, you can cancel to stay on this page, or log in again', 'Confirm logout', {
|
|
|
107
|
+ confirmButtonText: 'Re-Login',
|
|
|
108
|
+ cancelButtonText: 'Cancel',
|
|
|
109
|
+ type: 'warning'
|
|
|
110
|
+ }).then(() => {
|
|
|
111
|
+ store.dispatch('user/resetToken').then(() => {
|
|
|
112
|
+ location.reload()
|
|
113
|
113
|
})
|
|
|
114
|
+ })
|
|
114
|
115
|
// }
|
|
115
|
116
|
return Promise.reject(new Error(res.message || 'Error'))
|
|
116
|
117
|
} else {
|
|
|
@@ -119,7 +120,7 @@ service.interceptors.response.use(
|
|
119
|
120
|
},
|
|
120
|
121
|
error => {
|
|
121
|
122
|
// console.log(JSON.stringify(error), "mmmmm")
|
|
122
|
|
-
|
|
|
123
|
+
|
|
123
|
124
|
// Message({
|
|
124
|
125
|
// message: error.message,
|
|
125
|
126
|
// type: 'error',
|
|
|
@@ -127,21 +128,40 @@ service.interceptors.response.use(
|
|
127
|
128
|
// })
|
|
128
|
129
|
// return Promise.reject(error)
|
|
129
|
130
|
|
|
130
|
|
- if (error.response.status == 401&& store.state.isAuthority) {
|
|
|
131
|
+ // if (error.response.status == 401&& store.state.isAuthority) {
|
|
|
132
|
+ // store.state.isAuthority = false;
|
|
|
133
|
+ // MessageBox.confirm('身份失效,请重新登录', '确认退出', {
|
|
|
134
|
+ // confirmButtonText: '确定',
|
|
|
135
|
+ // cancelButtonText: '取消',
|
|
|
136
|
+ // type: 'warning'
|
|
|
137
|
+ // }).then(() => {
|
|
|
138
|
+ // store.dispatch('user/resetToken').then(() => {
|
|
|
139
|
+ // location.reload()
|
|
|
140
|
+ // })
|
|
|
141
|
+ // closenewWebSocket(JSON.parse(getUser()).uid)
|
|
|
142
|
+ // })
|
|
|
143
|
+ // }
|
|
|
144
|
+
|
|
|
145
|
+ if (error.response.status == 401 && store.state.isAuthority) {
|
|
|
146
|
+
|
|
131
|
147
|
store.state.isAuthority = false;
|
|
132
|
|
- MessageBox.confirm('身份失效,请重新登录', '确认退出', {
|
|
|
148
|
+
|
|
|
149
|
+ MessageBox.alert('身份失效,请重新登录', '确认退出', {
|
|
133
|
150
|
confirmButtonText: '确定',
|
|
134
|
|
- cancelButtonText: '取消',
|
|
135
|
|
- type: 'warning'
|
|
136
|
|
- }).then(() => {
|
|
137
|
|
- store.dispatch('user/resetToken').then(() => {
|
|
138
|
|
- location.reload()
|
|
139
|
|
- })
|
|
140
|
|
- closenewWebSocket(JSON.parse(getUser()).uid)
|
|
|
151
|
+ callback:()=>{
|
|
|
152
|
+
|
|
|
153
|
+ store.dispatch('user/resetToken')
|
|
|
154
|
+ .then(() => {
|
|
|
155
|
+ location.reload()
|
|
|
156
|
+ })
|
|
|
157
|
+ closenewWebSocket(JSON.parse(getUser()).uid)
|
|
|
158
|
+ console.log("我到这儿le.....s")
|
|
|
159
|
+ }
|
|
|
160
|
+
|
|
141
|
161
|
})
|
|
142
|
|
- }else if(error.response.status == 666&& store.state.isAuthority){
|
|
|
162
|
+ }else if (error.response.status == 666 && store.state.isAuthority) {
|
|
143
|
163
|
this.$message.error('服务器神游中!');
|
|
144
|
|
- }else if(error.response.status == 504&& store.state.isAuthority){
|
|
|
164
|
+ } else if (error.response.status == 504 && store.state.isAuthority) {
|
|
145
|
165
|
this.$message.error('请求超时,请稍后再试');
|
|
146
|
166
|
}
|
|
147
|
167
|
}
|