Просмотр исходного кода

fix:修改退出登录一直提示token过期的问题

mlchen 1 день назад
Родитель
Сommit
06f5132218
4 измененных файлов с 12 добавлено и 7 удалено
  1. 3 2
      src/App.vue
  2. 3 1
      src/api/system/user/index.js
  3. 3 4
      src/layout/components/header-tools.vue
  4. 3 0
      src/utils/request.js

+ 3 - 2
src/App.vue

@@ -7,17 +7,18 @@
 <script>
   import { updateDocumentTitle } from '@/utils/document-title-util';
   import { getPathAddress } from '@/api/system/file/index';
+  import { getToken } from '@/utils/token-util';
   export default {
     name: 'App',
     created() {
       console.log('我是子应用-----------');
       // 恢复主题
       this.$store.dispatch('theme/recoverTheme');
-      if (!sessionStorage.filePath) {
+      if (getToken() && !sessionStorage.filePath) {
         getPathAddress().then((res) => {
           console.log(res);
           sessionStorage.filePath = res;
-        });
+        }).catch(() => {});
       }
     },
     methods: {

+ 3 - 1
src/api/system/user/index.js

@@ -63,7 +63,9 @@ export async function updatePassword (params) {
 
 // 退出登录
 export async function userLogout (params) {
-  const res = await request.post('/main/user/logout', params);
+  const res = await request.post('/main/user/logout', params, {
+    showErrorToast: false
+  });
   if (res.data.code == 0) {
     return res.data;
   }

+ 3 - 4
src/layout/components/header-tools.vue

@@ -172,10 +172,9 @@ export default {
           { type: 'warning' }
         )
           .then(() => {
-            userLogout().then((res) => {
-              localStorage.removeItem('userId');
-              logout();
-            });
+            userLogout().catch(() => {});
+            localStorage.removeItem('userId');
+            logout();
           })
           .catch(() => {});
       }

+ 3 - 0
src/utils/request.js

@@ -63,6 +63,9 @@ service.interceptors.response.use(
     console.log(error,'error')
     if (error?.response?.status === 401) {
       const currentPath = router.currentRoute.path;
+      if (!getToken() || currentPath === '/login') {
+        return Promise.reject(error);
+      }
       // if (currentPath === LAYOUT_PATH) {
       //   logout(true);
       // } else {