set file build image

This commit is contained in:
Kittapath 2023-11-07 19:23:16 +07:00
parent a079fcd0ae
commit 970c582e34
7 changed files with 1793 additions and 2223 deletions

View file

@ -1,79 +1,79 @@
import { createRouter, createWebHistory } from "vue-router";
import { createRouter, createWebHistory } from "vue-router"
const MainLayout = () => import("@/views/MainLayout.vue");
const Dashboard = () => import("@/views/Dashboard.vue");
const Error404NotFound = () => import("@/views/Error404NotFound.vue");
const MainLayout = () => import("@/views/MainLayout.vue")
const Dashboard = () => import("@/views/Dashboard.vue")
const Error404NotFound = () => import("@/views/Error404NotFound.vue")
import ModuleManual from "@/modules/01_manual/router";
import ModuleManual from "@/modules/01_manual/router"
// TODO: ใช้หรือไม่?
import keycloak from "@/plugins/keycloak";
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",
},
},
...ModuleManual,
],
},
/**
* 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,
},
],
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",
// },
// },
...ModuleManual,
],
},
/**
* 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",
};
}
},
});
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(to.meta.Role)) {
next();
} else {
next({ path: "" });
// next();
}
}
} else {
next();
}
// 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(to.meta.Role)) {
// next()
// } else {
// next({ path: "" })
// // next();
// }
// }
// } else {
// next()
// }
next()
})
export default router;
export default router