diff --git a/src/api/02_organizational/api.organization.ts b/src/api/02_organizational/api.organization.ts index b07565b76..e90248dfa 100644 --- a/src/api/02_organizational/api.organization.ts +++ b/src/api/02_organizational/api.organization.ts @@ -112,4 +112,10 @@ export default { * รายการคำร้องขอแก้ไขทะเบียนประวัติ */ requestEdit: `${orgProfile}/edit/`, + + /** + * รายการเมนู + */ + orgPermissions: `${organization}/permission/menu`, + }; diff --git a/src/interface/response/main.ts b/src/interface/response/main.ts new file mode 100644 index 000000000..f866af099 --- /dev/null +++ b/src/interface/response/main.ts @@ -0,0 +1,21 @@ +interface ListMenu { + id: string; + icon: string; + order: number; + parentId?: string | null; + path: string; + sysDescription: string; + sysName: string; + children?: ListMenu[]; +} + +interface ChildConfig { + sysName?: string; + path: string; +} + +interface ChildLevelTree { + [key: string]: ChildConfig[]; +} + +export type { ListMenu, ChildLevelTree, ChildConfig }; diff --git a/src/stores/menuList.ts b/src/stores/menuList.ts new file mode 100644 index 000000000..b532a9d7b --- /dev/null +++ b/src/stores/menuList.ts @@ -0,0 +1,115 @@ +import { defineStore } from "pinia"; +import { ref } from "vue"; + +import type { + ListMenu, + ChildLevelTree, + ChildConfig, +} from "@/interface/response/main"; + +export const useMenuDataStore = defineStore("menuUse", () => { + const menuList = ref([ + { + id: "dashboard", + order: 0, + icon: "mdi-home-variant-outline", + sysName: "หน้าแรก", + sysDescription: "หน้าแรก", + path: "dashboard", + parentId: null, + children: [], + }, + ]); + + const childLevelTree = ref({ + SYS_EVA_INDICATOR: [ + { + sysName: "ตามแผน", + path: "KPIIndicatorByPlan", + }, + { + sysName: "ตามตำแหน่ง", + path: "KPIIndicatorByRole", + }, + { + sysName: "งานที่ได้รับมอบหมาย", + path: "KPIAssignment", + }, + ], + SYS_EXAM_CONTEST: [ + { + sysName: "จัดการรอบสอบแข่งขัน", + path: "competePeriod", + }, + { + sysName: "สถิติสมัครสอบแข่งขัน", + path: "competePeriodStat", + }, + ], + SYS_EXAM_SELECT: [ + { + sysName: "จัดการรอบคัดเลือก", + path: "qualifyPeriod", + }, + { + sysName: "จัดการรอบคัดเลือกคนพิการ", + path: "disablePeriod", + }, + { + sysName: "จัดการรายชื่อคัดเลือก", + path: "manage", + }, + { + sysName: "สถิติสมัครคัดเลือก", + path: "qualifyPeriodStat", + }, + { + sysName: "สถิติสมัครคัดเลือกคนพิการ", + path: "qualifyPeriodStatDisable", + }, + ], + SYS_DISCIPLINE_INFO: [ + { + sysName: "กรรมการ", + path: "disciplineDirector", + }, + { + sysName: "ช่องทางการร้องเรียน", + path: "disciplineChannel", + }, + ], + SYS_EVA_INFO: [ + { + sysName: "กรรมการ", + path: "evaluateDirector", + }, + { + sysName: "การประชุม", + path: "evaluateMeeting", + }, + ], + }); + + function fetchListMenu(data: ListMenu[]) { + data.forEach((item) => { + if (item.children && item.children.length !== 0) { + item.children.forEach((q: ListMenu) => { + const config: any = childLevelTree.value[q.id]; + if (config) { + if (!q.children) { + q.children = []; + } + // เพิ้ม ข้อมูลเลเวล 3 + q.children.push(...config); + } + }); + } + }); + menuList.value.push(...data); + } + + return { + fetchListMenu, + menuList, + }; +}); diff --git a/src/views/MainLayout.vue b/src/views/MainLayout.vue index 169a4c631..7480bb0bc 100644 --- a/src/views/MainLayout.vue +++ b/src/views/MainLayout.vue @@ -6,6 +6,7 @@ import { useDataStore } from "@/stores/data"; import { storeToRefs } from "pinia"; import { scroll, useQuasar } from "quasar"; import { useCounterMixin } from "@/stores/mixin"; +import { useMenuDataStore } from "@/stores/menuList"; import http from "@/plugins/http"; import config from "@/app.config"; @@ -28,6 +29,7 @@ const route = useRoute(); const router = useRouter(); const link = ref(""); const mixin = useCounterMixin(); //เรียกฟังก์ชันกลาง +const storeMenu = useMenuDataStore(); const { showLoader, hideLoader, @@ -230,10 +232,13 @@ const activeBtn = () => { * ยังจับ boolean ผิด จึงต้อง set */ onMounted(async () => { + await fetchSys(); + if (keycloak.tokenParsed) { await fetchroleUser(keycloak.tokenParsed.role); } await fetchmsgNoread(); + // await getDataNotification(1, "NOMAL"); myEventHandler(null, false); window.addEventListener("resize", (e: any) => { @@ -499,6 +504,20 @@ const handleButtonClick = () => { console.log("No manual available for this page:", currentPath); } }; + +/** + * function fetch รายการเมนูทั้งหมด + */ +function fetchSys() { + http + .get(config.API.orgPermissions) + .then((res) => { + storeMenu.fetchListMenu(res.data.result); + }) + .catch((err) => { + messageError($q, err); + }); +} @@ -762,28 +781,15 @@ const handleButtonClick = () => { -
-
+
+
@@ -798,7 +804,7 @@ const handleButtonClick = () => { self="center left" :offset="[10, 10]" > - {{ menuItem.label }} + {{ menuItem.sysName }} {
{{ subMenu.label }} + >{{ subMenu.sysName }} @@ -847,7 +854,7 @@ const handleButtonClick = () => { { > {{ - subMenu2.label + subMenu2.sysName }} @@ -873,7 +880,7 @@ const handleButtonClick = () => { :to="{ name: `${subMenu.path}` }" > - {{ subMenu.label }} + {{ subMenu.sysName }}
@@ -887,7 +894,7 @@ const handleButtonClick = () => { :to="{ name: `${subMenu.path}` }" > - {{ subMenu.label }} + {{ subMenu.sysName }}
@@ -899,8 +906,8 @@ const handleButtonClick = () => { clickable v-ripple :to="{ name: `${menuItem.path}` }" - :active="link === menuItem.label" - @click="link = menuItem.label" + :active="link === menuItem.sysName" + @click="link = menuItem.sysName" active-class="text-primary menuActiveMini" v-else > @@ -914,7 +921,7 @@ const handleButtonClick = () => { self="center left" :offset="[10, 10]" > - {{ menuItem.label }} + {{ menuItem.sysName }}
@@ -946,28 +953,15 @@ const handleButtonClick = () => { -
+
-
+
{ active-class="text-primary active-item text-weight-bold menuSubAct" clickable v-for="subMenu2 in subMenu.children" - :key="subMenu2.key" + :key="subMenu2.id" :to="{ name: `${subMenu2.path}` }" > {{ subMenu2.label }} + >{{ subMenu2.sysName }} @@ -1028,7 +1023,7 @@ const handleButtonClick = () => { :to="{ name: `${subMenu.path}` }" > - {{ subMenu.label }} + {{ subMenu.sysName }}
@@ -1046,7 +1041,7 @@ const handleButtonClick = () => { > {{ - subMenu.label + subMenu.sysName }} @@ -1066,18 +1061,12 @@ const handleButtonClick = () => { > - + - {{ menuItem.label }} + {{ menuItem.sysName }}