zhangxiao
2024-08-07 4b2c984f257b232b911b4dada3f9782feb2d012f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import type { Router, LocationQueryRaw } from 'vue-router';
import NProgress from 'nprogress'; // progress bar
 
import { useUserStore } from '@/store';
import { isLogin } from '@/utils/auth';
 
export default function setupUserLoginInfoGuard(router: Router) {
  router.beforeEach(async (to, from, next) => {
    NProgress.start();
    const userStore = useUserStore();
    next();
    // if (isLogin()) {
    //   if (userStore.role) {
    //     next();
    //   } else {
    //     try {
    //       await userStore.info();
    //       next();
    //     } catch (error) {
    //       await userStore.logout();
    //       next({
    //         name: 'login',
    //         query: {
    //           redirect: to.name,
    //           ...to.query,
    //         } as LocationQueryRaw,
    //       });
    //     }
    //   }
    // } else {
    //   if (to.name === 'login') {
    //     next();
    //     return;
    //   }
    //   next({
    //     name: 'login',
    //     query: {
    //       redirect: to.name,
    //       ...to.query,
    //     } as LocationQueryRaw,
    //   });
    // }
  });
}