diff --git a/src/modules/02_users/views/01_user.vue b/src/modules/02_users/views/01_user.vue index a2f5bddb..6c5d5aa7 100644 --- a/src/modules/02_users/views/01_user.vue +++ b/src/modules/02_users/views/01_user.vue @@ -6,6 +6,7 @@ import { useRouter } from "vue-router"; import http from "@/plugins/http"; import config from "@/app.config"; import { useCounterMixin } from "@/stores/mixin"; +import { updateCurrentPage } from "@/utils/functions"; /** importType*/ import type { QTableProps } from "quasar"; @@ -233,12 +234,17 @@ function openDialog() { * @param id รายการผู้ใช้งาน * ลบข้อมูลรายชื่อเสร็จแล้วทำการดึงข้อมูลรายชื่อผู้ใช้งานใหม่ */ -function onDeleteUser(id: string) { +async function onDeleteUser(id: string) { dialogRemove($q, () => { showLoader(); http .delete(config.API.managementUser + `/${id}`) .then(async () => { + currentPage.value = await updateCurrentPage( + currentPage.value, + maxPage.value, + rows.value.length + ); await fetchListUsers(); success($q, "ลบข้อมูลสำเร็จ"); }) diff --git a/src/utils/functions.ts b/src/utils/functions.ts new file mode 100644 index 00000000..2c3d4874 --- /dev/null +++ b/src/utils/functions.ts @@ -0,0 +1,19 @@ +/** + * คำนวณหน้าที่จะแสดงหลังจากลบข้อมูล + * + * @param page หน้าปัจจุบัน + * @param maxPage หน้าสุดท้าย + * @param total จำนวนข้อมูลในหน้าปัจจุบัน + * @returns หน้าที่ควรแสดง + */ +export async function updateCurrentPage( + page: number, + maxPage: number, + total: number +) { + // ถ้าหน้าปัจจุบันไม่ใช่หน้าแรก และเป็นหน้าสุดท้าย และมีข้อมูลเหลือ 1 รายการ ให้กลับไปหน้าก่อนหน้า + if (page > 1 && page === maxPage && total === 1) { + return page - 1; + } + return page; +}