123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- import router from './router';
- import { createDiscreteApi} from 'naive-ui';
- import { useUserStore } from '@/stores/modules/userStore';
- const whiteList = ['/login'];
- const TITLE_SUFFIX = ' - LibraAI人工智能运营体';
- const { loadingBar } = createDiscreteApi(['loadingBar'], {
- loadingBarProviderProps: {
- loadingBarStyle: {
- backgroundColor: "#2454FF"
- }
- }
- })
- // 简易的基础权限
- router.beforeEach(async (to, from, next) => {
- loadingBar.start();
-
- const isRouterAuth = whiteList.includes(to.path);
- if (isRouterAuth) {
- next()
- } else {
- const userStore = useUserStore();
- const { token } = userStore.userInfo;
-
- if ( !token ) {
- return next('/login');
- } else {
- next()
- }
-
- }
- })
- router.afterEach((to) => {
- document.title = to?.meta?.title + TITLE_SUFFIX;
- loadingBar.finish();
- })
|