feat: local storage role

This commit is contained in:
oat_dev 2024-06-28 15:13:27 +07:00
parent d932225629
commit be75902c5e

View file

@ -14,6 +14,7 @@ const { toc } = storeToRefs(manualStore);
const { loader } = storeToRefs(dataStore); const { loader } = storeToRefs(dataStore);
const role = ref<string>("user"); const role = ref<string>("user");
const queryRole = route.query.role as string;
const drawerMini = ref(false); const drawerMini = ref(false);
const drawerMain = ref(false); const drawerMain = ref(false);
@ -38,10 +39,30 @@ const toggleBtnLeft = () => {
} }
}; };
function setLocalStorageItem(key: string, value: string): void {
localStorage.setItem(key, value);
}
function getLocalStorageItem(key: string): string | null {
return localStorage.getItem(key);
}
onMounted(async () => { onMounted(async () => {
{ {
const data = await fetch("/toc.json").then((r) => r.json()); const data = await fetch("/toc.json").then((r) => r.json());
role.value = route.query.role as string;
if (!!queryRole) {
setLocalStorageItem("role", queryRole);
role.value = queryRole;
} else {
const getLocalRole = getLocalStorageItem("role");
if (getLocalRole !== null) {
role.value = getLocalRole;
} else {
role.value = "user";
}
}
menuList.value = data; menuList.value = data;
if (role.value !== "admin") { if (role.value !== "admin") {
menuList.value = data.filter( menuList.value = data.filter(