mirror of https://github.com/certd/certd
chore: 集成vben
parent
9557fc799e
commit
746d3c97c3
|
@ -71,31 +71,11 @@ export function setupCommonGuard(router: Router) {
|
||||||
*/
|
*/
|
||||||
function setupAccessGuard(router: Router) {
|
function setupAccessGuard(router: Router) {
|
||||||
router.beforeEach(async (to, from) => {
|
router.beforeEach(async (to, from) => {
|
||||||
// 基本路由,这些路由不需要进入权限拦截
|
|
||||||
const needAuth = to.matched.some((r) => {
|
|
||||||
return r.meta?.auth || r.meta?.permission;
|
|
||||||
});
|
|
||||||
|
|
||||||
const accessStore = useAccessStore();
|
const accessStore = useAccessStore();
|
||||||
if (needAuth) {
|
|
||||||
if (!accessStore.accessToken) {
|
|
||||||
// 没有访问权限,跳转登录页面
|
|
||||||
if (to.fullPath !== LOGIN_PATH) {
|
|
||||||
return {
|
|
||||||
path: LOGIN_PATH,
|
|
||||||
// 如不需要,直接删除 query
|
|
||||||
query: to.fullPath === DEFAULT_HOME_PATH ? {} : { redirect: encodeURIComponent(to.fullPath) },
|
|
||||||
// 携带当前跳转的页面,登录后重新跳转该页面
|
|
||||||
replace: true
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 是否已经生成过动态路由
|
// 是否已经生成过动态路由
|
||||||
if (!accessStore.isAccessChecked) {
|
if (!accessStore.isAccessChecked) {
|
||||||
if (accessStore.accessToken) {
|
if (accessStore.accessToken) {
|
||||||
|
//如果已登录
|
||||||
const permissionStore = usePermissionStore();
|
const permissionStore = usePermissionStore();
|
||||||
await permissionStore.loadFromRemote();
|
await permissionStore.loadFromRemote();
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
|
@ -109,25 +89,27 @@ function setupAccessGuard(router: Router) {
|
||||||
accessStore.setIsAccessChecked(true);
|
accessStore.setIsAccessChecked(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 生成菜单和路由
|
// 基本路由,这些路由不需要进入权限拦截
|
||||||
// const { accessibleMenus, accessibleRoutes } = await generateAccess({
|
const needAuth = to.matched.some((r) => {
|
||||||
// roles: [],
|
return r.meta?.auth || r.meta?.permission;
|
||||||
// router,
|
});
|
||||||
// // 则会在菜单中显示,但是访问会被重定向到403
|
|
||||||
// routes: accessRoutes
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// // 保存菜单信息和路由信息
|
|
||||||
// accessStore.setAccessMenus(accessibleMenus);
|
|
||||||
// accessStore.setAccessRoutes(accessibleRoutes);
|
|
||||||
|
|
||||||
// const redirectPath = (from.query.redirect ?? (to.path === DEFAULT_HOME_PATH ? DEFAULT_HOME_PATH : to.fullPath)) as string;
|
if (!needAuth) {
|
||||||
//
|
|
||||||
// return {
|
|
||||||
// ...router.resolve(decodeURIComponent(redirectPath)),
|
|
||||||
// replace: true
|
|
||||||
// };
|
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
if (!accessStore.accessToken) {
|
||||||
|
// 没有访问权限,跳转登录页面
|
||||||
|
if (to.fullPath !== LOGIN_PATH) {
|
||||||
|
return {
|
||||||
|
path: LOGIN_PATH,
|
||||||
|
// 如不需要,直接删除 query
|
||||||
|
query: to.fullPath === DEFAULT_HOME_PATH ? {} : { redirect: encodeURIComponent(to.fullPath) },
|
||||||
|
// 携带当前跳转的页面,登录后重新跳转该页面
|
||||||
|
replace: true
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue