ปรับ API จัดการผู้ใช้งาน

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2024-11-12 09:39:33 +07:00
parent cb7bbcb68b
commit c74f39aa46

View file

@ -10,6 +10,7 @@ import { useCounterMixin } from "@/stores/mixin";
/** importType*/ /** importType*/
import type { QTableProps } from "quasar"; import type { QTableProps } from "quasar";
import type { import type {
DataOption,
ItemsMenu, ItemsMenu,
Pagination, Pagination,
} from "@/modules/02_users/interface/index/Main"; } from "@/modules/02_users/interface/index/Main";
@ -37,6 +38,7 @@ const currentPage = ref<number>(1); // หน้า
const total = ref<number>(0); // const total = ref<number>(0); //
const maxPage = ref<number>(0); // const maxPage = ref<number>(0); //
const pageSize = ref<number>(10); // const pageSize = ref<number>(10); //
const employeeClass = ref<string>("officer");
const columns = ref<QTableProps["columns"]>([ const columns = ref<QTableProps["columns"]>([
{ {
name: "no", name: "no",
@ -149,24 +151,28 @@ const itemMenu = ref<ItemsMenu[]>([
}, },
]); ]);
const employeeClassMain = ref<DataOption[]>([
{ id: "employee", name: "ลูกจ้างประจำ" },
{ id: "officer", name: "ข้าราชการ" },
]);
const employeeClassOption = ref<DataOption[]>(employeeClassMain.value);
/** /**
* งกนดงขอมลรายชอผใชงาน * งกนดงขอมลรายชอผใชงาน
*/ */
async function fetchListUsers() { async function fetchListUsers() {
let max = pageSize.value;
let first = (currentPage.value - 1) * pageSize.value;
showLoader(); showLoader();
await http await http
.get( .get(
config.API.managementUser + config.API.managementUser +
`?max=${max}&first=${first}&search=${keyword.value}` `?pageSize=${pageSize.value}&page=${currentPage.value}&keyword=${keyword.value}&type=${employeeClass.value}`
) )
.then(async (res) => { .then(async (res) => {
const data = await res.data.data; const data = await res.data.result;
total.value = data.total;
total.value = res.data.total;
maxPage.value = Math.ceil(total.value / pageSize.value); maxPage.value = Math.ceil(total.value / pageSize.value);
rows.value = data.map((e: Users) => ({ rows.value = data.data.map((e: Users) => ({
...e, ...e,
roles: Array.isArray(e.roles) roles: Array.isArray(e.roles)
? e.roles.filter( ? e.roles.filter(
@ -288,6 +294,24 @@ function updatePagination(initialPagination: Pagination) {
pageSize.value = initialPagination.rowsPerPage; pageSize.value = initialPagination.rowsPerPage;
} }
/**
* function นหาขอม Option
* @param val คำคนหา
* @param update function
* @param type ประเภท option
*/
function filterFnOptions(val: string, update: Function, type: string) {
switch (type) {
case "employeeClass":
update(() => {
employeeClassOption.value = employeeClassMain.value.filter(
(v: DataOption) => v.name.indexOf(val) > -1
);
});
break;
}
}
/** /**
* การเปลยนแปลงของจำนวนขอมลตอหน * การเปลยนแปลงของจำนวนขอมลตอหน
* *
@ -318,8 +342,38 @@ onMounted(async () => {
</div> </div>
<q-card flast bordered class="q-pa-md"> <q-card flast bordered class="q-pa-md">
<div class="items-center col-12 row q-col-gutter-sm q-mb-sm"> <div class="items-center col-12 row q-col-gutter-sm">
<q-btn flat round dense color="primary" icon="add" @click="openDialog()"> <q-select
outlined
dense
v-model="employeeClass"
:options="employeeClassOption"
label="สถานภาพ"
emit-value
map-options
option-label="name"
option-value="id"
use-input
style="width: 230px"
@update:model-value="(currentPage = 1), fetchListUsers()"
@filter="(inputValue: string,
doneFn: Function) => filterFnOptions(inputValue, doneFn,'employeeClass')"
><template v-slot:no-option>
<q-item>
<q-item-section class="text-grey"> ไมอม </q-item-section>
</q-item>
</template>
</q-select>
<q-btn
class="q-ml-sm"
flat
round
dense
color="primary"
icon="add"
@click="openDialog()"
>
<q-tooltip>เพมผใชงาน </q-tooltip> <q-tooltip>เพมผใชงาน </q-tooltip>
</q-btn> </q-btn>
<q-space /> <q-space />