first commit
This commit is contained in:
29
src/router/guard/permission.ts
Normal file
29
src/router/guard/permission.ts
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* @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();
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user