Files
lingji-work-fe/src/router/guard/permission.ts

30 lines
868 B
TypeScript
Raw Normal View History

2025-06-16 14:42:26 +08:00
/*
* @Author:
* @Date: 2023-03-05 14:46:43
* @LastEditors:
* @LastEditTime: 2023-03-05 15:55:36
* @Description:
*/
import type { Router, RouteRecordNormalized } from 'vue-router';
import NProgress from 'nprogress'; // progress bar
import { useAppStore } from '@/stores';
export default function setupPermissionGuard(router: Router) {
router.beforeEach(async (to, from, next) => {
console.log('access permission router guard');
const appStore = useAppStore();
//* 菜单是否为服务端渲染
if (appStore.menuFromServer) {
//* 没有服务端渲染的菜单
if(!appStore.appAsyncMenus) {
// todo 请求服务端渲染菜单的接口当前为mock数据
await appStore.fetchServerMenuConfig();
}
next();
} else {
next();
}
NProgress.done();
});
}