|
@@ -1,34 +1,38 @@
|
|
|
-import type { Router } from 'vue-router';
|
|
|
-import { useAppStoreWidthOut } from '/@/store/modules/app';
|
|
|
-import { useUserStoreWidthOut } from '/@/store/modules/user';
|
|
|
-import { useTransitionSetting } from '/@/hooks/setting/useTransitionSetting';
|
|
|
-import { unref } from 'vue';
|
|
|
+import type { Router } from 'vue-router'
|
|
|
+import { useAppStoreWidthOut } from '/@/store/modules/app'
|
|
|
+import { useUserStoreWidthOut } from '/@/store/modules/user'
|
|
|
+import { useTransitionSetting } from '/@/hooks/setting/useTransitionSetting'
|
|
|
+import { unref } from 'vue'
|
|
|
|
|
|
export function createPageLoadingGuard(router: Router) {
|
|
|
- const userStore = useUserStoreWidthOut();
|
|
|
- const appStore = useAppStoreWidthOut();
|
|
|
- const { getOpenPageLoading } = useTransitionSetting();
|
|
|
- router.beforeEach(async (to) => {
|
|
|
+ const userStore = useUserStoreWidthOut()
|
|
|
+ const appStore = useAppStoreWidthOut()
|
|
|
+ const { getOpenPageLoading } = useTransitionSetting()
|
|
|
+ router.beforeEach(async to => {
|
|
|
+ if (!userStore.getUserInfo) {
|
|
|
+ await userStore.getUserInfoAction()
|
|
|
+ return true
|
|
|
+ }
|
|
|
if (!userStore.getToken) {
|
|
|
- return true;
|
|
|
+ return true
|
|
|
}
|
|
|
if (to.meta.loaded) {
|
|
|
- return true;
|
|
|
+ return true
|
|
|
}
|
|
|
|
|
|
if (unref(getOpenPageLoading)) {
|
|
|
- appStore.setPageLoadingAction(true);
|
|
|
- return true;
|
|
|
+ appStore.setPageLoadingAction(true)
|
|
|
+ return true
|
|
|
}
|
|
|
|
|
|
- return true;
|
|
|
- });
|
|
|
+ return true
|
|
|
+ })
|
|
|
router.afterEach(async () => {
|
|
|
if (unref(getOpenPageLoading)) {
|
|
|
setTimeout(() => {
|
|
|
- appStore.setPageLoading(false);
|
|
|
- }, 220);
|
|
|
+ appStore.setPageLoading(false)
|
|
|
+ }, 220)
|
|
|
}
|
|
|
- return true;
|
|
|
- });
|
|
|
+ return true
|
|
|
+ })
|
|
|
}
|