Преглед на файлове

修改长时间未操作,点击病案详情只提示请先登录不退出登录页的问题

liyanyan преди 1 седмица
родител
ревизия
23961b0a0b
променени са 1 файла, в които са добавени 13 реда и са изтрити 2 реда
  1. 13 2
      src/utils/request.js

+ 13 - 2
src/utils/request.js

@@ -1,7 +1,8 @@
 import axios from 'axios';
 import { MessageBox, Message } from 'element-ui';
 import store from '@/store';
-import { getToken } from '@/utils/auth';
+import { getToken, removeToken } from '@/utils/auth';
+import router from '@/router'
 
 // create an axios instance
 const service = axios.create({
@@ -44,7 +45,17 @@ service.interceptors.response.use(
   response => {
     const res = response.data;
     // if the custom code is not 20000, it is judged as an error.
-    if (res.code !== 200) {
+    if(res.code == -1) {
+      Message({
+        message: `${res.msg}`,
+        type: 'error',
+        duration: 5 * 1000,
+      });
+      removeToken()
+      router.push({path:`/login`})
+      return
+    }
+    else if (res.code !== 200) {
       Message({
         message: res.msg || 'Error2',
         type: 'error',