20 changed files with 239 additions and 174 deletions
@ -0,0 +1,33 @@ |
|||
import type { TransitionSetting } from '/@/types/config'; |
|||
|
|||
import { computed, unref } from 'vue'; |
|||
|
|||
import { appStore } from '/@/store/modules/app'; |
|||
|
|||
export function useTransitionSetting() { |
|||
const getTransitionSetting = computed(() => appStore.getProjectConfig.transitionSetting); |
|||
|
|||
const getEnableTransition = computed(() => unref(getTransitionSetting).enable); |
|||
|
|||
const getOpenNProgress = computed(() => unref(getTransitionSetting)?.openNProgress); |
|||
|
|||
const getOpenPageLoading = computed(() => { |
|||
return unref(getTransitionSetting)?.openPageLoading && unref(getEnableTransition); |
|||
}); |
|||
|
|||
const getBasicTransition = computed(() => unref(getTransitionSetting)?.basicTransition); |
|||
|
|||
function setTransitionSetting(transitionSetting: Partial<TransitionSetting>) { |
|||
appStore.commitProjectConfigState({ transitionSetting }); |
|||
} |
|||
|
|||
return { |
|||
setTransitionSetting, |
|||
|
|||
getTransitionSetting, |
|||
getEnableTransition, |
|||
getOpenNProgress, |
|||
getOpenPageLoading, |
|||
getBasicTransition, |
|||
}; |
|||
} |
|||
@ -1,19 +1,24 @@ |
|||
import type { Router } from 'vue-router'; |
|||
|
|||
import { useTransitionSetting } from '/@/hooks/setting/useTransitionSetting'; |
|||
|
|||
import NProgress from 'nprogress'; |
|||
import 'nprogress/nprogress.css'; |
|||
import { unref } from 'vue'; |
|||
|
|||
const { getOpenNProgress } = useTransitionSetting(); |
|||
|
|||
export function createProgressGuard(router: Router) { |
|||
// NProgress.inc(0.1);
|
|||
// NProgress.configure({ easing: 'ease', speed: 200, showSpinner: false });
|
|||
|
|||
router.beforeEach(async (to) => { |
|||
!to.meta.inTab && NProgress.start(); |
|||
!to.meta.inTab && unref(getOpenNProgress) && NProgress.start(); |
|||
return true; |
|||
}); |
|||
|
|||
router.afterEach(async (to) => { |
|||
!to.meta.inTab && NProgress.done(); |
|||
!to.meta.inTab && unref(getOpenNProgress) && NProgress.done(); |
|||
return true; |
|||
}); |
|||
} |
|||
|
|||
Loading…
Reference in new issue