กำหนดสิทธิ์จัดการโครงสร้าง

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2024-09-06 16:30:07 +07:00
parent 6e9c8bf593
commit 09fdfe9f20
2 changed files with 81 additions and 27 deletions

View file

@ -28,7 +28,12 @@ const nodeTree = ref<DataTree[]>([]); // ข้อมูลรายการโ
const expanded = ref<Array<string>>([]); //
const orgId = ref<string>(""); // id
async function fatchOrgg() {
/**
* งกนดงขอมลโครงสราง
*
* เกบขอมลโครงสรางไวใน nodeTree
*/
async function fatchOrg() {
showLoader();
await http
.get(config.API.permissionOrg)
@ -44,23 +49,34 @@ async function fatchOrgg() {
});
}
/**
* งกนเลอกหนวยงาน
* @param id หนวยงานทเลอก
*
* กำหนดคาของ qureyBody ใหเปนค defult และกำหนดคาของ qureyBody.id เปนหนวยงานทเลอก
* และดงขอมลรายชอคนททธดการโครงสรางในหนวยงานทเลอก
*/
function selectedOrg(id: string) {
orgId.value = id;
qureyBody.id = id;
qureyBody.searchKeyword = "";
qureyBody.searchField = "fullName";
qureyBody.page = 1;
qureyBody.pageSize = 10;
fetchListPerson(true);
}
/******* รายชื่อคนที่มีสิทธิ์จัดการโครงสร้าง *******/
const qureyBody = reactive<QueryProfile>({
searchKeyword: "",
searchField: "fullName",
page: 1,
pageSize: 10,
id: null,
searchKeyword: "", //
searchField: "fullName", // field
page: 1, //
pageSize: 10, //
id: null, //
});
const rows = ref<DataProfile[]>([]);
const total = ref<number>(0);
const maxPage = ref<number>(0);
const rows = ref<DataProfile[]>([]); //
const total = ref<number>(0); //
const maxPage = ref<number>(0); //
const columns = ref<QTableProps["columns"]>([
{
name: "fullName",
@ -112,9 +128,14 @@ const columns = ref<QTableProps["columns"]>([
style: "font-size: 14px",
},
]);
const modalAdd = ref<boolean>(false); // modal
const modalAdd = ref<boolean>(false);
/**
* งกนดงขอมลรายชอคนททธดการโครงสราง
* @param newPage โหลดหนาแรก าเป true โหลดหนาแรก false ใหโหลดหนาปจจ
*
* เกบมลรายชอคนททธดการโครงสรางไวใน rows.value
*/
async function fetchListPerson(newPage: boolean = false) {
qureyBody.page = newPage ? 1 : qureyBody.page;
showLoader();
@ -122,8 +143,8 @@ async function fetchListPerson(newPage: boolean = false) {
.post(config.API.permissionOrgProfile, qureyBody)
.then(async (res) => {
const data = await res.data.result;
maxPage.value = Math.ceil(data.total / qureyBody.pageSize);
total.value = data.total;
maxPage.value = Math.ceil(data.total / qureyBody.pageSize); //
total.value = data.total; //
rows.value = data.data;
})
.catch((err) => {
@ -134,19 +155,27 @@ async function fetchListPerson(newPage: boolean = false) {
});
}
/**
* งกนยนยนการลบรายชอคนททธดการโครงสราง
* @param id รายชอคนททธดการโครงสราง
*
* ลบเสรจจะโหลดขอมลรายชอคนททธดการโครงสราง
*/
function onDeletePerson(id: string) {
dialogRemove($q, async () => {
showLoader();
await http
.delete(config.API.permissionOrg + `/${id}`)
.then(async () => {
// maxPage.value 1
if (maxPage.value !== 1) {
// page 1
if (rows.value.length === 1) {
qureyBody.page = qureyBody.page - 1;
}
await fetchListPerson(false);
await fetchListPerson(false); //
} else {
await fetchListPerson(true);
await fetchListPerson(true); //
}
success($q, "ลบข้อมูสำเร็จ");
})
@ -167,6 +196,11 @@ function updatePagination(newPagination: Pagination) {
qureyBody.pageSize = newPagination.rowsPerPage;
}
/**
* การเปลยนแปลงของ pageSize ใน queryBody
*
* เม pageSize การเปลยนแปลงใหโหลดขอมลหนาแรก
*/
watch(
() => qureyBody.pageSize,
() => {
@ -180,8 +214,8 @@ watch(
*/
onMounted(async () => {
await Promise.all([
fatchOrgg(), //
fetchListPerson(),
fatchOrg(), //
fetchListPerson(), //
]);
});
</script>