hrms-mgt/src/router/index.ts

130 lines
3.9 KiB
TypeScript
Raw Normal View History

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");
2024-08-26 17:40:11 +07:00
const ErrorPermission = () => import("@/views/ErrorPermission.vue");
2023-06-01 12:54:58 +07:00
2024-07-31 09:48:33 +07:00
import ModuleMetadataNew from "@/modules/01_masterdata/router";
2024-08-01 12:12:28 +07:00
import ModuleOrganizationalNew from "@/modules/02_organization/router";
import ModulePositionEmployee from "@/modules/16_positionEmployee/router";
2023-06-01 12:54:58 +07:00
import ModuleRecruiting from "@/modules/03_recruiting/router";
2024-08-01 12:12:28 +07:00
import ModuleRegistryNew from "@/modules/04_registryPerson/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";
import ModuleRegistryEmployee from "@/modules/08_registryEmployee/router";
import ModuleLeave from "@/modules/09_leave/router";
import ModuleDiscipline from "@/modules/11_discipline/router";
2023-12-15 13:30:39 +07:00
import ModuleEvaluate from "@/modules/12_evaluatePersonal/router";
import ModuleSalary from "@/modules/13_salary/router";
import ModuleKPI from "@/modules/14_KPI/router";
import ModuleDevelopment from "@/modules/15_development/router";
import ModuleSupport from "@/modules/00_support/router";
import ModuleActing from "@/modules/17_acting/router";
2024-09-09 17:26:30 +07:00
import ModuleCommand from "@/modules/18_command/router";
import ModulePositionCondition from "@/modules/19_condition/router";
2023-06-01 12:54:58 +07:00
// TODO: ใช้หรือไม่?
2024-12-20 22:36:41 +07:00
import { authenticated, logout } from "@/plugins/auth";
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-08-26 17:40:11 +07:00
{
path: "/error",
name: "errorPermission",
component: ErrorPermission,
},
2024-07-31 09:48:33 +07:00
// ...ModuleMetadata,
...ModuleMetadataNew,
2024-07-31 09:48:33 +07:00
// ...ModuleOrganizational,
...ModuleOrganizationalNew,
...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,
...ModuleRegistryEmployee,
...ModuleLeave,
...ModuleDiscipline,
...ModuleEvaluate,
...ModuleSalary,
...ModuleKPI,
...ModuleDevelopment,
...ModuleSupport,
...ModuleActing,
2024-09-09 17:26:30 +07:00
...ModuleCommand,
...ModulePositionCondition,
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
2024-08-28 15:29:09 +07:00
// authen with client
2024-07-23 16:33:59 +07:00
{
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-08-28 15:29:09 +07:00
// authen with client
router.beforeEach(async (to, from, next) => {
2023-06-01 12:54:58 +07:00
if (to.meta.Auth) {
2024-08-28 15:29:09 +07:00
const checkAuthen = await authenticated();
2024-12-20 22:36:41 +07:00
console.log("checkAuthen", checkAuthen);
2024-08-28 15:29:09 +07:00
if (!checkAuthen && to.meta.Auth) {
2024-12-20 22:36:41 +07:00
logout();
2023-06-01 12:54:58 +07:00
}
}
2024-07-23 16:33:59 +07:00
next();
2023-06-01 12:54:58 +07:00
});
export default router;