2023-06-01 12:54:58 +07:00
|
|
|
import { createRouter, createWebHistory } from "vue-router";
|
|
|
|
|
|
|
|
|
|
const MainLayout = () => import("@/views/MainLayout.vue");
|
|
|
|
|
const Dashboard = () => import("@/views/Dashboard.vue");
|
|
|
|
|
const Error404NotFound = () => import("@/views/Error404NotFound.vue");
|
2024-07-23 16:33:59 +07:00
|
|
|
const loginView = () => import("@/views/login.vue");
|
2023-06-01 12:54:58 +07:00
|
|
|
|
2024-07-31 09:48:33 +07:00
|
|
|
// import ModuleMetadata from "@/modules/01_metadata/router";
|
|
|
|
|
import ModuleMetadataNew from "@/modules/01_masterdata/router";
|
|
|
|
|
// import ModuleOrganizational from "@/modules/02_organizational/router";
|
2024-01-12 13:54:47 +07:00
|
|
|
import ModuleOrganizationalNew from "@/modules/02_organizationalNew/router";
|
2024-03-14 16:03:27 +07:00
|
|
|
import ModulePositionEmployee from "@/modules/16_positionEmployee/router";
|
2023-06-01 12:54:58 +07:00
|
|
|
import ModuleRecruiting from "@/modules/03_recruiting/router";
|
2024-07-31 09:48:33 +07:00
|
|
|
import ModuleRegistryNew from "@/modules/04_registryNew/router";
|
|
|
|
|
// import ModuleRegistry from "@/modules/04_registry/router";
|
2023-06-01 12:54:58 +07:00
|
|
|
import ModulePlacement from "@/modules/05_placement/router";
|
|
|
|
|
import ModuleRetirement from "@/modules/06_retirement/router";
|
|
|
|
|
import ModuleInsignia from "@/modules/07_insignia/router";
|
2023-07-04 17:40:05 +07:00
|
|
|
import ModuleRegistryEmployee from "@/modules/08_registryEmployee/router";
|
2023-08-10 17:58:18 +07:00
|
|
|
import ModuleOrder from "@/modules/10_order/router";
|
2023-10-16 13:28:48 +07:00
|
|
|
import ModuleLeave from "@/modules/09_leave/router";
|
2023-12-15 09:05:52 +07:00
|
|
|
import ModuleDiscipline from "@/modules/11_discipline/router";
|
2023-12-15 13:30:39 +07:00
|
|
|
import ModuleEvaluate from "@/modules/12_evaluatePersonal/router";
|
2024-02-15 11:46:25 +07:00
|
|
|
import ModuleSalary from "@/modules/13_salary/router";
|
|
|
|
|
import ModuleKPI from "@/modules/14_KPI/router";
|
|
|
|
|
import ModuleDevelopment from "@/modules/15_development/router";
|
2024-01-29 11:11:08 +07:00
|
|
|
import ModuleSupport from "@/modules/00_support/router";
|
2024-06-18 16:42:40 +07:00
|
|
|
import ModuleActing from "@/modules/17_acting/router";
|
2023-06-01 12:54:58 +07:00
|
|
|
|
|
|
|
|
// TODO: ใช้หรือไม่?
|
2024-07-26 12:52:47 +07:00
|
|
|
import keycloak, { kcLogout } from "@/plugins/keycloak";
|
2023-06-01 12:54:58 +07:00
|
|
|
|
|
|
|
|
const router = createRouter({
|
|
|
|
|
history: createWebHistory(import.meta.env.BASE_URL),
|
|
|
|
|
routes: [
|
|
|
|
|
{
|
|
|
|
|
path: "/",
|
|
|
|
|
name: "home",
|
|
|
|
|
component: MainLayout,
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
path: "/",
|
|
|
|
|
name: "dashboard",
|
|
|
|
|
component: Dashboard,
|
|
|
|
|
meta: {
|
|
|
|
|
Auth: true,
|
2024-07-31 09:48:33 +07:00
|
|
|
Key: "HOME",
|
2023-06-01 12:54:58 +07:00
|
|
|
},
|
|
|
|
|
},
|
2024-07-31 09:48:33 +07:00
|
|
|
// ...ModuleMetadata,
|
2024-01-12 13:54:47 +07:00
|
|
|
...ModuleMetadataNew,
|
2024-07-31 09:48:33 +07:00
|
|
|
// ...ModuleOrganizational,
|
2024-01-12 13:54:47 +07:00
|
|
|
...ModuleOrganizationalNew,
|
2024-03-14 16:03:27 +07:00
|
|
|
...ModulePositionEmployee,
|
2023-06-01 12:54:58 +07:00
|
|
|
...ModuleRecruiting,
|
2024-07-31 09:48:33 +07:00
|
|
|
// ...ModuleRegistry,
|
|
|
|
|
...ModuleRegistryNew,
|
2023-06-01 12:54:58 +07:00
|
|
|
...ModulePlacement,
|
|
|
|
|
...ModuleRetirement,
|
|
|
|
|
...ModuleInsignia,
|
2023-07-04 17:40:05 +07:00
|
|
|
...ModuleRegistryEmployee,
|
2023-08-10 17:58:18 +07:00
|
|
|
...ModuleOrder,
|
2023-10-16 13:28:48 +07:00
|
|
|
...ModuleLeave,
|
2023-12-14 12:23:34 +07:00
|
|
|
...ModuleDiscipline,
|
2023-12-15 09:05:52 +07:00
|
|
|
...ModuleEvaluate,
|
2024-02-15 11:46:25 +07:00
|
|
|
...ModuleSalary,
|
|
|
|
|
...ModuleKPI,
|
|
|
|
|
...ModuleDevelopment,
|
2024-01-29 11:11:08 +07:00
|
|
|
...ModuleSupport,
|
2024-06-18 16:42:40 +07:00
|
|
|
...ModuleActing,
|
2023-06-01 12:54:58 +07:00
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* 404 Not Found
|
|
|
|
|
* ref: https://router.vuejs.org/guide/essentials/dynamic-matching.html#catch-all-404-not-found-route
|
|
|
|
|
*/
|
|
|
|
|
{
|
|
|
|
|
// path: "/:catchAll(.*)*", // TODO: ใช้ pathMatch แทนตามในเอกสารแนะนำ คงไว้เผื่อจำเป็น
|
|
|
|
|
path: "/:pathMatch(.*)*",
|
|
|
|
|
component: Error404NotFound,
|
|
|
|
|
},
|
2024-07-23 16:33:59 +07:00
|
|
|
|
|
|
|
|
// authen with keycloak client
|
|
|
|
|
{
|
|
|
|
|
path: "/login",
|
|
|
|
|
name: "loginMain",
|
|
|
|
|
component: loginView,
|
|
|
|
|
meta: {
|
|
|
|
|
Auth: false,
|
|
|
|
|
},
|
|
|
|
|
},
|
2024-07-26 12:52:47 +07:00
|
|
|
{
|
|
|
|
|
path: "/auth",
|
|
|
|
|
name: "auth",
|
|
|
|
|
component: () => import("@/views/auth.vue"),
|
|
|
|
|
},
|
2023-06-01 12:54:58 +07:00
|
|
|
],
|
|
|
|
|
|
|
|
|
|
scrollBehavior(to, from, savedPosition) {
|
|
|
|
|
if (savedPosition) {
|
|
|
|
|
return savedPosition;
|
|
|
|
|
} else if (to.hash) {
|
|
|
|
|
return {
|
|
|
|
|
el: to.hash,
|
|
|
|
|
behavior: "smooth",
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2024-07-23 16:33:59 +07:00
|
|
|
// authen with keycloak client
|
2023-06-01 12:54:58 +07:00
|
|
|
router.beforeEach((to, from, next) => {
|
|
|
|
|
if (to.meta.Auth) {
|
2024-07-26 12:52:47 +07:00
|
|
|
if (keycloak.authenticated === undefined) {
|
|
|
|
|
kcLogout();
|
|
|
|
|
} else {
|
|
|
|
|
next();
|
2023-06-01 12:54:58 +07:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
next();
|
|
|
|
|
}
|
2024-07-23 16:33:59 +07:00
|
|
|
next();
|
2023-06-01 12:54:58 +07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export default router;
|