bug修正 : 如果沒有首頁權限,依舊會先進首頁

This commit is contained in:
koko 2025-09-26 13:53:23 +08:00
parent 348bbe09cb
commit 2948a95b56
2 changed files with 28 additions and 20 deletions

View File

@ -1,7 +1,7 @@
<script setup>
import { onMounted, ref, watch, computed, inject } from "vue";
import { AUTHPAGES } from "@/constant";
import { getAuth, getAllSysSidebar } from "@/apis/building";
import { getAllSysSidebar } from "@/apis/building";
import useBuildingStore from "@/stores/useBuildingStore";
import useUserInfoStore from "@/stores/useUserInfoStore";
import { twMerge } from "tailwind-merge";
@ -12,20 +12,6 @@ const buildingStore = useBuildingStore();
const alerts = inject("app_alerts");
const alarmslength = computed(() => (alerts?.value || []).length);
const iniFroList = async () => {
const res = await getAuth();
store.updateAuthPage(
res.data.map((d) =>
AUTHPAGES.find(({ authCode }) => authCode === d.authCode)
? {
...d,
...AUTHPAGES.find(({ authCode }) => authCode === d.authCode),
}
: d
)
);
};
const authPages = computed(() =>
store.auth_page.filter(({ showView }) => showView)
@ -45,10 +31,6 @@ watch(
}
}
);
onMounted(() => {
iniFroList();
});
</script>
<template>
<ul class="px-1 menu-box my-2">

View File

@ -1,6 +1,8 @@
<script setup>
import { onMounted, ref, watch, inject } from "vue";
import { Login } from "@/apis/login";
import { getAuth } from "@/apis/building";
import { AUTHPAGES } from "@/constant";
import * as yup from "yup";
import useFormErrorMessage from "@/hooks/useFormErrorMessage";
import { useRouter } from "vue-router";
@ -35,7 +37,31 @@ const doLogin = async () => {
const res = await Login(value);
if (res.isSuccess) {
store.user = res.data;
// 使 store
try {
const authRes = await getAuth();
const userAuthPages = authRes.data.map((d) =>
AUTHPAGES.find(({ authCode }) => authCode === d.authCode)
? {
...d,
...AUTHPAGES.find(({ authCode }) => authCode === d.authCode),
}
: d
);
// store
store.updateAuthPage(userAuthPages);
// showView
const firstAvailablePage = userAuthPages.find(page => page.showView && page.navigate);
const redirectPath = firstAvailablePage?.navigate || "/dashboard";
router.replace({ path: redirectPath });
} catch (error) {
console.error("獲取使用者權限時發生錯誤:", error);
router.replace({ path: "/dashboard" });
}
} else {
openToast("error", res.msg);
}