2024-05-31 15:08:11 +07:00
|
|
|
<script setup lang="ts">
|
|
|
|
|
import { ref, onMounted } from "vue";
|
|
|
|
|
import { useQuasar } from "quasar";
|
2024-09-09 14:59:32 +07:00
|
|
|
|
2024-05-31 15:08:11 +07:00
|
|
|
import { useRouter } from "vue-router";
|
|
|
|
|
import http from "@/plugins/http";
|
|
|
|
|
import config from "@/app.config";
|
2024-09-09 14:59:32 +07:00
|
|
|
import { useCounterMixin } from "@/stores/mixin";
|
2024-05-31 15:08:11 +07:00
|
|
|
|
|
|
|
|
/** importType*/
|
|
|
|
|
import type { QTableProps } from "quasar";
|
|
|
|
|
import type { ItemsMenu } from "@/modules/02_users/interface/index/Main";
|
|
|
|
|
import type { Roles } from "@/modules/02_users/interface/response/Main";
|
|
|
|
|
|
|
|
|
|
/** importComponents*/
|
|
|
|
|
import DialogAddRole from "@/modules/02_users/components/Roles/DialogAddRole.vue";
|
|
|
|
|
|
|
|
|
|
/** use*/
|
|
|
|
|
const $q = useQuasar();
|
|
|
|
|
const router = useRouter();
|
2024-12-11 15:12:22 +07:00
|
|
|
const {
|
|
|
|
|
dialogRemove,
|
|
|
|
|
messageError,
|
|
|
|
|
showLoader,
|
|
|
|
|
hideLoader,
|
|
|
|
|
success,
|
|
|
|
|
onSearchDataTable,
|
|
|
|
|
} = useCounterMixin();
|
2024-05-31 15:08:11 +07:00
|
|
|
|
|
|
|
|
/** Table*/
|
2024-09-09 14:59:32 +07:00
|
|
|
const rows = ref<Roles[]>([]); // รายการบทบาท
|
2024-12-11 15:12:22 +07:00
|
|
|
const rowsMain = ref<Roles[]>([]); // รายการบทบาท
|
2024-09-09 14:59:32 +07:00
|
|
|
const keyword = ref<string>(""); // คำค้นหา
|
2024-05-31 15:08:11 +07:00
|
|
|
const columns = ref<QTableProps["columns"]>([
|
|
|
|
|
{
|
|
|
|
|
name: "no",
|
|
|
|
|
align: "left",
|
|
|
|
|
label: "ลำดับ",
|
2025-02-26 15:30:25 +07:00
|
|
|
sortable: false,
|
|
|
|
|
field: "no",
|
2024-05-31 15:08:11 +07:00
|
|
|
headerStyle: "font-size: 14px",
|
|
|
|
|
style: "font-size: 14px",
|
|
|
|
|
},
|
|
|
|
|
{
|
2024-06-11 18:59:22 +07:00
|
|
|
name: "roleName",
|
2024-05-31 15:08:11 +07:00
|
|
|
align: "left",
|
|
|
|
|
label: "ชื่อบทบาท",
|
|
|
|
|
sortable: true,
|
2024-06-11 18:59:22 +07:00
|
|
|
field: "roleName",
|
2024-05-31 15:08:11 +07:00
|
|
|
headerStyle: "font-size: 14px",
|
|
|
|
|
style: "font-size: 14px",
|
|
|
|
|
},
|
|
|
|
|
{
|
2024-06-11 18:59:22 +07:00
|
|
|
name: "roleDescription",
|
2024-05-31 15:08:11 +07:00
|
|
|
align: "left",
|
|
|
|
|
label: "คำอธิบาย",
|
|
|
|
|
sortable: true,
|
2024-06-11 18:59:22 +07:00
|
|
|
field: "roleDescription",
|
2024-05-31 15:08:11 +07:00
|
|
|
headerStyle: "font-size: 14px",
|
|
|
|
|
style: "font-size: 14px",
|
|
|
|
|
},
|
|
|
|
|
]);
|
2024-06-11 18:59:22 +07:00
|
|
|
const visibleColumns = ref<string[]>(["no", "roleName", "roleDescription"]);
|
2024-05-31 15:08:11 +07:00
|
|
|
|
2024-09-09 14:59:32 +07:00
|
|
|
const modalDialogAdd = ref<boolean>(false); // เพิ่มบทบาท
|
2024-05-31 15:08:11 +07:00
|
|
|
|
2024-09-09 14:59:32 +07:00
|
|
|
// รายการตัวเลือก
|
2024-05-31 15:08:11 +07:00
|
|
|
const itemMenu = ref<ItemsMenu[]>([
|
|
|
|
|
{
|
|
|
|
|
label: "แก้ไข",
|
|
|
|
|
icon: "edit",
|
|
|
|
|
color: "edit",
|
|
|
|
|
type: "edit",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: "ลบ",
|
|
|
|
|
icon: "delete",
|
|
|
|
|
color: "red",
|
|
|
|
|
type: "delete",
|
|
|
|
|
},
|
|
|
|
|
]);
|
|
|
|
|
|
2024-09-09 14:59:32 +07:00
|
|
|
/**
|
|
|
|
|
* function fetch รายการบทบาท
|
|
|
|
|
* และบันทึกใน rows
|
|
|
|
|
*/
|
|
|
|
|
async function fetchListRole() {
|
2024-06-11 18:59:22 +07:00
|
|
|
showLoader();
|
2024-09-09 14:59:32 +07:00
|
|
|
await http
|
2024-06-11 18:59:22 +07:00
|
|
|
.get(config.API.managementAuth + `/list`)
|
2024-09-09 14:59:32 +07:00
|
|
|
.then(async (res) => {
|
|
|
|
|
const data = await res.data.result;
|
2024-06-11 18:59:22 +07:00
|
|
|
rows.value = data;
|
2024-12-11 15:12:22 +07:00
|
|
|
rowsMain.value = data;
|
2024-06-11 18:59:22 +07:00
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
messageError($q, err);
|
|
|
|
|
})
|
|
|
|
|
.finally(() => {
|
|
|
|
|
hideLoader();
|
|
|
|
|
});
|
2024-05-31 15:08:11 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-09-09 14:59:32 +07:00
|
|
|
* ฟังก์ชันจัดการการกระทำต่าง ๆ กับข้อมูลบทบาท
|
2024-05-31 15:08:11 +07:00
|
|
|
* @param type ประเภท
|
2024-09-09 14:59:32 +07:00
|
|
|
* @param data ข้อมูลรายการบทบาท
|
2024-05-31 15:08:11 +07:00
|
|
|
*/
|
|
|
|
|
function onClickAction(type: string, data: Roles) {
|
2024-09-09 14:59:32 +07:00
|
|
|
// เช็คการกระทำ
|
2024-05-31 15:08:11 +07:00
|
|
|
if (type === "edit") {
|
2024-09-09 14:59:32 +07:00
|
|
|
// ไปหน้าจัดการสิทธิ์
|
2024-06-11 18:59:22 +07:00
|
|
|
router.push(`/roles/${data.id}`);
|
2024-05-31 15:08:11 +07:00
|
|
|
} else if (type === "delete") {
|
2024-09-09 14:59:32 +07:00
|
|
|
// ลบรายการยบทบาท
|
2024-05-31 15:08:11 +07:00
|
|
|
onDeleteRole(data.id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-11 15:12:22 +07:00
|
|
|
/** เปิด popup เพิ่มบทบาท*/
|
2024-05-31 15:08:11 +07:00
|
|
|
function openDialog() {
|
|
|
|
|
modalDialogAdd.value = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* function ยืนยันการลบข้อมูลบทบาท
|
|
|
|
|
* @param id รายการบทบาท
|
|
|
|
|
*/
|
|
|
|
|
function onDeleteRole(id: string) {
|
2024-09-09 14:59:32 +07:00
|
|
|
dialogRemove($q, async () => {
|
2024-06-11 18:59:22 +07:00
|
|
|
showLoader();
|
2024-09-09 14:59:32 +07:00
|
|
|
await http
|
2024-06-11 18:59:22 +07:00
|
|
|
.delete(config.API.managementAuth + `/${id}`)
|
2024-09-09 14:59:32 +07:00
|
|
|
.then(async () => {
|
|
|
|
|
await fetchListRole();
|
2024-06-11 18:59:22 +07:00
|
|
|
success($q, "ลบข้อมูลสำเร็จ");
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
messageError($q, err);
|
|
|
|
|
})
|
|
|
|
|
.finally(() => {
|
|
|
|
|
hideLoader();
|
|
|
|
|
});
|
2024-05-31 15:08:11 +07:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-11 15:12:22 +07:00
|
|
|
function serchDataTable() {
|
|
|
|
|
rows.value = onSearchDataTable(
|
|
|
|
|
keyword.value,
|
|
|
|
|
rowsMain.value,
|
|
|
|
|
columns.value ? columns.value : []
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-09 14:59:32 +07:00
|
|
|
/**
|
|
|
|
|
* hook ทำงานเมื่อมีการเรียกใช้งาน Components
|
|
|
|
|
* ดึงข้อมูลบทบาท
|
|
|
|
|
*/
|
2024-05-31 15:08:11 +07:00
|
|
|
onMounted(() => {
|
|
|
|
|
fetchListRole();
|
|
|
|
|
});
|
|
|
|
|
</script>
|
2024-05-30 14:04:48 +07:00
|
|
|
|
|
|
|
|
<template>
|
2024-05-31 15:08:11 +07:00
|
|
|
<div class="row items-center">
|
2024-06-11 14:07:20 +07:00
|
|
|
<div class="toptitle text-dark row items-center q-py-xs">
|
|
|
|
|
จัดการบทบาทและสิทธิ์
|
|
|
|
|
</div>
|
2024-05-31 15:08:11 +07:00
|
|
|
</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-12-11 15:12:22 +07:00
|
|
|
@keydown.enter.pervent="serchDataTable"
|
2024-05-31 15:08:11 +07:00
|
|
|
>
|
2024-12-11 15:12:22 +07:00
|
|
|
<template v-slot:append>
|
2024-05-31 15:08:11 +07:00
|
|
|
<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"
|
2024-11-05 16:45:53 +07:00
|
|
|
style="min-width: 140px"
|
2024-05-31 15:08:11 +07:00
|
|
|
/>
|
|
|
|
|
</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"
|
|
|
|
|
>
|
|
|
|
|
<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">
|
2024-06-12 11:28:18 +07:00
|
|
|
<q-tr :props="props">
|
2024-06-11 18:59:22 +07:00
|
|
|
<q-td v-for="col in props.cols" :key="col.name" :props="props">
|
2025-02-26 15:30:25 +07:00
|
|
|
<div v-if="col.name === 'no'">
|
|
|
|
|
{{ props.rowIndex + 1 }}
|
|
|
|
|
</div>
|
|
|
|
|
<div v-else>
|
2024-05-31 15:08:11 +07:00
|
|
|
{{ 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>
|
|
|
|
|
</d-table>
|
|
|
|
|
</div>
|
|
|
|
|
</q-card>
|
|
|
|
|
|
2024-06-11 18:59:22 +07:00
|
|
|
<DialogAddRole v-model:modal="modalDialogAdd" />
|
|
|
|
|
<!-- :fetchlist="fetchListRole" v-model:isStatusEdit="isStatusEdit"
|
|
|
|
|
:roleId="roleId" -->
|
2024-05-30 14:04:48 +07:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<style scoped></style>
|