ปรับสิทธิ์

This commit is contained in:
setthawutttty 2024-10-09 14:49:22 +07:00
parent b356eef92f
commit c8a9dbb259
3 changed files with 27 additions and 22 deletions

View file

@ -6,6 +6,7 @@ import { useRouter, useRoute } from "vue-router";
import http from "@/plugins/http";
import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
import { setAuthen, authenticated, tokenParsed } from "@/plugins/auth";
/** importType*/
import type { QTableProps } from "quasar";
@ -18,6 +19,7 @@ import DialogAddRoleUser from "@/modules/02_users/components/Users/DialogRoleUse
const $q = useQuasar();
const router = useRouter();
const route = useRoute();
const roleSuper = ref<boolean>(false);
const { dialogRemove, messageError, showLoader, hideLoader, success } =
useCounterMixin();
@ -66,13 +68,11 @@ async function fetchListRoleUser() {
http
.get(config.API.managementUser + `/role/${userId.value}`)
.then(async (res) => {
rows.value = await res.data.filter(
(e: Roles) =>
e.name === "STAFF" ||
e.name === "SUPER_ADMIN" ||
e.name === "ADMIN" ||
e.name === "USER"
);
const item = roleSuper.value
? ["STAFF", "SUPER_ADMIN", "ADMIN", "USER"]
: ["STAFF", "USER"];
rows.value = await res.data.filter((e: Roles) => item.includes(e.name));
})
.catch((err) => {
messageError($q, err);
@ -118,8 +118,10 @@ function openDialog() {
*
* โหลดขอมลรายการสทธ
*/
onMounted(() => {
fetchListRoleUser();
onMounted(async () => {
const checkToken: any = await tokenParsed();
roleSuper.value = await checkToken.role.includes("SUPER_ADMIN");
await fetchListRoleUser();
});
</script>
@ -209,6 +211,7 @@ onMounted(() => {
v-model:modal="modalDialogAdd"
:userId="userId"
:roles="rows"
v-model:role-super="roleSuper"
/>
</template>