fix CurrentPage ===> จัดการผู้ใช้งาน

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2025-07-11 10:14:20 +07:00
parent 8aa17c7648
commit 72ba71c1f6
2 changed files with 26 additions and 1 deletions

View file

@ -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, "ลบข้อมูลสำเร็จ");
})

19
src/utils/functions.ts Normal file
View file

@ -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;
}