|
@@ -1,21 +1,20 @@
|
|
|
import { isNavigationFailure, Router } from 'vue-router';
|
|
|
-// import { useUserStoreWidthOut } from '@/store/modules/user';
|
|
|
+import { useUserStore } from '@/store/modules/users';
|
|
|
import { storage } from '@/utils/storage';
|
|
|
import { PageEnum } from '@/enums/pageEnum';
|
|
|
-import { useLoadingBar } from 'naive-ui';
|
|
|
import { ACCESS_TOKEN } from '@/store/mutation-types';
|
|
|
|
|
|
const LOGIN_PATH = PageEnum.BASE_LOGIN;
|
|
|
|
|
|
const whitePathList = [LOGIN_PATH]; // no redirect whitelist
|
|
|
|
|
|
-const Loading = useLoadingBar();
|
|
|
-
|
|
|
export function createRouterGuards(router: Router) {
|
|
|
- // const userStore = useUserStoreWidthOut();
|
|
|
+ const userStore = useUserStore();
|
|
|
router.beforeEach(async (to, from, next) => {
|
|
|
console.log('access token');
|
|
|
- Loading && Loading.start();
|
|
|
+ window.$loadingBar && window.$loadingBar.start();
|
|
|
+
|
|
|
+ // console.log(window.$loadingBar, '232332');
|
|
|
if (from.path === LOGIN_PATH && to.name === 'errorPage') {
|
|
|
next(PageEnum.BASE_HOME);
|
|
|
return;
|
|
@@ -40,17 +39,19 @@ export function createRouterGuards(router: Router) {
|
|
|
path: LOGIN_PATH,
|
|
|
replace: true
|
|
|
};
|
|
|
+
|
|
|
if (to.path) {
|
|
|
redirectData.query = {
|
|
|
...redirectData.query,
|
|
|
redirect: to.path
|
|
|
};
|
|
|
}
|
|
|
+ console.log(redirectData, to);
|
|
|
next(redirectData);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // await userStore.GetInfo();
|
|
|
+ await userStore.getInfo();
|
|
|
|
|
|
// const redirectPath = (from.query.redirect || to.path) as string;
|
|
|
// const redirect = decodeURIComponent(redirectPath);
|
|
@@ -58,7 +59,7 @@ export function createRouterGuards(router: Router) {
|
|
|
// to.path === redirect ? { ...to, replace: true } : { path: redirect };
|
|
|
// next(nextData);
|
|
|
next();
|
|
|
- Loading && Loading.finish();
|
|
|
+ // window.$loadingBar && window.$loadingBar.finish();
|
|
|
});
|
|
|
|
|
|
router.afterEach((to, _, failure) => {
|
|
@@ -88,7 +89,7 @@ export function createRouterGuards(router: Router) {
|
|
|
// }
|
|
|
// }
|
|
|
// asyncRouteStore.setKeepAliveComponents(keepAliveComponents);
|
|
|
- Loading && Loading.finish();
|
|
|
+ window.$loadingBar && window.$loadingBar.finish();
|
|
|
});
|
|
|
|
|
|
// router.onError(error => {});
|