start commit for admin system

This commit is contained in:
Warunee Tamkoo 2024-05-29 17:58:57 +07:00
commit badb676529
300 changed files with 58634 additions and 0 deletions

83
src/router/index.ts Normal file
View file

@ -0,0 +1,83 @@
import { createRouter, createWebHistory } from "vue-router";
const MainLayout = () => import("@/views/MainLayout.vue");
const Dashboard = () => import("@/views/Dashboard.vue");
const Error404NotFound = () => import("@/views/Error404NotFound.vue");
import ModuleMetadata from "@/modules/01_metadata/router";
// TODO: ใช้หรือไม่?
import keycloak from "@/plugins/keycloak";
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,
Key: [7],
Role: "dashboard",
},
},
...ModuleMetadata,
],
},
/**
* 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,
},
],
scrollBehavior(to, from, savedPosition) {
if (savedPosition) {
return savedPosition;
} else if (to.hash) {
return {
el: to.hash,
behavior: "smooth",
};
}
},
});
router.beforeEach((to, from, next) => {
if (to.meta.Auth) {
if (!keycloak.authenticated) {
keycloak.login({
redirectUri: `${window.location.protocol}//${window.location.host}${to.path}`,
locale: "th",
});
} else {
// keycloak.updateToken(60);
const role = keycloak.tokenParsed?.role;
// ถ้าเป็นคนกรอกข้อมูล
if (role.includes("keyregistry") && to.meta.Role != "registry") {
next({ path: "/registry" });
} else if (role.includes(to.meta.Role)) {
next();
} else {
next({ path: "" });
// next();
}
}
} else {
next();
}
// next();
});
export default router;