2024-05-30 14:04:48 +07:00
|
|
|
<script setup lang="ts">
|
2024-05-31 15:08:11 +07:00
|
|
|
import { ref, onMounted, watch } from "vue";
|
2024-05-30 14:04:48 +07:00
|
|
|
import { useQuasar } from "quasar";
|
2024-05-31 15:08:11 +07:00
|
|
|
import { useRouter } from "vue-router";
|
2024-05-30 14:04:48 +07:00
|
|
|
import http from "@/plugins/http";
|
|
|
|
|
import config from "@/app.config";
|
|
|
|
|
|
2024-05-30 14:24:36 +07:00
|
|
|
/** importType*/
|
2024-05-30 14:04:48 +07:00
|
|
|
import type { QTableProps } from "quasar";
|
|
|
|
|
import type { ItemsMenu } from "@/modules/02_users/interface/index/Main";
|
2024-05-31 15:08:11 +07:00
|
|
|
import type { Users, Roles } from "@/modules/02_users/interface/response/Main";
|
2024-05-30 14:04:48 +07:00
|
|
|
|
|
|
|
|
/** importComponents*/
|
|
|
|
|
import DialogAddUser from "@/modules/02_users/components/Users/DialogAddUser.vue";
|
2024-05-31 15:08:11 +07:00
|
|
|
// import DialogManagementRole from "@/modules/02_users/components/Users/DialogManagementRole.vue";
|
2024-05-30 14:04:48 +07:00
|
|
|
|
|
|
|
|
/** importStore*/
|
|
|
|
|
import { useCounterMixin } from "@/stores/mixin";
|
|
|
|
|
|
2024-05-30 14:24:36 +07:00
|
|
|
/** use*/
|
2024-05-30 14:04:48 +07:00
|
|
|
const $q = useQuasar();
|
2024-05-31 15:08:11 +07:00
|
|
|
const router = useRouter();
|
2024-05-30 14:24:36 +07:00
|
|
|
const { dialogRemove, messageError, showLoader, hideLoader, success } =
|
|
|
|
|
useCounterMixin();
|
2024-05-30 14:04:48 +07:00
|
|
|
|
|
|
|
|
/** Table*/
|
|
|
|
|
const rows = ref<Users[]>([]);
|
2024-05-31 15:08:11 +07:00
|
|
|
const total = ref<number>(0);
|
|
|
|
|
const currentPage = ref<number>(1);
|
|
|
|
|
const maxPage = ref<number>(0);
|
|
|
|
|
const pageSize = ref<number>(10);
|
2024-05-30 14:04:48 +07:00
|
|
|
const columns = ref<QTableProps["columns"]>([
|
|
|
|
|
{
|
|
|
|
|
name: "no",
|
|
|
|
|
align: "left",
|
|
|
|
|
label: "ลำดับ",
|
|
|
|
|
sortable: true,
|
2024-05-31 15:08:11 +07:00
|
|
|
field: (row) =>
|
|
|
|
|
(currentPage.value - 1) * pageSize.value + rows.value.indexOf(row) + 1,
|
2024-05-30 14:04:48 +07:00
|
|
|
headerStyle: "font-size: 14px",
|
|
|
|
|
style: "font-size: 14px",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "username",
|
|
|
|
|
align: "left",
|
|
|
|
|
label: "ชื่อผู้ใช้งาน",
|
|
|
|
|
sortable: true,
|
|
|
|
|
field: "username",
|
|
|
|
|
headerStyle: "font-size: 14px",
|
|
|
|
|
style: "font-size: 14px",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "email",
|
|
|
|
|
align: "left",
|
|
|
|
|
label: "Email",
|
|
|
|
|
sortable: true,
|
|
|
|
|
field: "email",
|
|
|
|
|
headerStyle: "font-size: 14px",
|
|
|
|
|
style: "font-size: 14px",
|
|
|
|
|
},
|
|
|
|
|
{
|
2024-05-31 15:08:11 +07:00
|
|
|
name: "firstname",
|
2024-05-30 14:04:48 +07:00
|
|
|
align: "left",
|
|
|
|
|
label: "ชื่อ",
|
|
|
|
|
sortable: true,
|
2024-05-31 15:08:11 +07:00
|
|
|
field: "firstname",
|
2024-05-30 14:04:48 +07:00
|
|
|
headerStyle: "font-size: 14px",
|
|
|
|
|
style: "font-size: 14px",
|
|
|
|
|
},
|
|
|
|
|
{
|
2024-05-31 15:08:11 +07:00
|
|
|
name: "lastname",
|
2024-05-30 14:04:48 +07:00
|
|
|
align: "left",
|
|
|
|
|
label: "นามสกุล",
|
|
|
|
|
sortable: true,
|
2024-05-31 15:08:11 +07:00
|
|
|
field: "lastname",
|
2024-05-30 14:04:48 +07:00
|
|
|
headerStyle: "font-size: 14px",
|
|
|
|
|
style: "font-size: 14px",
|
|
|
|
|
},
|
2024-05-31 15:08:11 +07:00
|
|
|
{
|
|
|
|
|
name: "role",
|
|
|
|
|
align: "left",
|
|
|
|
|
label: "สิทธิ์",
|
|
|
|
|
sortable: true,
|
|
|
|
|
headerStyle: "font-size: 14px",
|
|
|
|
|
style: "font-size: 14px",
|
|
|
|
|
field: (row) => {
|
2024-06-13 09:59:02 +07:00
|
|
|
const names = row.roles.map((role: Roles) => role.roleName);
|
2024-05-31 15:08:11 +07:00
|
|
|
return names.join(", ");
|
|
|
|
|
},
|
|
|
|
|
},
|
2024-05-30 14:04:48 +07:00
|
|
|
]);
|
|
|
|
|
const visibleColumns = ref<string[]>([
|
|
|
|
|
"no",
|
|
|
|
|
"username",
|
|
|
|
|
"email",
|
2024-05-31 15:08:11 +07:00
|
|
|
"firstname",
|
|
|
|
|
"lastname",
|
|
|
|
|
"role",
|
2024-05-30 14:04:48 +07:00
|
|
|
]);
|
|
|
|
|
const keyword = ref<string>("");
|
|
|
|
|
|
2024-05-31 15:08:11 +07:00
|
|
|
/** addUser*/
|
2024-05-30 14:04:48 +07:00
|
|
|
const modalDialogAdd = ref<boolean>(false);
|
|
|
|
|
const isStatusEdit = ref<boolean>(false);
|
|
|
|
|
const userId = ref<string>("");
|
|
|
|
|
|
|
|
|
|
/** List Mune*/
|
|
|
|
|
const itemMenu = ref<ItemsMenu[]>([
|
|
|
|
|
{
|
|
|
|
|
label: "แก้ไข",
|
|
|
|
|
icon: "edit",
|
|
|
|
|
color: "edit",
|
|
|
|
|
type: "edit",
|
|
|
|
|
},
|
2024-05-31 15:08:11 +07:00
|
|
|
{
|
|
|
|
|
label: "จัดการสิทธิ์",
|
|
|
|
|
icon: "mdi-account-group",
|
|
|
|
|
color: "blue-9",
|
|
|
|
|
type: "managementRole",
|
|
|
|
|
},
|
2024-05-30 14:04:48 +07:00
|
|
|
{
|
|
|
|
|
label: "ลบ",
|
|
|
|
|
icon: "delete",
|
|
|
|
|
color: "red",
|
|
|
|
|
type: "delete",
|
|
|
|
|
},
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
/** function fetch รายชื่อผู้ใช้งาน*/
|
|
|
|
|
function fetchListUsers() {
|
2024-05-31 15:08:11 +07:00
|
|
|
let max = pageSize.value;
|
|
|
|
|
let first = (currentPage.value - 1) * pageSize.value;
|
2024-05-30 14:04:48 +07:00
|
|
|
showLoader();
|
|
|
|
|
http
|
2024-05-31 15:08:11 +07:00
|
|
|
.get(
|
|
|
|
|
config.API.managementUser +
|
|
|
|
|
`?max=${max}&first=${first}&search=${keyword.value}`
|
|
|
|
|
)
|
2024-05-30 14:04:48 +07:00
|
|
|
.then((res) => {
|
2024-05-31 15:08:11 +07:00
|
|
|
const data = res.data.data;
|
|
|
|
|
total.value = res.data.total;
|
|
|
|
|
maxPage.value = Math.ceil(total.value / pageSize.value);
|
2024-05-30 14:04:48 +07:00
|
|
|
rows.value = data;
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
messageError($q, err);
|
|
|
|
|
})
|
|
|
|
|
.finally(() => {
|
|
|
|
|
hideLoader();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param type ประเภท
|
|
|
|
|
* @param data ข้อมูลรายการผู้ใช้งาน
|
|
|
|
|
*/
|
|
|
|
|
function onClickAction(type: string, data: Users) {
|
|
|
|
|
if (type === "edit") {
|
|
|
|
|
modalDialogAdd.value = true;
|
|
|
|
|
isStatusEdit.value = true;
|
|
|
|
|
userId.value = data.id;
|
|
|
|
|
} else if (type === "delete") {
|
|
|
|
|
onDeleteUser(data.id);
|
2024-05-31 15:08:11 +07:00
|
|
|
} else if (type === "managementRole") {
|
|
|
|
|
data && router.push(`/users/roles/${data.id}`);
|
2024-05-30 14:04:48 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function openDialog() {
|
|
|
|
|
modalDialogAdd.value = true;
|
|
|
|
|
isStatusEdit.value = false;
|
|
|
|
|
userId.value = "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* function ยืนยันการลบข้อมูลรายการผู้ใช้งาน
|
|
|
|
|
* @param id รายการผู้ใช้งาน
|
|
|
|
|
*/
|
|
|
|
|
function onDeleteUser(id: string) {
|
|
|
|
|
dialogRemove($q, () => {
|
|
|
|
|
showLoader();
|
|
|
|
|
http
|
|
|
|
|
.delete(config.API.managementUser + `/${id}`)
|
|
|
|
|
.then(() => {
|
|
|
|
|
success($q, "ลบข้อมูลสำเร็จ");
|
|
|
|
|
fetchListUsers();
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
messageError($q, err);
|
|
|
|
|
})
|
|
|
|
|
.finally(() => {
|
|
|
|
|
hideLoader();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-31 15:08:11 +07:00
|
|
|
/**
|
|
|
|
|
* function อัปเดท paging
|
|
|
|
|
* @param initialPagination ข้อมูล pagination
|
|
|
|
|
*/
|
|
|
|
|
async function updatePagination(initialPagination: any) {
|
|
|
|
|
currentPage.value = 1;
|
|
|
|
|
pageSize.value = initialPagination.rowsPerPage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
watch(
|
|
|
|
|
() => pageSize.value,
|
|
|
|
|
() => {
|
|
|
|
|
fetchListUsers();
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2024-05-30 14:04:48 +07:00
|
|
|
onMounted(() => {
|
|
|
|
|
fetchListUsers();
|
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<div class="row items-center">
|
|
|
|
|
<div class="toptitle text-dark row items-center q-py-xs">
|
|
|
|
|
จัดการผู้ใช้งาน
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<q-card flast bordered class="q-pa-md">
|
|
|
|
|
<div class="items-center col-12 row q-col-gutter-sm q-mb-sm">
|
|
|
|
|
<q-btn flat round dense color="primary" icon="add" @click="openDialog()">
|
|
|
|
|
<q-tooltip>เพิ่มผู้ใช้งาน </q-tooltip>
|
|
|
|
|
</q-btn>
|
|
|
|
|
<q-space />
|
|
|
|
|
|
|
|
|
|
<q-input
|
|
|
|
|
borderless
|
|
|
|
|
dense
|
|
|
|
|
outlined
|
|
|
|
|
v-model="keyword"
|
|
|
|
|
placeholder="ค้นหา"
|
2024-05-31 15:08:11 +07:00
|
|
|
@keydown.enter.prevent="(currentPage = 1), fetchListUsers()"
|
2024-05-30 14:04:48 +07:00
|
|
|
>
|
|
|
|
|
<template v-slot:append>
|
|
|
|
|
<q-icon name="search" />
|
|
|
|
|
</template>
|
|
|
|
|
</q-input>
|
|
|
|
|
<q-select
|
|
|
|
|
v-model="visibleColumns"
|
|
|
|
|
multiple
|
|
|
|
|
outlined
|
|
|
|
|
dense
|
|
|
|
|
options-dense
|
|
|
|
|
:display-value="$q.lang.table.columns"
|
|
|
|
|
emit-value
|
|
|
|
|
map-options
|
|
|
|
|
:options="columns"
|
|
|
|
|
option-value="name"
|
|
|
|
|
options-cover
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="col-12 q-pt-sm">
|
|
|
|
|
<d-table
|
|
|
|
|
ref="table"
|
|
|
|
|
:columns="columns"
|
|
|
|
|
:rows="rows"
|
|
|
|
|
row-key="id"
|
|
|
|
|
flat
|
|
|
|
|
bordered
|
|
|
|
|
:paging="true"
|
|
|
|
|
dense
|
|
|
|
|
:rows-per-page-options="[10, 25, 50, 100]"
|
|
|
|
|
:visible-columns="visibleColumns"
|
2024-05-31 15:08:11 +07:00
|
|
|
@update:pagination="updatePagination"
|
2024-05-30 14:04:48 +07:00
|
|
|
>
|
|
|
|
|
<template v-slot:header="props">
|
|
|
|
|
<q-tr :props="props">
|
|
|
|
|
<q-th v-for="col in props.cols" :key="col.name" :props="props">
|
|
|
|
|
<span class="text-weight-medium">{{ col.label }}</span>
|
|
|
|
|
</q-th>
|
|
|
|
|
<q-th auto-width></q-th>
|
|
|
|
|
</q-tr>
|
|
|
|
|
</template>
|
|
|
|
|
<template v-slot:body="props">
|
|
|
|
|
<q-tr :props="props" class="cursor-pointer">
|
|
|
|
|
<q-td v-for="col in props.cols" :key="col.name" :props="props">
|
|
|
|
|
<div>
|
|
|
|
|
{{ col.value ? col.value : "-" }}
|
|
|
|
|
</div>
|
|
|
|
|
</q-td>
|
|
|
|
|
<q-td>
|
|
|
|
|
<q-btn
|
|
|
|
|
flat
|
|
|
|
|
dense
|
|
|
|
|
icon="mdi-dots-vertical"
|
|
|
|
|
class="q-pa-none q-ml-xs"
|
|
|
|
|
color="grey-13"
|
|
|
|
|
size="12px"
|
|
|
|
|
>
|
|
|
|
|
<q-menu>
|
|
|
|
|
<q-list dense style="min-width: 200px">
|
|
|
|
|
<q-item
|
|
|
|
|
v-for="(item, index) in itemMenu"
|
|
|
|
|
:key="index"
|
|
|
|
|
clickable
|
|
|
|
|
v-close-popup
|
|
|
|
|
@click.stop="onClickAction(item.type, props.row)"
|
|
|
|
|
>
|
|
|
|
|
<q-item-section>
|
|
|
|
|
<div class="row items-center">
|
|
|
|
|
<q-icon
|
|
|
|
|
:color="item.color"
|
|
|
|
|
size="17px"
|
|
|
|
|
:name="item.icon"
|
|
|
|
|
/>
|
|
|
|
|
<div class="q-pl-md">{{ item.label }}</div>
|
|
|
|
|
</div>
|
|
|
|
|
</q-item-section>
|
|
|
|
|
</q-item>
|
|
|
|
|
</q-list>
|
|
|
|
|
</q-menu>
|
|
|
|
|
</q-btn>
|
|
|
|
|
</q-td>
|
|
|
|
|
</q-tr>
|
|
|
|
|
</template>
|
2024-05-31 15:08:11 +07:00
|
|
|
<template v-slot:pagination="scope">
|
|
|
|
|
ทั้งหมด {{ total }} รายการ
|
|
|
|
|
<q-pagination
|
|
|
|
|
v-model="currentPage"
|
|
|
|
|
active-color="primary"
|
|
|
|
|
color="dark"
|
|
|
|
|
:max="Number(maxPage)"
|
|
|
|
|
size="sm"
|
|
|
|
|
boundary-links
|
|
|
|
|
direction-links
|
|
|
|
|
:max-pages="5"
|
|
|
|
|
@update:model-value="fetchListUsers"
|
|
|
|
|
></q-pagination>
|
|
|
|
|
</template>
|
2024-05-30 14:04:48 +07:00
|
|
|
</d-table>
|
|
|
|
|
</div>
|
|
|
|
|
</q-card>
|
|
|
|
|
|
|
|
|
|
<DialogAddUser
|
|
|
|
|
:fetchlist="fetchListUsers"
|
|
|
|
|
v-model:modal="modalDialogAdd"
|
|
|
|
|
v-model:isStatusEdit="isStatusEdit"
|
|
|
|
|
:userId="userId"
|
|
|
|
|
/>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<style scoped></style>
|