progress.ts
1.32 KB
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
45
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';
import router from '@/router/index';
// import * as store from "@/pinia/index";
import { useLoginStore } from '@/pinia/login';
NProgress.configure({ showSpinner: false });
router.beforeEach((to: any, from: any, next: any) => {
console.log(window.localStorage.getItem('isCnlive'))
NProgress.start();
// const hasToken = store.family.loginStore().token;
const hasToken = useLoginStore()?.$state?.token
const whiteList = ['/login', '/enter'];
// TODOS 这里需要把中国网的登录页也加到白名单里
// 页面标题设置
globalThis.document.title = to.meta.title? to.meta.title: import.meta.env.VITE_APP_TITLE;
if (hasToken) {
if (to.path === '/login' || to.path === '/enter') {
next({ path: '/dashboard' })
NProgress.done()
} else {
next()
NProgress.done()
}
} else {
if (whiteList.indexOf(to.path) !== -1) {
next()
} else {
if (from.path !== '/') {
console.log('请重新登录')
}
// TODOS 这里需要区分社区环境还是中国网环境
let loginPath: string = window.localStorage.getItem('isCnlive') === 'true'? '/enter': '/login';
next({ path: loginPath });
NProgress.done()
}
}
})
router.afterEach(() => {
NProgress.done()
})