fixing await & clear code และเก็บ dataProfile ตอน get profile main layout
This commit is contained in:
parent
417a6e5618
commit
1698d86024
3 changed files with 72 additions and 45 deletions
|
|
@ -16,6 +16,7 @@ import {
|
|||
} from "@/plugins/auth";
|
||||
|
||||
import { useDataStore } from "@/stores/data";
|
||||
import { useKpiDataStore } from "@/modules/08_KPI/store";
|
||||
|
||||
// landing page config url
|
||||
const configParam = {
|
||||
|
|
@ -27,6 +28,7 @@ const router = useRouter();
|
|||
|
||||
const $q = useQuasar();
|
||||
const dataStore = useDataStore();
|
||||
const kpiDataStore = useKpiDataStore();
|
||||
|
||||
const mixin = useCounterMixin();
|
||||
const {
|
||||
|
|
@ -44,15 +46,13 @@ const notiList = ref<any>([]);
|
|||
const notiTrigger = ref(false);
|
||||
const currentRouteName = router.currentRoute.value.name;
|
||||
const tab = ref<any>(currentRouteName);
|
||||
const link = ref<string>("");
|
||||
const isSsoToken = ref(false);
|
||||
|
||||
/**
|
||||
* เรียกฟังก์ชันทั้งหมดตอนเรียกใช้ไฟล์นี้
|
||||
*/
|
||||
onMounted(async () => {
|
||||
await checkUser();
|
||||
await fetchTotolNotificate();
|
||||
await Promise.all([checkUser(), fetchTotolNotificate()]);
|
||||
const user = await tokenParsed();
|
||||
const SSO_TOKEN = await getCookie("SSO");
|
||||
isSsoToken.value = SSO_TOKEN === "y" ? true : false;
|
||||
|
|
@ -63,9 +63,10 @@ async function checkUser() {
|
|||
await http
|
||||
.get(config.API.profilePosition())
|
||||
.then(async (res) => {
|
||||
const data = await res.data.result;
|
||||
const data = res.data.result;
|
||||
await dataStore.getData(data);
|
||||
await dataStore.getProFileType();
|
||||
kpiDataStore.dataProfile = data; // Set dataProfile in kpiDataStore
|
||||
if (data.avatarName) {
|
||||
await getImg(data.profileId, data.avatarName);
|
||||
} else {
|
||||
|
|
@ -77,17 +78,19 @@ async function checkUser() {
|
|||
component: CustomComponent,
|
||||
componentProps: {
|
||||
title: "ข้อความแจ้งเตือน",
|
||||
message: err.response.data.message,
|
||||
message:
|
||||
err.response?.data?.message || "เกิดข้อผิดพลาดที่ไม่ทราบสาเหตุ",
|
||||
icon: "warning",
|
||||
color: "red",
|
||||
onlycancel: true,
|
||||
},
|
||||
}).onCancel(async () => {
|
||||
}).onCancel(() => {
|
||||
showLoader();
|
||||
await logout();
|
||||
setTimeout(() => {
|
||||
hideLoader();
|
||||
}, 1000);
|
||||
logout().then(() => {
|
||||
setTimeout(() => {
|
||||
hideLoader();
|
||||
}, 1000);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -97,11 +100,7 @@ function getImg(id: string, pathName: string) {
|
|||
.get(config.API.fileByFile("ทะเบียนประวัติ", "โปรไฟล์", id, pathName))
|
||||
.then((res) => {
|
||||
dataStore.profileImg = res.data.downloadUrl;
|
||||
})
|
||||
.catch((e) => {
|
||||
// messageError($q, e);
|
||||
})
|
||||
.finally(() => {});
|
||||
});
|
||||
}
|
||||
|
||||
const totalNoti = ref<number>(0);
|
||||
|
|
@ -160,7 +159,7 @@ const doLogout = () => {
|
|||
async () => {
|
||||
await http.post(config.API.keycloakLogSSO, { text: "ออกจากระบบ" });
|
||||
// authen with client
|
||||
await logoutSSO();
|
||||
logoutSSO();
|
||||
},
|
||||
"ยืนยันการออกจากระบบ",
|
||||
"ต้องการออกจากระบบใช่หรือไม่"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue