Explorar el Código

feat: 页面加载时从storage读取用户头像和昵称;监听storage事件,发现token被删除时调起登录弹窗;重新登录后修改刷新页面的方法以确保能成功刷新。

任一存 hace 4 años
padre
commit
53b2490cc8
Se han modificado 3 ficheros con 5 adiciones y 16 borrados
  1. 0 1
      src/components/table/index.vue
  2. 3 5
      src/pages/material.js
  3. 2 10
      src/utils/request.js

+ 0 - 1
src/components/table/index.vue

@@ -128,7 +128,6 @@ export default {
   },
   mounted () {
     const resizeObserver = new ResizeObserver((entries) => {
-      console.log('asdf');
       if (entries[0].target.clientHeight < entries[0].target.scrollHeight) {
         this.hasScrollBar = true
       } else {

+ 3 - 5
src/pages/material.js

@@ -7,8 +7,8 @@ import 'viewerjs/dist/viewer.css'
 import Viewer from 'v-viewer'
 import { showLoginTips } from '@/utils/request'
 import { Button } from 'element-ui';
-Vue.component(Button.name, Button);
 
+Vue.component(Button.name, Button);
 
 window.tipInstance = null
 
@@ -20,12 +20,10 @@ Vue.use(Viewer,{
   }
 })
 
-
-
 Vue.config.productionTip = false
 
-window.addEventListener('store', () => {
-  console.log(localStorage.getItem('token'));
+store.dispatch('refreshUserInfo')
+window.addEventListener('storage', () => {
   if (!localStorage.getItem('token')) {
     showLoginTips()
   }

+ 2 - 10
src/utils/request.js

@@ -13,7 +13,6 @@ import { base64ToBlob } from "./file";
 import { checkLogin } from "@/api";
 import { LoginDetector } from "@/utils/starter";
 import { $alert, $confirm } from "@/components/shared/message";
-import store from '@/Store'
 
 let vue = new Vue();
 
@@ -66,16 +65,14 @@ export const showLoginTips = () => {
     no: function() {
       checkLogin().then((response) => {
         if (response.code === statusCode.SUCCESS) {
-          store.dispatch('refreshUserInfo')
           postQueue.length && postQueue.forEach((item) => item());
           postQueue = [];
           LoginDetector.valid();
-          let url = window.location.href
-          window.location.href = url
+          location.reload()
         } else if (response.code === statusCode.FAILURE_CODE_5001) {
           showLoginTips();
         }
-      });
+      })
       showLoginTips.__is_show = false;
     },
   });
@@ -206,11 +203,6 @@ export const http = {
             postQueue.push(function() {
               http[method](url, data, done, fail);
             });
-            // if (url.indexOf('isLogin') == -1) {
-            //     postQueue.push(function() {
-            //         http[method](url, data, done, fail)
-            //     })
-            // }
           }
         });