37 lines
991 B
TypeScript
37 lines
991 B
TypeScript
import NProgress from "nprogress";
|
|
import { useAbilityStore } from "@/stores/ability";
|
|
import { useNavigationStore } from "@/stores/admin/navigation";
|
|
|
|
export async function abilityAndNavUpdate(to: any, from: any, next: any) {
|
|
NProgress.start();
|
|
const ability = useAbilityStore();
|
|
const navigation = useNavigationStore();
|
|
|
|
let admin = to.meta.admin || false;
|
|
let type = to.meta.type;
|
|
let section = to.meta.section;
|
|
let module = to.meta.module;
|
|
|
|
if ((admin && ability.isAdmin()) || ability.can(type, section, module)) {
|
|
NProgress.done();
|
|
navigation.activeNavigation = to.name.split("-")[1];
|
|
navigation.activeLink = to.name.split("-")[2];
|
|
next();
|
|
} else {
|
|
NProgress.done();
|
|
next({ name: "admin-default" });
|
|
}
|
|
}
|
|
|
|
export async function isOwner(to: any, from: any, next: any) {
|
|
NProgress.start();
|
|
const ability = useAbilityStore();
|
|
|
|
if (ability.isOwner) {
|
|
NProgress.done();
|
|
next();
|
|
} else {
|
|
NProgress.done();
|
|
next(false);
|
|
}
|
|
}
|