From 607f28ee0e724b00f7eab45469cbc839536a1a83 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Mon, 24 Jun 2024 13:07:27 +0700 Subject: [PATCH] Add normal --- public/build-and-deploy.md | 1 + public/debug.md | 1 + public/pages.json | 14 ++ src/modules/01_manual/MainPage.vue | 2 +- src/modules/02_pages/MainPage.vue | 263 ++++++++++++++++++++++++++ src/modules/{01_manual => }/router.ts | 11 +- src/router/index.ts | 136 ++++++------- src/views/MainLayout.vue | 10 +- 8 files changed, 365 insertions(+), 73 deletions(-) create mode 100644 public/build-and-deploy.md create mode 100644 public/debug.md create mode 100644 public/pages.json create mode 100644 src/modules/02_pages/MainPage.vue rename src/modules/{01_manual => }/router.ts (50%) diff --git a/public/build-and-deploy.md b/public/build-and-deploy.md new file mode 100644 index 00000000..39e7fc0f --- /dev/null +++ b/public/build-and-deploy.md @@ -0,0 +1 @@ +# Build and Deploy diff --git a/public/debug.md b/public/debug.md new file mode 100644 index 00000000..2fab5925 --- /dev/null +++ b/public/debug.md @@ -0,0 +1 @@ +# Debug diff --git a/public/pages.json b/public/pages.json new file mode 100644 index 00000000..b330d1a6 --- /dev/null +++ b/public/pages.json @@ -0,0 +1,14 @@ +[ + { + "icon": "mdi-file-outline", + "activeIcon": "mdi-file", + "label": "การตรวจสอบและแก้ไขปัญหา", + "path": "/debug" + }, + { + "icon": "mdi-file-outline", + "activeIcon": "mdi-file", + "label": "Build and Deploy", + "path": "/build-and-deploy" + } +] diff --git a/src/modules/01_manual/MainPage.vue b/src/modules/01_manual/MainPage.vue index ec9436d6..167fb44c 100644 --- a/src/modules/01_manual/MainPage.vue +++ b/src/modules/01_manual/MainPage.vue @@ -25,7 +25,7 @@ const active = ref(""); function onScroll() { let current = ""; - document.querySelectorAll("h2,h3").forEach((v) => { + document.querySelectorAll("h2,h3").forEach((v) => { if ( window.top && window.top.scrollY + window.innerHeight / 2 > v.offsetTop diff --git a/src/modules/02_pages/MainPage.vue b/src/modules/02_pages/MainPage.vue new file mode 100644 index 00000000..f730365b --- /dev/null +++ b/src/modules/02_pages/MainPage.vue @@ -0,0 +1,263 @@ + + + + + diff --git a/src/modules/01_manual/router.ts b/src/modules/router.ts similarity index 50% rename from src/modules/01_manual/router.ts rename to src/modules/router.ts index 1ec79225..79622bae 100644 --- a/src/modules/01_manual/router.ts +++ b/src/modules/router.ts @@ -1,9 +1,16 @@ import type { RouteRecordRaw } from "vue-router"; -export default [ +const route: RouteRecordRaw[] = [ { path: "/manual/:name", name: "Manual", component: () => import("@/modules/01_manual/MainPage.vue"), }, -] satisfies RouteRecordRaw[]; + { + path: "/:name", + name: "Pages", + component: () => import("@/modules/02_pages/MainPage.vue"), + }, +]; + +export default route; diff --git a/src/router/index.ts b/src/router/index.ts index 5093c23b..6c0813f9 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -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/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", - }, - }, - ...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; diff --git a/src/views/MainLayout.vue b/src/views/MainLayout.vue index 0acd3a2a..b10f0e8d 100644 --- a/src/views/MainLayout.vue +++ b/src/views/MainLayout.vue @@ -37,8 +37,14 @@ const toggleBtnLeft = () => { }; onMounted(async () => { - const data = await fetch("/toc.json").then((r) => r.json()); - menuList.value[1].children = data; + { + const data = await fetch("/toc.json").then((r) => r.json()); + menuList.value[1].children = data; + } + { + const data = await fetch("/pages.json").then((r) => r.json()); + menuList.value.push(...data); + } }); const downloadFile = () => {