Refactoring code module 02_users

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2024-09-09 14:59:32 +07:00
parent 7540311518
commit c11ff006eb
12 changed files with 301 additions and 1363 deletions

View file

@ -1,8 +1,10 @@
<script setup lang="ts">
import { ref, watch } from "vue";
import { useQuasar } from "quasar";
import http from "@/plugins/http";
import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
/** importComponents*/
import DialogHeader from "@/components/DialogHeader.vue";
@ -12,9 +14,6 @@ import type { QTableProps } from "quasar";
import type { FilterReqMaster } from "@/modules/02_users/interface/request/Main";
import type { Roles } from "@/modules/02_users/interface/response/Main";
/** importStore*/
import { useCounterMixin } from "@/stores/mixin";
/** use*/
const $q = useQuasar();
const {

View file

@ -1,19 +1,17 @@
<script setup lang="ts">
import { ref, reactive, watch } from "vue";
import { reactive } from "vue";
import { useQuasar } from "quasar";
import { useRouter } from "vue-router";
import { useRouter } from "vue-router";
import http from "@/plugins/http";
import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
import type { FormRole } from "@/modules/02_users/interface/request/Main";
/** importComponents*/
import DialogHeader from "@/components/DialogHeader.vue";
/** importStore*/
import { useCounterMixin } from "@/stores/mixin";
/** use*/
const $q = useQuasar();
const router = useRouter();
@ -22,21 +20,24 @@ const { showLoader, hideLoader, dialogConfirm, messageError, success } =
/** props*/
const modal = defineModel<boolean>("modal", { required: true });
//
const formData = reactive<FormRole>({
roleName: "",
roleDescription: "",
roleName: "", //
roleDescription: "", //
});
/** function บันทึกข้อมูลผู้ใช้งาน*/
/**
* function นทกขอมลผใชงาน
*/
function onSubmit() {
dialogConfirm($q, () => {
dialogConfirm($q, async () => {
showLoader();
http
await http
.post(config.API.managementAuth, formData)
.then((res) => {
closeDialog();
router.push(`/roles/${res.data.result}`);
success($q, "บันทึกข้อมูลสำเร็จ");
closeDialog();
})
.catch((e) => {
messageError($q, e);
@ -47,7 +48,9 @@ function onSubmit() {
});
}
/** function ปิด Dialog */
/**
* function Dialog
*/
function closeDialog() {
modal.value = false;
formData.roleName = "";

View file

@ -1,8 +1,10 @@
<script setup lang="ts">
import { ref, reactive, watch } from "vue";
import { useQuasar } from "quasar";
import http from "@/plugins/http";
import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
import type { QTableProps } from "quasar";
import type {
@ -18,9 +20,6 @@ import type { Profile } from "@/modules/02_users/interface/response/Main";
/** importComponents*/
import DialogHeader from "@/components/DialogHeader.vue";
/** importStore*/
import { useCounterMixin } from "@/stores/mixin";
/** use*/
const $q = useQuasar();
const { showLoader, hideLoader, dialogConfirm, messageError, success } =
@ -37,8 +36,7 @@ const props = defineProps({
},
});
/** Table*/
const rows = ref<Profile[]>([]);
// Table
const columns = ref<QTableProps["columns"]>([
{
name: "citizenId",
@ -101,34 +99,40 @@ const columns = ref<QTableProps["columns"]>([
style: "font-size: 14px",
},
]);
const selected = ref<Profile[]>([]);
const searchType = ref<string>("citizenId");
const keyword = ref<string>("");
const rows = ref<Profile[]>([]); //
const selected = ref<Profile[]>([]); //
const searchType = ref<string>("citizenId"); //
const keyword = ref<string>(""); //
//
const searchTypeOption = ref<DataOption[]>([
{ id: "citizenId", name: "เลขประจำตัวประชาชน" },
{ id: "firstname", name: "ชื่อ" },
{ id: "lastname", name: "นามสกุล" },
]);
const query = reactive({
page: 1,
pageSize: 10,
page: 1, //
pageSize: 10, //
});
const total = ref<number>(0);
const maxPage = ref<number>(1);
const total = ref<number>(0); //
const maxPage = ref<number>(1); //
const isPwd = ref<boolean>(true);
const roles = ref<Roles[]>([]);
const isPwd = ref<boolean>(true); //
const roles = ref<Roles[]>([]); //
//
const formData = reactive<FormUser>({
profileId: "",
username: "",
password: "",
firstName: "",
lastName: "",
email: "",
roles: [],
profileId: "", // id
username: "", //
password: "", //
firstName: "", //
lastName: "", //
email: "", //
roles: [], //
});
const roleOptions = ref([]);
const roleOptions = ref([]); // ;
/**
* งกนดงขอมลรายช
*/
function fetchListUser() {
showLoader();
const body = {
@ -141,8 +145,8 @@ function fetchListUser() {
`?page=${query.page}&pageSize=${query.pageSize}`,
body
)
.then((res) => {
const data = res.data.result;
.then(async (res) => {
const data = await res.data.result;
maxPage.value = Math.ceil(data.total / query.pageSize);
total.value = data.total;
rows.value = data.data;
@ -156,8 +160,10 @@ function fetchListUser() {
}
/**
* function fetch อมใชงาน
* งกนดงขอมลผใชงานตาม ID ใชงาน
* @param id ใชงาน
*
* และกำหนดฟอรมเพมผใชงานจาก respone
*/
function fetchUserDetail(id: string) {
showLoader();
@ -179,7 +185,11 @@ function fetchUserDetail(id: string) {
});
}
/** function fetc รายการ role*/
/**
* งขอมลรายการบทบาท
*
* นทกใน roleOptions
*/
function fetchlistRole() {
http
.get(config.API.managementRole)
@ -197,7 +207,9 @@ function fetchlistRole() {
});
}
/** function บันทึกข้อมูลผู้ใช้งาน*/
/**
* งกนยนยนการบนทกขอมลผใชงาน
*/
function onSubmit() {
formData.roles = !isStatusEdit.value
? roles.value.map((e: { id: string }) => e.id)
@ -225,7 +237,9 @@ function onSubmit() {
});
}
/** function ปิด Dialog */
/**
* งก Dialog และกำหนด วแปรไปเปนค defult
*/
function closeDialog() {
modal.value = false;
formData.profileId = "";
@ -251,6 +265,11 @@ async function updatePagination(initialPagination: Pagination) {
query.pageSize = initialPagination.rowsPerPage;
}
/**
* การเปลยนแปลงของจำนวนขอมลตอหน
*
* งขอมลรายชอตามจำนวนขอมลตอหน
*/
watch(
() => query.pageSize,
() => {
@ -258,6 +277,11 @@ watch(
}
);
/**
* การเปลยนแปลงของ modal
*
* isStatusEdit เป true งขอมลของผใชงาน
*/
watch(
() => modal.value,
() => {
@ -269,6 +293,11 @@ watch(
}
);
/**
* การเปลยนแปลงของการเลอกรายช
*
* กำหนด ฟอรมเพมขอผใชงานตามราชชอทเลอก
*/
watch(
() => selected.value,
() => {
@ -279,7 +308,6 @@ watch(
formData.lastName = data.lastName;
formData.email = data.email;
formData.username = data.citizenId;
// formData.password = "54321";
}
}
);

View file

@ -1,8 +1,10 @@
<script setup lang="ts">
import { ref, reactive, watch } from "vue";
import { ref, watch } from "vue";
import { useQuasar } from "quasar";
import http from "@/plugins/http";
import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
import type { QTableProps } from "quasar";
import type { Roles } from "@/modules/02_users/interface/request/Main";
@ -10,9 +12,6 @@ import type { Roles } from "@/modules/02_users/interface/request/Main";
/** importComponents*/
import DialogHeader from "@/components/DialogHeader.vue";
/** importStore*/
import { useCounterMixin } from "@/stores/mixin";
/** use*/
const $q = useQuasar();
const {
@ -27,8 +26,7 @@ const {
/** props*/
const modal = defineModel<boolean>("modal", { required: true });
const userId = defineModel<string>("userId", { required: true });
const roles = defineModel<any[]>("roles", {});
const roles = defineModel<any[]>("roles");
const props = defineProps({
fetchlist: {
type: Function,
@ -36,7 +34,8 @@ const props = defineProps({
},
});
const rows = ref<Roles[]>([]);
// Table
const rows = ref<Roles[]>([]); //
const columns = ref<QTableProps["columns"]>([
{
name: "name",
@ -59,9 +58,11 @@ const columns = ref<QTableProps["columns"]>([
]);
const visibleColumns = ref<string[]>(["name", "description"]);
const selected = ref<Roles[]>([]);
const selected = ref<Roles[]>([]); //
/** function fetc รายการ role*/
/**
* งกนดงขอมลรายการสทธงหมด
*/
function fetchlistRole() {
showLoader();
http
@ -85,19 +86,27 @@ function fetchlistRole() {
});
}
/**
* งกนยนยนการบนทกการเพมสทธ
*
* เมอเสรจจะโหลดขอมลรายการสทธใหม
*/
function onSubmit() {
//
if (selected.value.length === 0) {
//
dialogMessageNotify($q, "กรุณาเลือก role อย่างน้อง 1 role");
} else {
dialogConfirm($q, () => {
//
dialogConfirm($q, async () => {
showLoader();
const body = { role: selected.value.map((e: { id: string }) => e.id) };
http
.post(config.API.management + `/${userId.value}/role`, body)
.then(() => {
props.fetchlist?.();
closeDialog();
.then(async () => {
await props.fetchlist?.();
success($q, "บันทึกข้อมูลสำเร็จ");
closeDialog();
})
.catch((err) => {
messageError($q, err);
@ -109,12 +118,17 @@ function onSubmit() {
}
}
/** function ปิด Dialog */
/**
* งก Dialog และกำหนดใหรายการสทธเลอกเปนคาวาง
*/
function closeDialog() {
modal.value = false;
selected.value = [];
}
/**
* modal เม modal เป true ทำการโหลขอมลรายการสทธงหมด
*/
watch(
() => modal.value,
() => {

View file

@ -1,20 +1,20 @@
/** user*/
const ListsPageUser = () => import("@/modules/02_users/views/listsUser.vue");
const ListsPageUser = () => import("@/modules/02_users/views/01_user.vue");
const PageManagementRole = () =>
import("@/modules/02_users/views/managementRoleUser.vue");
import("@/modules/02_users/views/page01_ManagementRoleUser.vue");
/** role*/
const ListsPageRole = () => import("@/modules/02_users/views/listsRole.vue");
const ListsPageRole = () => import("@/modules/02_users/views/02_rolesAndPermissions.vue");
const ListsPage2Role = () =>
import("@/modules/02_users/views/permissionDetail.vue");
import("@/modules/02_users/views/page02_rolesAndPermissionsDetail.vue");
/** PermissionPage*/
const PermissionPage = () =>
import("@/modules/02_users/views/permissionsView.vue");
import("@/modules/02_users/views/03_permissionsView.vue");
/** roleOrganization */
const roleOrgview = () =>
import("@/modules/02_users/views/roleOrganization.vue");
import("@/modules/02_users/views/04_roleOrganization.vue");
export default [
{

View file

@ -1,9 +1,11 @@
<script setup lang="ts">
import { ref, onMounted, watch } from "vue";
import { useQuasar } from "quasar";
import { useRouter } from "vue-router";
import http from "@/plugins/http";
import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
/** importType*/
import type { QTableProps } from "quasar";
@ -14,11 +16,7 @@ import type {
import type { Users, Roles } from "@/modules/02_users/interface/response/Main";
/** importComponents*/
import DialogAddUser from "@/modules/02_users/components/Users/DialogAddUser.vue";
// import DialogManagementRole from "@/modules/02_users/components/Users/DialogManagementRole.vue";
/** importStore*/
import { useCounterMixin } from "@/stores/mixin";
import DialogAddUser from "@/modules/02_users/components/Users/DialogFormUser.vue";
/** use*/
const $q = useQuasar();
@ -33,11 +31,12 @@ const {
} = useCounterMixin();
/** Table*/
const rows = ref<Users[]>([]);
const total = ref<number>(0);
const currentPage = ref<number>(1);
const maxPage = ref<number>(0);
const pageSize = ref<number>(10);
const keyword = ref<string>(""); //
const rows = ref<Users[]>([]); //
const currentPage = ref<number>(1); //
const total = ref<number>(0); //
const maxPage = ref<number>(0); //
const pageSize = ref<number>(10); //
const columns = ref<QTableProps["columns"]>([
{
name: "no",
@ -116,21 +115,14 @@ const visibleColumns = ref<string[]>([
"role",
"enabled",
]);
const keyword = ref<string>("");
/** addUser*/
const modalDialogAdd = ref<boolean>(false);
const isStatusEdit = ref<boolean>(false);
const userId = ref<string>("");
/** เพิ่มข้อมูลผู้ใช้งาน*/
const modalDialogAdd = ref<boolean>(false); // popup
const isStatusEdit = ref<boolean>(false); //
const userId = ref<string>(""); // id
/** List Mune*/
//
const itemMenu = ref<ItemsMenu[]>([
// {
// label: "",
// icon: "edit",
// color: "edit",
// type: "edit",
// },
{
label: "ระงับการใช้งาน",
icon: "mdi-lock-outline",
@ -157,18 +149,20 @@ const itemMenu = ref<ItemsMenu[]>([
},
]);
/** function fetch รายชื่อผู้ใช้งาน*/
function fetchListUsers() {
/**
* งกนดงขอมลรายชอผใชงาน
*/
async function fetchListUsers() {
let max = pageSize.value;
let first = (currentPage.value - 1) * pageSize.value;
showLoader();
http
await http
.get(
config.API.managementUser +
`?max=${max}&first=${first}&search=${keyword.value}`
)
.then((res) => {
const data = res.data.data;
.then(async (res) => {
const data = await res.data.data;
total.value = res.data.total;
maxPage.value = Math.ceil(total.value / pageSize.value);
@ -194,25 +188,35 @@ function fetchListUsers() {
}
/**
*
* @param type ประเภท
* งกนจดการการกระทำตาง บขอมลผใชงาน
* @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);
} else if (type === "managementRole") {
//
data && router.push(`/users/roles/${data.id}`);
} else if (type === "open" || type === "close") {
// /
const status = type === "open" ? true : false;
onLockUser(data.id, status);
}
}
/**
* งกนเป popup สำหรบเพมขอมลผใชงาน
*
* กำหนดสถานะการแกไขเป false และ id ใชงานทองการแกไขเปนคาวาง
*/
function openDialog() {
modalDialogAdd.value = true;
isStatusEdit.value = false;
@ -222,15 +226,17 @@ function openDialog() {
/**
* function นยนการลบขอมลรายการผใชงาน
* @param id รายการผใชงาน
*
* ลบขอมลรายชอเสรจแลวทำการดงขอมลรายชอผใชงานใหม
*/
function onDeleteUser(id: string) {
dialogRemove($q, () => {
showLoader();
http
.delete(config.API.managementUser + `/${id}`)
.then(() => {
.then(async () => {
await fetchListUsers();
success($q, "ลบข้อมูลสำเร็จ");
fetchListUsers();
})
.catch((err) => {
messageError($q, err);
@ -242,9 +248,11 @@ function onDeleteUser(id: string) {
}
/**
* function ระงบการใชงาน
* งกนระงบการใชงานผใชงาน
* @param id ใชงาน
* @param type เปดใชงาน,ระงบการใชงาน
*
* เสรจแลวทำการดงขอมลรายชอผใชงานใหม
*/
function onLockUser(id: string, type: boolean) {
dialogConfirm(
@ -255,7 +263,7 @@ function onLockUser(id: string, type: boolean) {
.put(config.API.managementUser + `/${id}/enableStatus/${type}`)
.then(async () => {
await fetchListUsers();
await success($q, type ? "เปิดใช้งานสำเร็จ" : "ระงับการใช้งานสำเร็จ");
success($q, type ? "เปิดใช้งานสำเร็จ" : "ระงับการใช้งานสำเร็จ");
})
.catch((err) => {
messageError($q, err);
@ -272,12 +280,19 @@ function onLockUser(id: string, type: boolean) {
/**
* function ปเดท paging
* @param initialPagination อม pagination
*
* กำหนดหนาไปยงหนาแรก
*/
function updatePagination(initialPagination: Pagination) {
currentPage.value = 1;
pageSize.value = initialPagination.rowsPerPage;
}
/**
* การเปลยนแปลงของจำนวนขอมลตอหน
*
* งขอมลรายชอผใชงานตามจำนวนขอมลตอหน
*/
watch(
() => pageSize.value,
() => {
@ -285,8 +300,13 @@ watch(
}
);
onMounted(() => {
fetchListUsers();
/**
* hook ทำงานเมอมการเรยกใชงาน Components
*
* งขอมลรายชอผใชงาน
*/
onMounted(async () => {
await fetchListUsers();
});
</script>

View file

@ -1,9 +1,11 @@
<script setup lang="ts">
import { ref, onMounted } from "vue";
import { useQuasar } from "quasar";
import { useRouter } from "vue-router";
import http from "@/plugins/http";
import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
/** importType*/
import type { QTableProps } from "quasar";
@ -13,9 +15,6 @@ import type { Roles } from "@/modules/02_users/interface/response/Main";
/** importComponents*/
import DialogAddRole from "@/modules/02_users/components/Roles/DialogAddRole.vue";
/** importStore*/
import { useCounterMixin } from "@/stores/mixin";
/** use*/
const $q = useQuasar();
const router = useRouter();
@ -23,7 +22,8 @@ const { dialogRemove, messageError, showLoader, hideLoader, success } =
useCounterMixin();
/** Table*/
const rows = ref<Roles[]>([]);
const rows = ref<Roles[]>([]); //
const keyword = ref<string>(""); //
const columns = ref<QTableProps["columns"]>([
{
name: "no",
@ -54,11 +54,10 @@ const columns = ref<QTableProps["columns"]>([
},
]);
const visibleColumns = ref<string[]>(["no", "roleName", "roleDescription"]);
const keyword = ref<string>("");
const modalDialogAdd = ref<boolean>(false);
const modalDialogAdd = ref<boolean>(false); //
/** List Mune*/
//
const itemMenu = ref<ItemsMenu[]>([
{
label: "แก้ไข",
@ -74,13 +73,17 @@ const itemMenu = ref<ItemsMenu[]>([
},
]);
/** function fetch รายการบทบาท*/
function fetchListRole() {
/**
* function fetch รายการบทบาท
*
* และบนทกใน rows
*/
async function fetchListRole() {
showLoader();
http
await http
.get(config.API.managementAuth + `/list`)
.then((res) => {
const data = res.data.result;
.then(async (res) => {
const data = await res.data.result;
rows.value = data;
})
.catch((err) => {
@ -92,18 +95,24 @@ function fetchListRole() {
}
/**
*
* งกนจดการการกระทำตาง บขอมลบทบาท
* @param type ประเภท
* @param data อมลรายการใชงาน
* @param data อมลรายการบทบาท
*/
function onClickAction(type: string, data: Roles) {
//
if (type === "edit") {
//
router.push(`/roles/${data.id}`);
} else if (type === "delete") {
//
onDeleteRole(data.id);
}
}
/**
* เป popup เพมบทบาท
*/
function openDialog() {
modalDialogAdd.value = true;
}
@ -113,13 +122,13 @@ function openDialog() {
* @param id รายการบทบาท
*/
function onDeleteRole(id: string) {
dialogRemove($q, () => {
dialogRemove($q, async () => {
showLoader();
http
await http
.delete(config.API.managementAuth + `/${id}`)
.then(() => {
.then(async () => {
await fetchListRole();
success($q, "ลบข้อมูลสำเร็จ");
fetchListRole();
})
.catch((err) => {
messageError($q, err);
@ -130,6 +139,11 @@ function onDeleteRole(id: string) {
});
}
/**
* hook ทำงานเมอมการเรยกใชงาน Components
*
* งขอมลบทบาท
*/
onMounted(() => {
fetchListRole();
});

View file

@ -1,11 +1,11 @@
<script setup lang="ts">
import { ref, reactive, onMounted, watch } from "vue";
import { useQuasar } from "quasar";
import http from "@/plugins/http";
import config from "@/app.config";
/** importComponents*/
import DialogAdd from "@/modules/02_users/components/Permissions/DialogAdd.vue";
import { usePermissionsStore } from "@/modules/02_users/stores/permissions";
import { useCounterMixin } from "@/stores/mixin";
/** importType*/
import type { QTableProps } from "quasar";
@ -17,21 +17,23 @@ import type {
Position,
} from "@/modules/02_users/interface/response/Main";
/** importStore*/
import { usePermissionsStore } from "@/modules/02_users/stores/permissions";
import { useCounterMixin } from "@/stores/mixin";
/** importComponents*/
import DialogAdd from "@/modules/02_users/components/Permissions/DialogAdd.vue";
/**
* use
*/
const $q = useQuasar();
const store = usePermissionsStore();
const { showLoader, hideLoader, messageError, success, dialogRemove } =
useCounterMixin();
/** Tree*/
const filter = ref<string>("");
const nodes = ref<Array<NodeTree[]>>([]);
const filter = ref<string>(""); //
const nodes = ref<Array<NodeTree[]>>([]); //
const lazy = ref(nodes);
const expanded = ref<string[]>([]);
const nodeId = ref<string>("");
const expanded = ref<string[]>([]); //
const nodeId = ref<string>(""); // id
/** Table*/
const columns = ref<QTableProps["columns"]>([
@ -187,6 +189,7 @@ const columnsExpand = ref<QTableProps["columns"]>([
style: "font-size: 14px",
},
]);
//
const reqMaster = reactive<FilterReqMaster>({
id: "",
type: 0,
@ -198,21 +201,23 @@ const reqMaster = reactive<FilterReqMaster>({
});
const maxPage = ref<number>(0);
const totalRow = ref<number>(0);
const posMaster = ref<PosMaster[]>([]);
const dataPosMaster = ref<PosMaster>();
const posMaster = ref<PosMaster[]>([]); //
const dataPosMaster = ref<PosMaster>(); //
const pagination = ref<Pagination>({
page: reqMaster.page,
rowsPerPage: reqMaster.pageSize,
});
/** Dialog*/
const modalDialogAdd = ref<boolean>(false);
const modalDialogAdd = ref<boolean>(false); // popup
/** function เรียกข้อมูลโครงสร้าง แบบปัจุบันและ แบบร่าง*/
function fetchOrganizationActive() {
http
/**
* function เรยกขอมลโครงสราง แบบปนและ แบบราง
*/
async function fetchOrganizationActive() {
showLoader();
await http
.get(config.API.activeOrganization)
.then((res) => {
.then(async (res) => {
const data = res.data.result;
if (data) {
store.activeId = data.activeId;
@ -222,11 +227,14 @@ function fetchOrganizationActive() {
store.typeOrganizational === "current"
? store.activeId
: store.draftId;
fetchDataTree(id);
await fetchDataTree(id);
}
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
@ -234,12 +242,12 @@ function fetchOrganizationActive() {
* function fetch อมลของ Tree
* @param id id โครงสราง
*/
function fetchDataTree(id: string) {
async function fetchDataTree(id: string) {
showLoader();
http
await http
.get(config.API.orgByid(id.toString()))
.then((res) => {
const data = res.data.result;
.then(async (res) => {
const data = await res.data.result;
nodes.value = data;
})
.catch((err) => {
@ -255,12 +263,12 @@ function fetchDataTree(id: string) {
* @param id idTree
* @param level levelTree
*/
function fetchDataTable(id: string, revisionId: string, level: number) {
async function fetchDataTable(id: string, revisionId: string, level: number) {
showLoader();
reqMaster.id = id;
reqMaster.revisionId = revisionId;
reqMaster.type = level;
http
await http
.post(config.API.orgPosMasterList, reqMaster)
.then(async (res) => {
posMaster.value = [];
@ -268,7 +276,7 @@ function fetchDataTable(id: string, revisionId: string, level: number) {
maxPage.value = Math.ceil(res.data.result.total / reqMaster.pageSize);
totalRow.value = res.data.result.total;
res.data.result.data.forEach((e: PosMaster) => {
await res.data.result.data.forEach((e: PosMaster) => {
const p = e.positions;
if (p.length !== 0) {
const a = p.find((el: Position) => el.positionIsSelected === true);
@ -311,6 +319,10 @@ function onClickAddRole(data: PosMaster) {
dataPosMaster.value = data;
}
/**
* นยนการลบสทธ
* @param id ตำแหน
*/
function onDeleteRole(id: string) {
dialogRemove(
$q,
@ -327,7 +339,7 @@ function onDeleteRole(id: string) {
reqMaster.revisionId,
reqMaster.type
);
await success($q, "ลบข้อมูลสำเร็จ");
success($q, "ลบข้อมูลสำเร็จ");
})
.catch((err) => {
messageError($q, err);

View file

@ -1,9 +1,11 @@
<script setup lang="ts">
import { ref, onMounted } from "vue";
import { useRouter, useRoute } from "vue-router";
import { useQuasar } from "quasar";
import { useRouter, useRoute } from "vue-router";
import http from "@/plugins/http";
import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
/** importType*/
import type { QTableProps } from "quasar";
@ -12,9 +14,6 @@ import type { Roles } from "@/modules/02_users/interface/response/Main";
/** importComponents*/
import DialogAddRoleUser from "@/modules/02_users/components/Users/DialogRoleUser.vue";
/** importStore*/
import { useCounterMixin } from "@/stores/mixin";
/** use*/
const $q = useQuasar();
const router = useRouter();
@ -22,9 +21,10 @@ const route = useRoute();
const { dialogRemove, messageError, showLoader, hideLoader, success } =
useCounterMixin();
const userId = ref<string>(route.params.id.toString());
const userId = ref<string>(route.params.id.toString()); // id
const rows = ref<Roles[]>([]);
// Table
const rows = ref<Roles[]>([]); //
const columns = ref<QTableProps["columns"]>([
{
name: "no",
@ -56,14 +56,17 @@ const columns = ref<QTableProps["columns"]>([
]);
const visibleColumns = ref<string[]>(["no", "name", "description"]);
const modalDialogAdd = ref<boolean>(false);
const modalDialogAdd = ref<boolean>(false); //
function fetchListRoleUser() {
/**
* งกนดงขอมลรายการสทธตามผใชงาน
*/
async function fetchListRoleUser() {
showLoader();
http
.get(config.API.managementUser + `/role/${userId.value}`)
.then((res) => {
rows.value = res.data.filter(
.then(async (res) => {
rows.value = await res.data.filter(
(e: Roles) =>
e.name === "STAFF" ||
e.name === "SUPER_ADMIN" ||
@ -79,13 +82,19 @@ function fetchListRoleUser() {
});
}
/**
* งกนลบขอมลสทธออกจากผใชงาน
* @param id ทธ
*
* ลบขอมลเสรจโหลดขอมลรายการสทธใหม
*/
function onDelete(id: string) {
dialogRemove($q, () => {
showLoader();
http
.delete(config.API.management + `/${userId.value}/role/${id}`)
.then(() => {
fetchListRoleUser();
.then(async () => {
await fetchListRoleUser();
success($q, "ลบข้อมูลสำเร็จ");
})
.catch((err) => {
@ -97,10 +106,18 @@ function onDelete(id: string) {
});
}
/**
* งกเพมสทธ
*/
function openDialog() {
modalDialogAdd.value = true;
}
/**
* hook ทำงานเมอมการเรยกใช components
*
* โหลดขอมลรายการสทธ
*/
onMounted(() => {
fetchListRoleUser();
});

View file

@ -1,9 +1,11 @@
<script setup lang="ts">
import { onMounted, reactive, ref } from "vue";
import { useRouter, useRoute } from "vue-router";
import { useQuasar } from "quasar";
import { useRouter, useRoute } from "vue-router";
import http from "@/plugins/http";
import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
import type {
DataOption,
@ -13,14 +15,15 @@ import type {
import type { SysList } from "@/modules/02_users/interface/response/Main";
import type { FormRole } from "@/modules/02_users/interface/request/Main";
/** importStore*/
import { useCounterMixin } from "@/stores/mixin";
/** use*/
const router = useRouter();
const route = useRoute();
const $q = useQuasar();
const { dialogConfirm, messageError, showLoader, hideLoader, success } =
useCounterMixin();
const roleId = ref<string>(route.params.id.toString()); // id
//
const attrPrivilegeOp = ref<DataOption[]>([
{
id: "ROOT",
@ -39,25 +42,26 @@ const attrPrivilegeOp = ref<DataOption[]>([
name: "มีสิทธิ์เข้าถึงข้อมูลเฉพาะเจาะจง",
},
]);
const router = useRouter();
const route = useRoute();
const roleId = ref<string>(route.params.id.toString());
//
const formData = reactive<FormRole>({
roleName: "",
roleDescription: "",
roleName: "", //
roleDescription: "", //
});
const sysListMain = ref<SysList[]>([]);
const systemLists = ref<SystemList[]>([]);
function fetchSys() {
/**
* งขอมลรายการระบบทหมด
*/
async function fetchSys() {
showLoader();
http
await http
.get(config.API.managementSysList)
.then((res) => {
sysListMain.value = res.data.result;
fetchDataRole();
.then(async (res) => {
sysListMain.value = await res.data.result;
await fetchDataRole();
})
.catch((err) => {
messageError($q, err);
@ -67,12 +71,17 @@ function fetchSys() {
});
}
function fetchDataRole() {
/**
* งขอมลบทบาทและสทธ
*
* นทกขอมลสทธเขากบรายการระบบ
*/
async function fetchDataRole() {
showLoader();
http
await http
.get(config.API.managementAuth + `/${roleId.value}`)
.then((res) => {
const data = res.data.result;
.then(async (res) => {
const data = await res.data.result;
const sysList = data.roleAttributes;
formData.roleName = data.roleName;
formData.roleDescription = data.roleDescription;
@ -144,6 +153,9 @@ function fetchDataRole() {
});
}
/**
* นยนการบนทกการบทบาทและสทธ
*/
function onSubmit() {
dialogConfirm($q, () => {
showLoader();
@ -189,9 +201,9 @@ function onSubmit() {
};
http
.patch(config.API.managementAuth + `/${roleId.value}`, body)
.then(() => {
.then(async () => {
await fetchDataRole();
success($q, "บันทึกข้อมูลสำเร็จ");
fetchDataRole();
})
.catch((err) => {
messageError($q, err);
@ -202,6 +214,11 @@ function onSubmit() {
});
}
/**
* hook ทำงานเมอมการเรยกใช components
*
* โหลดขอมลรายการระบบทงหมด
*/
onMounted(() => {
fetchSys();
});

File diff suppressed because it is too large Load diff