30 lines
868 B
TypeScript
30 lines
868 B
TypeScript
|
|
/*
|
|||
|
|
* @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();
|
|||
|
|
});
|
|||
|
|
}
|