fix CurrentPage ===> จัดการผู้ใช้งาน
This commit is contained in:
parent
8aa17c7648
commit
72ba71c1f6
2 changed files with 26 additions and 1 deletions
|
|
@ -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
19
src/utils/functions.ts
Normal 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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue