fix bug: "ADMIN" only disable action

This commit is contained in:
Warunee Tamkoo 2025-11-08 21:35:03 +07:00
parent 3856035ce1
commit d4b61dd490
7 changed files with 75 additions and 23 deletions

View file

@ -1,5 +1,5 @@
<script setup lang="ts">
import { reactive, ref, watch } from "vue";
import { reactive, ref, watch, onMounted } from "vue";
import { useQuasar } from "quasar";
import { storeToRefs } from "pinia";
@ -8,6 +8,7 @@ import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
import { useDataStoreUser } from "@/modules/02_users/stores/main";
import { usekeycloakPosition } from "@/stores/keycloakPosition";
import { tokenParsed } from "@/plugins/auth";
import type { QTableProps } from "quasar";
import type {
@ -171,12 +172,17 @@ function onClose() {
selected.value = [];
}
const tokenParsedData = ref<string[]>([]);
/**
* อน checkbox ของผใชงานทกำลงลอกอนอย
* @param id รหสผใชงาน
*/
function hideCheckbox(id: string) {
if (dataPosition.value?.profileId === id) {
if (
dataPosition.value?.profileId === id &&
tokenParsedData.value.includes("ADMIN") &&
!tokenParsedData.value.includes("SUPER_ADMIN")
) {
return false;
} else {
return true;
@ -194,6 +200,11 @@ watch(
onSearchListPerson(true);
}
);
onMounted(async () => {
const token = await tokenParsed();
tokenParsedData.value = token?.role || [];
});
</script>
<template>

View file

@ -1,5 +1,5 @@
<script setup lang="ts">
import { reactive, ref, watch } from "vue";
import { reactive, ref, watch, onMounted } from "vue";
import { useQuasar } from "quasar";
import { storeToRefs } from "pinia";
@ -8,6 +8,7 @@ import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
import { useDataStoreUser } from "@/modules/02_users/stores/main";
import { usekeycloakPosition } from "@/stores/keycloakPosition";
import { tokenParsed } from "@/plugins/auth";
import type { QTableProps } from "quasar";
import type {
@ -187,12 +188,17 @@ function onClose() {
isCheck.value = false;
}
const tokenParsedData = ref<string[]>([]);
/**
* อน checkbox ของผใชงานทกำลงลอกอนอย
* @param id รหสผใชงาน
*/
function hideCheckbox(id: string) {
if (dataPosition.value?.profileId === id) {
if (
dataPosition.value?.profileId === id &&
tokenParsedData.value.includes("ADMIN") &&
!tokenParsedData.value.includes("SUPER_ADMIN")
) {
return false;
} else {
return true;
@ -210,6 +216,11 @@ watch(
onSearchListPerson(true);
}
);
onMounted(async () => {
const token = await tokenParsed();
tokenParsedData.value = token?.role || [];
});
</script>
<template>

View file

@ -232,8 +232,7 @@ async function fetchOrganizationActive() {
* @param id id โครงสราง
*/
async function fetchDataTree(id: string) {
const tokenParsedData = await tokenParsed();
const isSuperAdmin = tokenParsedData.role.includes("SUPER_ADMIN");
const isSuperAdmin = tokenParsedData.value.includes("SUPER_ADMIN");
if (!isSuperAdmin) {
nodeTree.value = [];
}
@ -436,13 +435,18 @@ watch(
}
);
const tokenParsedData = ref<string[]>([]);
/**
* ตรวจสอบการแสดงป action
* @param keycloakID keycloakID รหสผใชงาน
* @returns true หากผใชงานมทธในการดำเนนการ
*/
function checkhideBtnAction(keycloakID: string) {
if (dataPosition.value?.keycloak === keycloakID) {
if (
dataPosition.value?.keycloak === keycloakID &&
tokenParsedData.value.includes("ADMIN") &&
!tokenParsedData.value.includes("SUPER_ADMIN")
) {
return false;
} else {
return true;
@ -455,6 +459,8 @@ function checkhideBtnAction(keycloakID: string) {
*/
onMounted(async () => {
await fetchOrganizationActive();
const token = await tokenParsed();
tokenParsedData.value = token.role || [];
});
</script>

View file

@ -286,13 +286,13 @@ async function fetchOrganizationActive() {
});
}
const tokenParsedData = ref<string[]>([]);
/**
* function fetch อมลของ Tree
* @param id id โครงสราง
*/
async function fetchDataTree(id: string) {
const tokenParsedData = await tokenParsed();
const isSuperAdmin = tokenParsedData.role.includes("SUPER_ADMIN");
const isSuperAdmin = tokenParsedData.value.includes("SUPER_ADMIN");
if (!isSuperAdmin) {
nodes.value = [];
} else {
@ -501,15 +501,21 @@ function isUpload() {
* @returns true หากผใชงานมทธในการดำเนนการ
*/
function checkhideBtnAction(current_holderId: string) {
if (dataPosition.value?.profileId === current_holderId) {
if (
dataPosition.value?.profileId === current_holderId &&
tokenParsedData.value.includes("ADMIN") &&
!tokenParsedData.value.includes("SUPER_ADMIN")
) {
return false;
} else {
return true;
}
}
onMounted(() => {
onMounted(async () => {
fetchOrganizationActive();
const token = await tokenParsed();
tokenParsedData.value = token.role || [];
});
</script>

View file

@ -63,9 +63,8 @@ const personId = ref<string>("");
* งกนดงขอมลโครงสราง
* เกบขอมลโครงสรางไวใน nodeTree
*/
async function fatchOrg() {
const tokenParsedData = await tokenParsed();
const isSuperAdmin = tokenParsedData.role.includes("SUPER_ADMIN");
async function fetchOrg() {
const isSuperAdmin = tokenParsedData.value.includes("SUPER_ADMIN");
if (!isSuperAdmin) {
nodeTree.value = [];
}
@ -215,8 +214,13 @@ function updatemodalPersonal(modal: boolean) {
modalPersonal.value = modal;
}
const tokenParsedData = ref<string[]>([]);
function checkhideBtnAction(id: string) {
if (dataPosition.value?.profileId === id) {
if (
dataPosition.value?.profileId === id &&
tokenParsedData.value.includes("ADMIN") &&
!tokenParsedData.value.includes("SUPER_ADMIN")
) {
return false;
} else {
return true;
@ -236,7 +240,9 @@ watch(
/** hook ทำงานเมื่อ Components ถูกเรียกใช้งาน*/
onMounted(async () => {
await fatchOrg(); //
await fetchOrg(); //
const token = await tokenParsed();
tokenParsedData.value = token?.role || [];
});
</script>

View file

@ -273,13 +273,13 @@ async function fetchOrganizationActive() {
});
}
const tokenParsedData = ref<string[]>([]);
/**
* function fetch อมลของ Tree
* @param id id โครงสราง
*/
async function fetchDataTree(id: string) {
const tokenParsedData = await tokenParsed();
const isSuperAdmin = tokenParsedData.role.includes("SUPER_ADMIN");
const isSuperAdmin = tokenParsedData.value.includes("SUPER_ADMIN");
if (!isSuperAdmin) {
nodes.value = [];
}
@ -411,7 +411,11 @@ function updatemodalPersonal(modal: boolean) {
}
function hideBtnAction(id: string) {
if (dataPosition.value?.profileId === id) {
if (
dataPosition.value?.profileId === id &&
tokenParsedData.value.includes("ADMIN") &&
!tokenParsedData.value.includes("SUPER_ADMIN")
) {
return false;
} else {
return true;
@ -432,8 +436,10 @@ watch(
}
);
onMounted(() => {
onMounted(async () => {
fetchOrganizationActive();
const token = await tokenParsed();
tokenParsedData.value = token?.role || [];
});
</script>

View file

@ -82,13 +82,13 @@ async function fatchOrg() {
});
}
const tokenParsedData = ref<string[]>([]);
/**
* function fetch อมลของ Tree
* @param id id โครงสราง
*/
async function fetchDataTree(id: string) {
const tokenParsedData = await tokenParsed();
const isSuperAdmin = tokenParsedData.role.includes("SUPER_ADMIN");
const isSuperAdmin = tokenParsedData.value.includes("SUPER_ADMIN");
if (!isSuperAdmin) {
nodeTree.value = [];
}
@ -260,7 +260,11 @@ function updatemodalPersonal(modal: boolean) {
}
function hideBtnAction(id: string) {
if (dataPosition.value?.profileId === id) {
if (
dataPosition.value?.profileId === id &&
tokenParsedData.value.includes("ADMIN") &&
!tokenParsedData.value.includes("SUPER_ADMIN")
) {
return false;
} else {
return true;
@ -281,6 +285,8 @@ watch(
/** hook ทำงานเมื่อ Components ถูกเรียกใช้งาน*/
onMounted(async () => {
await fatchOrg(); //
const token = await tokenParsed();
tokenParsedData.value = token?.role || [];
});
</script>