bug修正 : 如果沒有首頁權限,依舊會先進首頁
This commit is contained in:
parent
348bbe09cb
commit
2948a95b56
@ -1,7 +1,7 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { onMounted, ref, watch, computed, inject } from "vue";
|
import { onMounted, ref, watch, computed, inject } from "vue";
|
||||||
import { AUTHPAGES } from "@/constant";
|
import { AUTHPAGES } from "@/constant";
|
||||||
import { getAuth, getAllSysSidebar } from "@/apis/building";
|
import { getAllSysSidebar } from "@/apis/building";
|
||||||
import useBuildingStore from "@/stores/useBuildingStore";
|
import useBuildingStore from "@/stores/useBuildingStore";
|
||||||
import useUserInfoStore from "@/stores/useUserInfoStore";
|
import useUserInfoStore from "@/stores/useUserInfoStore";
|
||||||
import { twMerge } from "tailwind-merge";
|
import { twMerge } from "tailwind-merge";
|
||||||
@ -12,20 +12,6 @@ const buildingStore = useBuildingStore();
|
|||||||
|
|
||||||
const alerts = inject("app_alerts");
|
const alerts = inject("app_alerts");
|
||||||
const alarmslength = computed(() => (alerts?.value || []).length);
|
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(() =>
|
const authPages = computed(() =>
|
||||||
store.auth_page.filter(({ showView }) => showView)
|
store.auth_page.filter(({ showView }) => showView)
|
||||||
@ -45,10 +31,6 @@ watch(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
iniFroList();
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<ul class="px-1 menu-box my-2">
|
<ul class="px-1 menu-box my-2">
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { onMounted, ref, watch, inject } from "vue";
|
import { onMounted, ref, watch, inject } from "vue";
|
||||||
import { Login } from "@/apis/login";
|
import { Login } from "@/apis/login";
|
||||||
|
import { getAuth } from "@/apis/building";
|
||||||
|
import { AUTHPAGES } from "@/constant";
|
||||||
import * as yup from "yup";
|
import * as yup from "yup";
|
||||||
import useFormErrorMessage from "@/hooks/useFormErrorMessage";
|
import useFormErrorMessage from "@/hooks/useFormErrorMessage";
|
||||||
import { useRouter } from "vue-router";
|
import { useRouter } from "vue-router";
|
||||||
@ -35,7 +37,31 @@ const doLogin = async () => {
|
|||||||
const res = await Login(value);
|
const res = await Login(value);
|
||||||
if (res.isSuccess) {
|
if (res.isSuccess) {
|
||||||
store.user = res.data;
|
store.user = res.data;
|
||||||
router.replace({ path: "/dashboard" });
|
|
||||||
|
// 獲取並存儲使用者權限到 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 {
|
} else {
|
||||||
openToast("error", res.msg);
|
openToast("error", res.msg);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user