From 3f5b7356f12edc95fb2ca61799103d7247f80d6b Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Wed, 18 Dec 2024 10:11:48 +0700 Subject: [PATCH] api saveLog --- src/api/api.org.ts | 3 ++- src/views/home.vue | 45 ++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/api/api.org.ts b/src/api/api.org.ts index 086e557..eb970bf 100644 --- a/src/api/api.org.ts +++ b/src/api/api.org.ts @@ -1,7 +1,8 @@ import env from "./index"; const org = `${env.API_URI}/org`; -// const log = `${env.API_URI}/log`; +const ssoLog = `${env.API_URI}/org/keycloak/log/sso`; export default { org, + ssoLog, }; diff --git a/src/views/home.vue b/src/views/home.vue index 597ba1d..4631d09 100644 --- a/src/views/home.vue +++ b/src/views/home.vue @@ -13,6 +13,7 @@ import screen3 from "@/assets/screen3.png"; import screen4 from "@/assets/screen4.png"; import type { DateCards } from "@/interface/index/Main"; +import http from "@/plugins/http"; const $q = useQuasar(); @@ -109,11 +110,44 @@ async function goPage(sys: string, url: string) { } async function logout() { - await deleteCookie("BMAHRIS_KEYCLOAK_IDENTITY"); - await deleteCookie("BMAHRIS_KEYCLOAK_REFRESH"); + $q.dialog({ + component: CustomComponent, + componentProps: { + title: `ยืนยันการออกจากระบบ`, + message: "ต้องการออกจากระบบใช่หรือไม่?", + icon: "info", + color: "public", + }, + cancel: true, + persistent: true, + }).onOk(async () => { + await deleteCookie("BMAHRIS_KEYCLOAK_IDENTITY"); + await deleteCookie("BMAHRIS_KEYCLOAK_REFRESH"); + // ยิง logout เข้าระบบ + await postSaveLog("ออกจากระบบ", token.value); + window.location.href = `${config.API.URL_SSO}`; + }); +} - // ยิง logout เข้าระบบ - window.location.href = `${config.API.URL_SSO}`; +async function postSaveLog(type: string, token: any) { + await axios + .post( + config.API.ssoLog, + { text: type }, + { + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + accept: "application/json", + }, + } + ) + .then((res) => { + console.log("res:", res.data); + }) + .catch((err) => { + console.error("Error:", err); + }); } onMounted(async () => { @@ -138,11 +172,12 @@ onMounted(async () => { withCredentials: true, // Include cookies with the request } ) - .then((res: any) => { + .then(async (res: any) => { if (res.status === 200) { setCookie("BMAHRIS_KEYCLOAK_IDENTITY", res.data.access_token, 1); setCookie("BMAHRIS_KEYCLOAK_REFRESH", res.data.refresh_token, 1); // ยิง log เข้าระบบ + await postSaveLog("เข้าสู่ระบบ", res.data.access_token); } }) .catch((err: any) => {