จัดการบทบาทและสิทธิ์ => API
This commit is contained in:
parent
8a53037137
commit
ca0c31fc29
6 changed files with 135 additions and 140 deletions
|
|
@ -1,9 +1,13 @@
|
||||||
import env from "../index";
|
import env from "../index";
|
||||||
|
|
||||||
const management = `${env.API_URI}/org/keycloak`;
|
const management = `${env.API_URI}/org/keycloak`;
|
||||||
|
const managementAuth = `${env.API_URI}/org/auth/authRole`;
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
management,
|
management,
|
||||||
managementUser: `${management}/user`,
|
managementUser: `${management}/user`,
|
||||||
managementRole: `${management}/role`,
|
managementRole: `${management}/role`,
|
||||||
|
|
||||||
|
/** จัดการบทบาทและสิทธิ์*/
|
||||||
|
managementAuth,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, reactive, watch } from "vue";
|
import { ref, reactive, watch } from "vue";
|
||||||
import { useQuasar } from "quasar";
|
import { useQuasar } from "quasar";
|
||||||
|
import { useRouter } from "vue-router";
|
||||||
|
|
||||||
import http from "@/plugins/http";
|
import http from "@/plugins/http";
|
||||||
import config from "@/app.config";
|
import config from "@/app.config";
|
||||||
|
|
||||||
|
|
@ -14,101 +16,56 @@ import { useCounterMixin } from "@/stores/mixin";
|
||||||
|
|
||||||
/** use*/
|
/** use*/
|
||||||
const $q = useQuasar();
|
const $q = useQuasar();
|
||||||
|
const router = useRouter();
|
||||||
const { showLoader, hideLoader, dialogConfirm, messageError, success } =
|
const { showLoader, hideLoader, dialogConfirm, messageError, success } =
|
||||||
useCounterMixin();
|
useCounterMixin();
|
||||||
|
|
||||||
/** props*/
|
/** props*/
|
||||||
const modal = defineModel<boolean>("modal", { required: true });
|
const modal = defineModel<boolean>("modal", { required: true });
|
||||||
const isStatusEdit = defineModel<boolean>("isStatusEdit", { required: true });
|
|
||||||
const roleId = defineModel<string>("roleId", { required: true });
|
|
||||||
const props = defineProps({
|
|
||||||
fetchlist: {
|
|
||||||
type: Function,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const formData = reactive<FormRole>({
|
const formData = reactive<FormRole>({
|
||||||
role: "",
|
roleName: "",
|
||||||
description: "",
|
roleDescription: "",
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
|
||||||
* function fetch ข้อมูลผู้ใช้งาน
|
|
||||||
* @param id ผู้ใช้งาน
|
|
||||||
*/
|
|
||||||
function fetchRoleDetail(id: string) {
|
|
||||||
// showLoader();
|
|
||||||
// http
|
|
||||||
// .get(config.API.managementUser + `/${id}`)
|
|
||||||
// .then((res) => {
|
|
||||||
// const data = res.data;
|
|
||||||
// formData.username = data.username;
|
|
||||||
// formData.firstName = data.firstName;
|
|
||||||
// formData.lastName = data.lastName;
|
|
||||||
// formData.email = data.email;
|
|
||||||
// })
|
|
||||||
// .catch((err) => {
|
|
||||||
// messageError($q, err);
|
|
||||||
// })
|
|
||||||
// .finally(() => {
|
|
||||||
// hideLoader();
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
|
|
||||||
/** function บันทึกข้อมูลผู้ใช้งาน*/
|
/** function บันทึกข้อมูลผู้ใช้งาน*/
|
||||||
function onSubmit() {
|
function onSubmit() {
|
||||||
dialogConfirm($q, () => {
|
dialogConfirm($q, () => {
|
||||||
// showLoader();
|
showLoader();
|
||||||
// const url = isStatusEdit.value
|
http
|
||||||
// ? config.API.managementUser + `/${roleId.value}`
|
.post(config.API.managementAuth, formData)
|
||||||
// : config.API.managementUser;
|
.then((res) => {
|
||||||
// http[isStatusEdit.value ? "put" : "post"](url, formData)
|
closeDialog();
|
||||||
// .then(() => {
|
router.push(`/roles/${res.data.result}`);
|
||||||
// success($q, "บันทึกข้อมูลสำเร็จ");
|
})
|
||||||
// props.fetchlist?.();
|
.catch((e) => {
|
||||||
closeDialog();
|
messageError($q, e);
|
||||||
// })
|
})
|
||||||
// .catch((e) => {
|
.finally(() => {
|
||||||
// messageError($q, e);
|
hideLoader();
|
||||||
// })
|
});
|
||||||
// .finally(() => {
|
|
||||||
// hideLoader();
|
|
||||||
// });
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** function ปิด Dialog */
|
/** function ปิด Dialog */
|
||||||
function closeDialog() {
|
function closeDialog() {
|
||||||
modal.value = false;
|
modal.value = false;
|
||||||
formData.role = "";
|
formData.roleName = "";
|
||||||
formData.description = "";
|
formData.roleDescription = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(
|
|
||||||
() => modal.value,
|
|
||||||
() => {
|
|
||||||
if (modal.value && isStatusEdit.value) {
|
|
||||||
fetchRoleDetail(roleId.value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<q-dialog v-model="modal" persistent>
|
<q-dialog v-model="modal" persistent>
|
||||||
<q-card class="col-12" style="width: 25%">
|
<q-card class="col-12" style="width: 25%">
|
||||||
<q-form greedy @submit.prevent @validation-success="onSubmit">
|
<q-form greedy @submit.prevent @validation-success="onSubmit">
|
||||||
<DialogHeader
|
<DialogHeader :tittle="'เพิ่มบทบาท'" :close="closeDialog" />
|
||||||
:tittle="isStatusEdit ? 'แก้ไขบทบาท' : 'เพิ่มบทบาท'"
|
|
||||||
:close="closeDialog"
|
|
||||||
/>
|
|
||||||
<q-separator />
|
<q-separator />
|
||||||
<q-card-section>
|
<q-card-section>
|
||||||
<div class="row q-col-gutter-md">
|
<div class="row q-col-gutter-md">
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<q-input
|
<q-input
|
||||||
v-model="formData.role"
|
v-model="formData.roleName"
|
||||||
outlined
|
outlined
|
||||||
dense
|
dense
|
||||||
:rules="[(val:string) => !!val || `${'กรุณากรอกชื่อบทบาท'}`,]"
|
:rules="[(val:string) => !!val || `${'กรุณากรอกชื่อบทบาท'}`,]"
|
||||||
|
|
@ -120,7 +77,7 @@ watch(
|
||||||
</div>
|
</div>
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<q-input
|
<q-input
|
||||||
v-model="formData.description"
|
v-model="formData.roleDescription"
|
||||||
outlined
|
outlined
|
||||||
dense
|
dense
|
||||||
:rules="[(val:string) => !!val || `${'กรุณากรอกคำอิบาย'}`,]"
|
:rules="[(val:string) => !!val || `${'กรุณากรอกคำอิบาย'}`,]"
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ interface FormUser {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface FormRole {
|
interface FormRole {
|
||||||
role: string;
|
roleName: string;
|
||||||
description: string;
|
roleDescription: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Roles {
|
interface Roles {
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,15 @@ interface Users {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Roles {
|
interface Roles {
|
||||||
clientRole?: boolean;
|
createdAt: string;
|
||||||
composite?: boolean;
|
createdFullName: string;
|
||||||
containerId?: string;
|
createdUserId: string;
|
||||||
description: string;
|
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
lastUpdateFullName: string;
|
||||||
|
lastUpdateUserId: string;
|
||||||
|
lastUpdatedAt: string;
|
||||||
|
roleDescription: string;
|
||||||
|
roleName: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface NodeTree {
|
interface NodeTree {
|
||||||
|
|
|
||||||
|
|
@ -23,13 +23,7 @@ const { dialogRemove, messageError, showLoader, hideLoader, success } =
|
||||||
useCounterMixin();
|
useCounterMixin();
|
||||||
|
|
||||||
/** Table*/
|
/** Table*/
|
||||||
const rows = ref<Roles[]>([
|
const rows = ref<Roles[]>([]);
|
||||||
{
|
|
||||||
id: "1",
|
|
||||||
name: "ชื่อบทบาท",
|
|
||||||
description: "คำอธิบาย",
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
const columns = ref<QTableProps["columns"]>([
|
const columns = ref<QTableProps["columns"]>([
|
||||||
{
|
{
|
||||||
name: "no",
|
name: "no",
|
||||||
|
|
@ -41,30 +35,28 @@ const columns = ref<QTableProps["columns"]>([
|
||||||
style: "font-size: 14px",
|
style: "font-size: 14px",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "name",
|
name: "roleName",
|
||||||
align: "left",
|
align: "left",
|
||||||
label: "ชื่อบทบาท",
|
label: "ชื่อบทบาท",
|
||||||
sortable: true,
|
sortable: true,
|
||||||
field: "name",
|
field: "roleName",
|
||||||
headerStyle: "font-size: 14px",
|
headerStyle: "font-size: 14px",
|
||||||
style: "font-size: 14px",
|
style: "font-size: 14px",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "description",
|
name: "roleDescription",
|
||||||
align: "left",
|
align: "left",
|
||||||
label: "คำอธิบาย",
|
label: "คำอธิบาย",
|
||||||
sortable: true,
|
sortable: true,
|
||||||
field: "description",
|
field: "roleDescription",
|
||||||
headerStyle: "font-size: 14px",
|
headerStyle: "font-size: 14px",
|
||||||
style: "font-size: 14px",
|
style: "font-size: 14px",
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
const visibleColumns = ref<string[]>(["no", "name", "description"]);
|
const visibleColumns = ref<string[]>(["no", "roleName", "roleDescription"]);
|
||||||
const keyword = ref<string>("");
|
const keyword = ref<string>("");
|
||||||
|
|
||||||
const modalDialogAdd = ref<boolean>(false);
|
const modalDialogAdd = ref<boolean>(false);
|
||||||
const isStatusEdit = ref<boolean>(false);
|
|
||||||
const roleId = ref<string>("");
|
|
||||||
|
|
||||||
/** List Mune*/
|
/** List Mune*/
|
||||||
const itemMenu = ref<ItemsMenu[]>([
|
const itemMenu = ref<ItemsMenu[]>([
|
||||||
|
|
@ -84,19 +76,19 @@ const itemMenu = ref<ItemsMenu[]>([
|
||||||
|
|
||||||
/** function fetch รายการบทบาท*/
|
/** function fetch รายการบทบาท*/
|
||||||
function fetchListRole() {
|
function fetchListRole() {
|
||||||
// showLoader();
|
showLoader();
|
||||||
// http
|
http
|
||||||
// .get(config.API.managementUser)
|
.get(config.API.managementAuth + `/list`)
|
||||||
// .then((res) => {
|
.then((res) => {
|
||||||
// const data = res.data;
|
const data = res.data.result;
|
||||||
// rows.value = data;
|
rows.value = data;
|
||||||
// })
|
})
|
||||||
// .catch((err) => {
|
.catch((err) => {
|
||||||
// messageError($q, err);
|
messageError($q, err);
|
||||||
// })
|
})
|
||||||
// .finally(() => {
|
.finally(() => {
|
||||||
// hideLoader();
|
hideLoader();
|
||||||
// });
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -106,9 +98,7 @@ function fetchListRole() {
|
||||||
*/
|
*/
|
||||||
function onClickAction(type: string, data: Roles) {
|
function onClickAction(type: string, data: Roles) {
|
||||||
if (type === "edit") {
|
if (type === "edit") {
|
||||||
modalDialogAdd.value = true;
|
router.push(`/roles/${data.id}`);
|
||||||
isStatusEdit.value = true;
|
|
||||||
roleId.value = data.id;
|
|
||||||
} else if (type === "delete") {
|
} else if (type === "delete") {
|
||||||
onDeleteRole(data.id);
|
onDeleteRole(data.id);
|
||||||
}
|
}
|
||||||
|
|
@ -116,8 +106,6 @@ function onClickAction(type: string, data: Roles) {
|
||||||
|
|
||||||
function openDialog() {
|
function openDialog() {
|
||||||
modalDialogAdd.value = true;
|
modalDialogAdd.value = true;
|
||||||
isStatusEdit.value = false;
|
|
||||||
roleId.value = "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -126,26 +114,22 @@ function openDialog() {
|
||||||
*/
|
*/
|
||||||
function onDeleteRole(id: string) {
|
function onDeleteRole(id: string) {
|
||||||
dialogRemove($q, () => {
|
dialogRemove($q, () => {
|
||||||
// showLoader();
|
showLoader();
|
||||||
// http
|
http
|
||||||
// .delete(config.API.managementUser + `/${id}`)
|
.delete(config.API.managementAuth + `/${id}`)
|
||||||
// .then(() => {
|
.then(() => {
|
||||||
// success($q, "ลบข้อมูลสำเร็จ");
|
success($q, "ลบข้อมูลสำเร็จ");
|
||||||
// fetchListRole();
|
fetchListRole();
|
||||||
// })
|
})
|
||||||
// .catch((err) => {
|
.catch((err) => {
|
||||||
// messageError($q, err);
|
messageError($q, err);
|
||||||
// })
|
})
|
||||||
// .finally(() => {
|
.finally(() => {
|
||||||
// hideLoader();
|
hideLoader();
|
||||||
// });
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function viewDetail(id: string) {
|
|
||||||
router.push(`/roles/${id}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
fetchListRole();
|
fetchListRole();
|
||||||
});
|
});
|
||||||
|
|
@ -216,12 +200,7 @@ onMounted(() => {
|
||||||
</template>
|
</template>
|
||||||
<template v-slot:body="props">
|
<template v-slot:body="props">
|
||||||
<q-tr :props="props" class="cursor-pointer">
|
<q-tr :props="props" class="cursor-pointer">
|
||||||
<q-td
|
<q-td v-for="col in props.cols" :key="col.name" :props="props">
|
||||||
v-for="col in props.cols"
|
|
||||||
:key="col.name"
|
|
||||||
:props="props"
|
|
||||||
@click="viewDetail(props.row.id)"
|
|
||||||
>
|
|
||||||
<div>
|
<div>
|
||||||
{{ col.value ? col.value : "-" }}
|
{{ col.value ? col.value : "-" }}
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -265,12 +244,9 @@ onMounted(() => {
|
||||||
</div>
|
</div>
|
||||||
</q-card>
|
</q-card>
|
||||||
|
|
||||||
<DialogAddRole
|
<DialogAddRole v-model:modal="modalDialogAdd" />
|
||||||
:fetchlist="fetchListRole"
|
<!-- :fetchlist="fetchListRole" v-model:isStatusEdit="isStatusEdit"
|
||||||
v-model:modal="modalDialogAdd"
|
:roleId="roleId" -->
|
||||||
v-model:isStatusEdit="isStatusEdit"
|
|
||||||
:roleId="roleId"
|
|
||||||
/>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped></style>
|
<style scoped></style>
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,20 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { reactive, ref } from "vue";
|
import { onMounted, reactive, ref } from "vue";
|
||||||
import { useRouter } from "vue-router";
|
import { useRouter, useRoute } from "vue-router";
|
||||||
|
import { useQuasar } from "quasar";
|
||||||
|
import http from "@/plugins/http";
|
||||||
|
import config from "@/app.config";
|
||||||
|
|
||||||
import type { FormRole } from "@/modules/02_users/interface/request/Main";
|
import type { FormRole } from "@/modules/02_users/interface/request/Main";
|
||||||
|
|
||||||
|
/** importStore*/
|
||||||
|
import { useCounterMixin } from "@/stores/mixin";
|
||||||
|
|
||||||
|
/** use*/
|
||||||
|
const $q = useQuasar();
|
||||||
|
const { dialogConfirm, messageError, showLoader, hideLoader, success } =
|
||||||
|
useCounterMixin();
|
||||||
|
|
||||||
const attrPrivilege = ref<any[]>([]);
|
const attrPrivilege = ref<any[]>([]);
|
||||||
const attrPrivilegeOp = ref<any[]>([
|
const attrPrivilegeOp = ref<any[]>([
|
||||||
{
|
{
|
||||||
|
|
@ -23,9 +35,12 @@ const attrPrivilegeOp = ref<any[]>([
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const route = useRoute();
|
||||||
|
|
||||||
|
const roleId = ref<string>(route.params.id.toString());
|
||||||
const formData = reactive<FormRole>({
|
const formData = reactive<FormRole>({
|
||||||
role: "",
|
roleName: "",
|
||||||
description: "",
|
roleDescription: "",
|
||||||
});
|
});
|
||||||
|
|
||||||
const columns = ref<any>([]);
|
const columns = ref<any>([]);
|
||||||
|
|
@ -1154,9 +1169,49 @@ const systemLists = ref<any>([
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
function fetchDataRole() {
|
||||||
|
showLoader();
|
||||||
|
http
|
||||||
|
.get(config.API.managementAuth + `/${roleId.value}`)
|
||||||
|
.then((res) => {
|
||||||
|
const data = res.data.result;
|
||||||
|
formData.roleName = data.roleName;
|
||||||
|
formData.roleDescription = data.roleDescription;
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
messageError($q, err);
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
hideLoader();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function onSubmit() {
|
function onSubmit() {
|
||||||
|
dialogConfirm($q, () => {
|
||||||
|
showLoader();
|
||||||
|
const body = {
|
||||||
|
...formData,
|
||||||
|
authRoleAttrs: [],
|
||||||
|
};
|
||||||
|
http
|
||||||
|
.patch(config.API.managementAuth + `/${roleId.value}`, body)
|
||||||
|
.then(() => {
|
||||||
|
success($q, "บันทึกข้อมูลสำเร็จ");
|
||||||
|
fetchDataRole();
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
messageError($q, err);
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
hideLoader();
|
||||||
|
});
|
||||||
|
});
|
||||||
console.log(systemLists.value);
|
console.log(systemLists.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
fetchDataRole();
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
@ -1182,7 +1237,7 @@ function onSubmit() {
|
||||||
<div class="row q-col-gutter-md">
|
<div class="row q-col-gutter-md">
|
||||||
<div class="col-4">
|
<div class="col-4">
|
||||||
<q-input
|
<q-input
|
||||||
v-model="formData.role"
|
v-model="formData.roleName"
|
||||||
outlined
|
outlined
|
||||||
dense
|
dense
|
||||||
:rules="[(val:string) => !!val || `${'กรุณากรอกชื่อบทบาท'}`,]"
|
:rules="[(val:string) => !!val || `${'กรุณากรอกชื่อบทบาท'}`,]"
|
||||||
|
|
@ -1194,7 +1249,7 @@ function onSubmit() {
|
||||||
</div>
|
</div>
|
||||||
<div class="col-8">
|
<div class="col-8">
|
||||||
<q-input
|
<q-input
|
||||||
v-model="formData.description"
|
v-model="formData.roleDescription"
|
||||||
outlined
|
outlined
|
||||||
dense
|
dense
|
||||||
lazy-rules
|
lazy-rules
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue