From 503d1116343e314c89e1bcb6327e95bc3e820bbf Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Wed, 1 Apr 2026 16:59:59 +0700 Subject: [PATCH] fix: fetch permission.attrOwnership --- .../components/PersonalList/Table.vue | 77 ++++++++++++------- 1 file changed, 50 insertions(+), 27 deletions(-) diff --git a/src/modules/05_placement/components/PersonalList/Table.vue b/src/modules/05_placement/components/PersonalList/Table.vue index 584124bee..5f2d3f260 100644 --- a/src/modules/05_placement/components/PersonalList/Table.vue +++ b/src/modules/05_placement/components/PersonalList/Table.vue @@ -9,6 +9,7 @@ import { useRoute, useRouter } from "vue-router"; import { checkPermission } from "@/utils/permissions"; import { useCounterMixin } from "@/stores/mixin"; import { usePlacementDataStore } from "@/modules/05_placement/store"; +import { useMenuDataStore } from "@/stores/menuList"; import avatar from "@/assets/avatar_user.jpg"; import type { PartialTableName } from "@/modules/05_placement/interface/request/placement"; @@ -27,6 +28,7 @@ import DialogPreviewCommand from "@/modules/18_command/components/DialogPreviewC const $q = useQuasar(); // show dialog const DataStore = usePlacementDataStore(); +const storeMenu = useMenuDataStore(); const route = useRoute(); const router = useRouter(); const mixin = useCounterMixin(); //เรียกฟังก์ชันกลาง @@ -55,7 +57,14 @@ const command = ref(""); const commandId = ref(""); const commandCitizenId = ref(""); -let roleAdmin = ref(false); +// เปลี่ยนจาก ref เป็น computed property +const roleAdmin = computed(() => { + if (!storeMenu.permissions) return false; + + const permission = checkPermission(route); + return DataStore.isOfficer || permission?.attrOwnership == "OWNER"; +}); + const edit = ref(true); const modalPersonal = ref(false); const modal = ref(false); //modal ขอผ่อนผัน + สละสิทธิ์ @@ -92,6 +101,18 @@ const personal_selected = ref([]); const filterlistAdd = ref(""); const paging = ref(true); +// เพิ่ม watcher สำหรับ roleAdmin +watch( + roleAdmin, + (newValue) => { + const permission = checkPermission(route); + if (!newValue && permission?.attrOwnership !== "OWNER") { + displayAdd.value = false; + } + }, + { immediate: true } +); + // เช็ตสถานะการเลือกคนไปยังหน่วยงาน const checkSelected = computed(() => { if (selected.value.length === 0) { @@ -248,16 +269,17 @@ const columnsBase = ref([ }, ]); -const columns = computed(() => - roleAdmin.value || checkPermission(route)?.attrOwnership == "OWNER" +const columns = computed(() => { + const permission = checkPermission(route); + return roleAdmin.value || permission?.attrOwnership == "OWNER" ? columnsBase.value : columnsBase.value?.filter( (col) => col.name !== "no" && col.name !== "draft" && col.name !== "refCommandNo" - ) -); + ); +}); /** * แปลงสถานะพนักงาน @@ -406,8 +428,9 @@ async function getTable() { rowsAll.value.push(rowData); }); + const permission = checkPermission(route); const rowData = await (roleAdmin.value || - checkPermission(route)?.attrOwnership == "OWNER" + permission?.attrOwnership == "OWNER" ? rowsAll.value : rowsAll.value.filter((x: any) => x.isDraft === true)); @@ -554,8 +577,9 @@ function getClass(val: boolean) { * @param draft status */ function selectData(pid: string, draft: string) { + const permission = checkPermission(route); if ( - (roleAdmin.value || checkPermission(route)?.attrOwnership == "OWNER") && + (roleAdmin.value || permission?.attrOwnership == "OWNER") && draft === "ส่งตัวแล้ว" ) { personalId.value = pid; @@ -858,34 +882,33 @@ async function filterRowsMain(type: string, pos: string) { }); } +// Helper function รอให้ permissions load เสร็จ +function waitForPermissions(): Promise { + return new Promise((resolve) => { + const checkPermissions = () => { + if (storeMenu.permissions) { + resolve(); + } else { + setTimeout(checkPermissions, 100); // เช็คทุก 100ms + } + }; + checkPermissions(); + }); +} + +// ปรับปรุง getWorkFlow function async function getWorkFlow() { showLoader(); + + // รอให้ permissions load เสร็จก่อน + await waitForPermissions(); + await http .get(config.API.workflowKeycloakSystem("SYS_PLACEMENT_PASS")) .then(async (res) => { const data = await res.data.result; DataStore.isOfficer = data.isOfficer; DataStore.isStaff = data.isStaff; - roleAdmin.value = - data.isOfficer || checkPermission(route)?.attrOwnership == "OWNER"; - if ( - roleAdmin.value === false && - checkPermission(route)?.attrOwnership !== "OWNER" - ) { - displayAdd.value = false; - // visibleColumns.value = [ - // "position", - // "fullName", - // "examNumber", - // "idCard", - // "positionNumber", - // "organizationName", - // "reportingDate", - // "bmaOfficer", - // "statusName", - // "positionCandidate", - // ]; - } }) .catch((e) => { messageError($q, e);