From 72ba71c1f6e92dfca2b305742c39a5b77cb61c42 Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Fri, 11 Jul 2025 10:14:20 +0700 Subject: [PATCH] =?UTF-8?q?fix=20CurrentPage=20=3D=3D=3D>=20=E0=B8=88?= =?UTF-8?q?=E0=B8=B1=E0=B8=94=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B8=9C=E0=B8=B9?= =?UTF-8?q?=E0=B9=89=E0=B9=83=E0=B8=8A=E0=B9=89=E0=B8=87=E0=B8=B2=E0=B8=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/02_users/views/01_user.vue | 8 +++++++- src/utils/functions.ts | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/utils/functions.ts 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; +}