api saveLog

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2024-12-18 10:11:48 +07:00
parent 146dcb9028
commit 3f5b7356f1
2 changed files with 42 additions and 6 deletions

View file

@ -1,7 +1,8 @@
import env from "./index"; import env from "./index";
const org = `${env.API_URI}/org`; const org = `${env.API_URI}/org`;
// const log = `${env.API_URI}/log`; const ssoLog = `${env.API_URI}/org/keycloak/log/sso`;
export default { export default {
org, org,
ssoLog,
}; };

View file

@ -13,6 +13,7 @@ import screen3 from "@/assets/screen3.png";
import screen4 from "@/assets/screen4.png"; import screen4 from "@/assets/screen4.png";
import type { DateCards } from "@/interface/index/Main"; import type { DateCards } from "@/interface/index/Main";
import http from "@/plugins/http";
const $q = useQuasar(); const $q = useQuasar();
@ -109,11 +110,44 @@ async function goPage(sys: string, url: string) {
} }
async function logout() { async function logout() {
await deleteCookie("BMAHRIS_KEYCLOAK_IDENTITY"); $q.dialog({
await deleteCookie("BMAHRIS_KEYCLOAK_REFRESH"); 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 async function postSaveLog(type: string, token: any) {
window.location.href = `${config.API.URL_SSO}`; 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 () => { onMounted(async () => {
@ -138,11 +172,12 @@ onMounted(async () => {
withCredentials: true, // Include cookies with the request withCredentials: true, // Include cookies with the request
} }
) )
.then((res: any) => { .then(async (res: any) => {
if (res.status === 200) { if (res.status === 200) {
setCookie("BMAHRIS_KEYCLOAK_IDENTITY", res.data.access_token, 1); setCookie("BMAHRIS_KEYCLOAK_IDENTITY", res.data.access_token, 1);
setCookie("BMAHRIS_KEYCLOAK_REFRESH", res.data.refresh_token, 1); setCookie("BMAHRIS_KEYCLOAK_REFRESH", res.data.refresh_token, 1);
// log // log
await postSaveLog("เข้าสู่ระบบ", res.data.access_token);
} }
}) })
.catch((err: any) => { .catch((err: any) => {