From a5186c4ea1e8f2b08b9fb4d36f0fb95b0fff295f Mon Sep 17 00:00:00 2001 From: waruneeauy Date: Fri, 21 Feb 2025 15:26:09 +0700 Subject: [PATCH] fixing --- src/views/home.vue | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/views/home.vue b/src/views/home.vue index 0b90c08..1b6bb96 100644 --- a/src/views/home.vue +++ b/src/views/home.vue @@ -28,6 +28,7 @@ const urlUser = config.API.URL_USER; const urlMgt = config.API.URL_MGT; const urlCheckin = config.API.URL_CHECKIN; +// รายการระบบที่สามารถเข้าใช้งานได้ const cards = ref([ { label: "ระบบบริการเจ้าของข้อมูล", @@ -51,9 +52,13 @@ const cards = ref([ }, ]); -const token = ref(""); -const refreshToken = ref(""); -const name = ref(""); +const token = ref(""); // สำหรับเก็บ token ที่ได้จาก cookie +const refreshToken = ref(""); // สำหรับเก็บ refresh token ที่ได้จาก cookie +const name = ref(""); // สำหรับเก็บชื่อผู้ใช้ + +/** + * ฟังก์ชันสำหรับดึงชื่อผู้ใช้ + */ async function getName() { const token = await getCookie(cookieTokenName.value); if (token) { @@ -70,6 +75,11 @@ async function getName() { } else name.value = ""; } +/** + * ฟังก์ชั่นสำหรับตรวจสอบสิทธิ์ และเปลี่ยนหน้าไปยัง url ของระบบที่ต้องการ + * @param sys ระบบที่ต้องการเข้าถึง + * @param url ลิงค์ของระบบที่ต้องการเข้าถึง + */ async function goPage(sys: string, url: string) { const token = await getCookie(cookieTokenName.value); @@ -94,9 +104,6 @@ async function goPage(sys: string, url: string) { requiredRole = ["ADMIN", "SUPER_ADMIN"]; } - // console.log("requiredRole===>", requiredRole); - // console.log("decoded===>", JSON.parse(decoded).realm_access.roles); - // ตรวจสอบว่า payload.role มีค่าหรือไม่ และว่ามี role ที่ต้องการหรือไม่ if ( requiredRole.some((role) => @@ -120,6 +127,9 @@ async function goPage(sys: string, url: string) { } } +/** + * ฟังก์ชั่นสำหรับออกจากระบบ + */ async function logout() { $q.dialog({ component: CustomComponent, @@ -141,6 +151,11 @@ async function logout() { }); } +/** + * ฟังก์ชั่นสำหรับบันทึก log เข้าระบบ + * @param type + * @param token + */ async function postSaveLog(type: string, token: any) { await axios .post( @@ -168,7 +183,7 @@ onMounted(async () => { deleteCookie("BMAHRISUSER_KEYCLOAK_IDENTITY"); const uid = route.query.uid?.toString() || getCookie("uid"); - const serve = route.query.uid ? "sso" : "uat"; + const serve = location.hostname == "hrms.bangkok.go.th" ? "sso" : "uat"; await axios .post( `${config.API.sso}/kcauth`, @@ -198,7 +213,7 @@ onMounted(async () => { } }) .catch((err: any) => { - if (location.hostname == "hrms.chin.in.th") { + if (location.hostname != "hrms.bangkok.go.th") { router.push("/sso"); } else { window.location.href = `${config.API.URL_SSO}`;