fixing await & clear code และเก็บ dataProfile ตอน get profile main layout

This commit is contained in:
Warunee Tamkoo 2025-07-31 09:49:22 +07:00
parent 417a6e5618
commit 1698d86024
3 changed files with 72 additions and 45 deletions

View file

@ -19,35 +19,63 @@ export const useKpiDataStore = defineStore("KPIDate", () => {
const work = ref<boolean>(false); const work = ref<boolean>(false);
const tabMain = ref<string>(""); const tabMain = ref<string>("");
const dataProfile = ref<DataProfile>({ const dataProfile = ref<DataProfile>({
profileId: null, amountSpecial: 0,
prefix: "", avatar: "",
rank: "", avatarName: "",
firstName: "", birthDate: "",
lastName: "", child1: "",
child1DnaId: "",
child1Id: "",
child1ShortName: "",
child2: "",
child2DnaId: "",
child2Id: "",
child2ShortName: "",
child3: "",
child3DnaId: "",
child3Id: "",
child3ShortName: "",
child4: "",
child4DnaId: "",
child4Id: "",
child4ShortName: "",
citizenId: "", citizenId: "",
position: "", dateRetireLaw: "",
posMaster: null, dateStart: "",
posLevelName: null, firstName: "",
posLevelRank: null, isDirector: false,
posLevelId: null, isProbation: false,
posTypeName: null, keycloak: "",
posTypeRank: null, lastName: "",
posTypeId: null, leaveDate: null,
posExecutiveName: "", node: 0,
posExecutivePriority: null, nodeDnaId: "",
nodeId: "",
nodeShortName: "",
posExecutiveId: null, posExecutiveId: null,
rootId: null, posExecutiveName: null,
posExecutivePriority: null,
posLevelId: "",
posLevelName: "",
posLevelRank: 0,
posMaster: 0,
posMasterNo: 0,
posNo: "",
posTypeId: "",
posTypeName: "",
posTypeRank: 0,
position: "",
positionArea: null,
positionExecutiveField: null,
prefix: "",
profileId: "",
profileType: "",
rank: null,
root: "", root: "",
child1Id: null, rootDnaId: "",
child1: null, rootId: "",
child2Id: null, rootShortName: "",
child2: null, salary: 0,
child3Id: null,
child3: null,
child4Id: null,
child4: null,
node: null,
nodeId: null,
}); });
const dataEvaluation = ref<any>({ const dataEvaluation = ref<any>({

View file

@ -481,9 +481,9 @@ async function getProfile() {
if (!store.dataProfile.profileId) { if (!store.dataProfile.profileId) {
await http await http
.get(config.API.profilePosition()) .get(config.API.profilePosition())
.then(async (res) => { .then((res) => {
const data = await res.data.result; const data = res.data.result;
store.dataProfile = await data; store.dataProfile = data;
}) })
.catch((e) => { .catch((e) => {
messageError($q, e); messageError($q, e);

View file

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