张延森 4 years ago
parent
commit
146f8c3b29
1 changed files with 24 additions and 10 deletions
  1. 24
    10
      src/utils/request.js

+ 24
- 10
src/utils/request.js View File

77
           dangerouslyUseHTMLString: true,
77
           dangerouslyUseHTMLString: true,
78
           duration: 5 * 1000
78
           duration: 5 * 1000
79
         })
79
         })
80
-      } else if (code === 50008 || code === 50012 || code === 50014) {
80
+      } else if (code === 401 || code === 50008 || code === 50012 || code === 50014) {
81
         // to re-login
81
         // to re-login
82
-        MessageBox.confirm('You have been logged out, you can cancel to stay on this page, or log in again', 'Confirm logout', {
83
-          confirmButtonText: 'Re-Login',
84
-          cancelButtonText: 'Cancel',
82
+        MessageBox.confirm('您已登出或者登录已过期', '确认登出', {
83
+          confirmButtonText: '重新登录',
84
+          cancelButtonText: '取消',
85
           type: 'warning'
85
           type: 'warning'
86
         }).then(() => {
86
         }).then(() => {
87
           store.dispatch('user/resetToken').then(() => {
87
           store.dispatch('user/resetToken').then(() => {
104
   },
104
   },
105
   error => {
105
   error => {
106
     console.log('err' + error) // for debug
106
     console.log('err' + error) // for debug
107
-    Message({
108
-      message: error.message,
109
-      type: 'error',
110
-      duration: 5 * 1000
111
-    })
112
-    return Promise.reject(error)
107
+
108
+    const response = error.response || {}
109
+    if (response.status === 401) {
110
+      MessageBox.confirm('您已登出或者登录已过期', '确认登出', {
111
+        confirmButtonText: '重新登录',
112
+        cancelButtonText: '取消',
113
+        type: 'warning'
114
+      }).then(() => {
115
+        store.dispatch('user/resetToken').then(() => {
116
+          location.reload()
117
+        })
118
+      })
119
+    } else {
120
+      Message({
121
+        message: error.message,
122
+        type: 'error',
123
+        duration: 5 * 1000
124
+      })
125
+      return Promise.reject(error)
126
+    }
113
   }
127
   }
114
 )
128
 )
115
 
129