feat: local storage role
This commit is contained in:
parent
d932225629
commit
be75902c5e
1 changed files with 22 additions and 1 deletions
|
|
@ -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(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue