Browse Source

别的系统账号登录时报错处理

chenrui 4 years ago
parent
commit
45285073a4
2 changed files with 20 additions and 18 deletions
  1. 1 1
      src/store/modules/user.js
  2. 19 17
      src/utils/request.js

+ 1 - 1
src/store/modules/user.js

@@ -40,7 +40,7 @@ const user = {
       return new Promise((resolve, reject) => {
         login(userInfo).then(res => {
           console.log(res, 'login success')
-          if (res.userid) {
+          if (res && res.userid) {
             Vue.ls.set('hasError', 0)
             commit('SET_TOKEN', res.userid)
             commit('SET_NAME', { name: res.userNameCN, welcome: welcome() })

+ 19 - 17
src/utils/request.js

@@ -15,6 +15,7 @@ const err = (error) => {
   if (error.response) {
     const data = error.response.data
     if ((error.response.status == 403 || error.response.status == 401) && window.location.pathname != '/user/login') {
+      notification.destroy()
       notification.error({
         message: '提示',
         description: data.message
@@ -28,6 +29,7 @@ const err = (error) => {
   }
   // 超时无法访问服务
   if (error.message.indexOf('timeout') >= 0 && window.location.pathname != '/user/login') {
+    notification.destroy()
     notification.error({
       message: '提示',
       description: error.message
@@ -52,25 +54,25 @@ service.interceptors.request.use(config => {
 
 // response interceptor
 service.interceptors.response.use((response) => {
-  console.log(response, 'responseresponseresponse')
-  if (response.data.status == '-1') {
-    notification.error({
-      message: '提示',
-      description: response.data.message
-    })
-    setTimeout(function () {
-      store.dispatch('Logout').then(() => {
-        window.location.reload()
+  console.log(response, response.data.status, 'responseresponseresponse')
+  if (window.location.pathname != '/user/login') {
+    if (response.data.status == '900') {
+      notification.destroy()
+      notification.error({
+        message: '提示',
+        description: response.data.message
       })
-    }, 2000)
-  }
-  if ((response.data.status == '900') && window.location.pathname != '/user/login') {
-    notification.destroy()
-    notification.error({
-      message: '提示',
-      description: response.data.message
-    })
+    }
+  } else {
+    if (response.data.status == '500') {
+      notification.destroy()
+      notification.error({
+        message: '提示',
+        description: response.data.message
+      })
+    }
   }
+
   return response.data
 }, err)