From caa020f367886a49cff02af3e506189a591e4398 Mon Sep 17 00:00:00 2001 From: liangping <18786721@qq.com> Date: Fri, 10 Feb 2023 10:42:05 +0800 Subject: [PATCH] refactor project --- .../{plugins/vuetify => }/layouts/blank.vue | 0 .../DefaultLayoutWithHorizontalNav.vue | 0 .../DefaultLayoutWithVerticalNav.vue | 8 +-- .../layouts/components/Footer.vue | 0 .../layouts/components/NavBarI18n.vue | 0 .../components/NavBarNotifications.vue | 0 .../layouts/components/NavSearchBar.vue | 0 .../layouts/components/NavbarShortcuts.vue | 0 .../components/NavbarThemeSwitcher.vue | 0 .../layouts/components/UserProfile.vue | 0 .../{plugins/vuetify => }/layouts/default.vue | 0 packages/dashboard/src/main.ts | 4 +- .../login.vue => modules/[chain]/test.vue} | 0 .../dashboard/src/modules/dashboard/View.vue | 5 -- .../dashboard/src/modules/dashboard/router.ts | 9 ---- packages/dashboard/src/modules/index.ts | 0 .../{plugins/vuetify => }/pages/[...all].vue | 0 .../src/{plugins/vuetify => }/pages/index.vue | 0 .../vuetify => }/pages/second-page.vue | 0 .../src/plugins/vuetify/router/index.ts | 14 ----- .../src/plugins/vuetify/router/utils.ts | 6 --- packages/dashboard/src/router/index.ts | 52 +++---------------- packages/dashboard/vite.config.ts | 4 +- 23 files changed, 15 insertions(+), 87 deletions(-) rename packages/dashboard/src/{plugins/vuetify => }/layouts/blank.vue (100%) rename packages/dashboard/src/{plugins/vuetify => }/layouts/components/DefaultLayoutWithHorizontalNav.vue (100%) rename packages/dashboard/src/{plugins/vuetify => }/layouts/components/DefaultLayoutWithVerticalNav.vue (87%) rename packages/dashboard/src/{plugins/vuetify => }/layouts/components/Footer.vue (100%) rename packages/dashboard/src/{plugins/vuetify => }/layouts/components/NavBarI18n.vue (100%) rename packages/dashboard/src/{plugins/vuetify => }/layouts/components/NavBarNotifications.vue (100%) rename packages/dashboard/src/{plugins/vuetify => }/layouts/components/NavSearchBar.vue (100%) rename packages/dashboard/src/{plugins/vuetify => }/layouts/components/NavbarShortcuts.vue (100%) rename packages/dashboard/src/{plugins/vuetify => }/layouts/components/NavbarThemeSwitcher.vue (100%) rename packages/dashboard/src/{plugins/vuetify => }/layouts/components/UserProfile.vue (100%) rename packages/dashboard/src/{plugins/vuetify => }/layouts/default.vue (100%) rename packages/dashboard/src/{plugins/vuetify/pages/login.vue => modules/[chain]/test.vue} (100%) delete mode 100644 packages/dashboard/src/modules/dashboard/View.vue delete mode 100644 packages/dashboard/src/modules/dashboard/router.ts delete mode 100644 packages/dashboard/src/modules/index.ts rename packages/dashboard/src/{plugins/vuetify => }/pages/[...all].vue (100%) rename packages/dashboard/src/{plugins/vuetify => }/pages/index.vue (100%) rename packages/dashboard/src/{plugins/vuetify => }/pages/second-page.vue (100%) delete mode 100644 packages/dashboard/src/plugins/vuetify/router/index.ts delete mode 100644 packages/dashboard/src/plugins/vuetify/router/utils.ts diff --git a/packages/dashboard/src/plugins/vuetify/layouts/blank.vue b/packages/dashboard/src/layouts/blank.vue similarity index 100% rename from packages/dashboard/src/plugins/vuetify/layouts/blank.vue rename to packages/dashboard/src/layouts/blank.vue diff --git a/packages/dashboard/src/plugins/vuetify/layouts/components/DefaultLayoutWithHorizontalNav.vue b/packages/dashboard/src/layouts/components/DefaultLayoutWithHorizontalNav.vue similarity index 100% rename from packages/dashboard/src/plugins/vuetify/layouts/components/DefaultLayoutWithHorizontalNav.vue rename to packages/dashboard/src/layouts/components/DefaultLayoutWithHorizontalNav.vue diff --git a/packages/dashboard/src/plugins/vuetify/layouts/components/DefaultLayoutWithVerticalNav.vue b/packages/dashboard/src/layouts/components/DefaultLayoutWithVerticalNav.vue similarity index 87% rename from packages/dashboard/src/plugins/vuetify/layouts/components/DefaultLayoutWithVerticalNav.vue rename to packages/dashboard/src/layouts/components/DefaultLayoutWithVerticalNav.vue index 8bfed21b..3178bc83 100644 --- a/packages/dashboard/src/plugins/vuetify/layouts/components/DefaultLayoutWithVerticalNav.vue +++ b/packages/dashboard/src/layouts/components/DefaultLayoutWithVerticalNav.vue @@ -3,12 +3,12 @@ import navItems from '@/plugins/vuetify/navigation/vertical' import { useThemeConfig } from '@/plugins/vuetify/@core/composable/useThemeConfig' // Components -import Footer from '@/plugins/vuetify/layouts/components/Footer.vue' -import NavbarThemeSwitcher from '@/plugins/vuetify/layouts/components/NavbarThemeSwitcher.vue' -import UserProfile from '@/plugins/vuetify/layouts/components/UserProfile.vue' +import Footer from '@/layouts/components/Footer.vue' +import NavbarThemeSwitcher from '@/layouts/components/NavbarThemeSwitcher.vue' +import UserProfile from '@/layouts/components/UserProfile.vue' // @layouts plugin -import { VerticalNavLayout } from '@/plugins/vuetify/@layouts' +import { VerticalNavLayout } from '@layouts' const { appRouteTransition, isLessThanOverlayNavBreakpoint, isVerticalNavCollapsed } = useThemeConfig() const { width: windowWidth } = useWindowSize() diff --git a/packages/dashboard/src/plugins/vuetify/layouts/components/Footer.vue b/packages/dashboard/src/layouts/components/Footer.vue similarity index 100% rename from packages/dashboard/src/plugins/vuetify/layouts/components/Footer.vue rename to packages/dashboard/src/layouts/components/Footer.vue diff --git a/packages/dashboard/src/plugins/vuetify/layouts/components/NavBarI18n.vue b/packages/dashboard/src/layouts/components/NavBarI18n.vue similarity index 100% rename from packages/dashboard/src/plugins/vuetify/layouts/components/NavBarI18n.vue rename to packages/dashboard/src/layouts/components/NavBarI18n.vue diff --git a/packages/dashboard/src/plugins/vuetify/layouts/components/NavBarNotifications.vue b/packages/dashboard/src/layouts/components/NavBarNotifications.vue similarity index 100% rename from packages/dashboard/src/plugins/vuetify/layouts/components/NavBarNotifications.vue rename to packages/dashboard/src/layouts/components/NavBarNotifications.vue diff --git a/packages/dashboard/src/plugins/vuetify/layouts/components/NavSearchBar.vue b/packages/dashboard/src/layouts/components/NavSearchBar.vue similarity index 100% rename from packages/dashboard/src/plugins/vuetify/layouts/components/NavSearchBar.vue rename to packages/dashboard/src/layouts/components/NavSearchBar.vue diff --git a/packages/dashboard/src/plugins/vuetify/layouts/components/NavbarShortcuts.vue b/packages/dashboard/src/layouts/components/NavbarShortcuts.vue similarity index 100% rename from packages/dashboard/src/plugins/vuetify/layouts/components/NavbarShortcuts.vue rename to packages/dashboard/src/layouts/components/NavbarShortcuts.vue diff --git a/packages/dashboard/src/plugins/vuetify/layouts/components/NavbarThemeSwitcher.vue b/packages/dashboard/src/layouts/components/NavbarThemeSwitcher.vue similarity index 100% rename from packages/dashboard/src/plugins/vuetify/layouts/components/NavbarThemeSwitcher.vue rename to packages/dashboard/src/layouts/components/NavbarThemeSwitcher.vue diff --git a/packages/dashboard/src/plugins/vuetify/layouts/components/UserProfile.vue b/packages/dashboard/src/layouts/components/UserProfile.vue similarity index 100% rename from packages/dashboard/src/plugins/vuetify/layouts/components/UserProfile.vue rename to packages/dashboard/src/layouts/components/UserProfile.vue diff --git a/packages/dashboard/src/plugins/vuetify/layouts/default.vue b/packages/dashboard/src/layouts/default.vue similarity index 100% rename from packages/dashboard/src/plugins/vuetify/layouts/default.vue rename to packages/dashboard/src/layouts/default.vue diff --git a/packages/dashboard/src/main.ts b/packages/dashboard/src/main.ts index 4c1a059e..d6d99db7 100644 --- a/packages/dashboard/src/main.ts +++ b/packages/dashboard/src/main.ts @@ -8,8 +8,8 @@ import "@/plugins/vuetify/@core/scss/template/index.scss"; import "@/plugins/vuetify/styles/styles.scss"; import { createApp } from "vue"; import { createPinia } from "pinia"; -// import router from "./router"; -import router from "@/plugins/vuetify/router"; +import router from "./router"; +// import router from "@/plugins/vuetify/router"; loadFonts(); diff --git a/packages/dashboard/src/plugins/vuetify/pages/login.vue b/packages/dashboard/src/modules/[chain]/test.vue similarity index 100% rename from packages/dashboard/src/plugins/vuetify/pages/login.vue rename to packages/dashboard/src/modules/[chain]/test.vue diff --git a/packages/dashboard/src/modules/dashboard/View.vue b/packages/dashboard/src/modules/dashboard/View.vue deleted file mode 100644 index 7d06ff41..00000000 --- a/packages/dashboard/src/modules/dashboard/View.vue +++ /dev/null @@ -1,5 +0,0 @@ - diff --git a/packages/dashboard/src/modules/dashboard/router.ts b/packages/dashboard/src/modules/dashboard/router.ts deleted file mode 100644 index e05e047e..00000000 --- a/packages/dashboard/src/modules/dashboard/router.ts +++ /dev/null @@ -1,9 +0,0 @@ -import type { RouteRecordRaw } from "vue-router"; - -export const routes: RouteRecordRaw[] = [ - { - path: "/dashboard", - alias: ["dashboard"], - component: () => import("./View.vue"), - }, -]; diff --git a/packages/dashboard/src/modules/index.ts b/packages/dashboard/src/modules/index.ts deleted file mode 100644 index e69de29b..00000000 diff --git a/packages/dashboard/src/plugins/vuetify/pages/[...all].vue b/packages/dashboard/src/pages/[...all].vue similarity index 100% rename from packages/dashboard/src/plugins/vuetify/pages/[...all].vue rename to packages/dashboard/src/pages/[...all].vue diff --git a/packages/dashboard/src/plugins/vuetify/pages/index.vue b/packages/dashboard/src/pages/index.vue similarity index 100% rename from packages/dashboard/src/plugins/vuetify/pages/index.vue rename to packages/dashboard/src/pages/index.vue diff --git a/packages/dashboard/src/plugins/vuetify/pages/second-page.vue b/packages/dashboard/src/pages/second-page.vue similarity index 100% rename from packages/dashboard/src/plugins/vuetify/pages/second-page.vue rename to packages/dashboard/src/pages/second-page.vue diff --git a/packages/dashboard/src/plugins/vuetify/router/index.ts b/packages/dashboard/src/plugins/vuetify/router/index.ts deleted file mode 100644 index 34320b13..00000000 --- a/packages/dashboard/src/plugins/vuetify/router/index.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { setupLayouts } from "virtual:generated-layouts"; -import { createRouter, createWebHistory } from "vue-router"; -import routes from "~pages"; -import { routes as route2 } from "@/router"; -import { canNavigate } from "@layouts/plugins/casl"; - -const router = createRouter({ - history: createWebHistory(import.meta.env.BASE_URL), - routes: [...setupLayouts(routes), ...route2], -}); - -// Docs: https://router.vuejs.org/guide/advanced/navigation-guards.html#global-before-guards - -export default router; diff --git a/packages/dashboard/src/plugins/vuetify/router/utils.ts b/packages/dashboard/src/plugins/vuetify/router/utils.ts deleted file mode 100644 index bb79e180..00000000 --- a/packages/dashboard/src/plugins/vuetify/router/utils.ts +++ /dev/null @@ -1,6 +0,0 @@ -/** - * Return if user is logged in - * This is completely up to you and how you want to store the token in your frontend application - * e.g. If you are using cookies to store the application please update this function - */ -export const isUserLoggedIn = () => !!(localStorage.getItem('userData') && localStorage.getItem('accessToken')) diff --git a/packages/dashboard/src/router/index.ts b/packages/dashboard/src/router/index.ts index bbeffd54..8f09a5d0 100644 --- a/packages/dashboard/src/router/index.ts +++ b/packages/dashboard/src/router/index.ts @@ -1,50 +1,12 @@ -import { - createRouter, - createWebHistory, - type RouteRecordRaw, -} from "vue-router"; -import HomeView from "../views/HomeView.vue"; -import DashboardLayout from "@/plugins/vuetify/layouts/default.vue"; +import { setupLayouts } from "virtual:generated-layouts"; +import { createRouter, createWebHistory } from "vue-router"; +import routes from "~pages"; -const modules: Record = import.meta.glob( - "../modules/*/router.ts", - { eager: true } -); -let children: RouteRecordRaw[] = []; - -for (const path in modules) { - children = children.concat(modules[path].routes); -} - -console.log(children); - -export const routes = [ - { - path: "/about", - name: "about", - component: () => import("../views/AboutView.vue"), - }, - // setup all modules here. - { - path: "/:chain", - component: DashboardLayout, - children: [ - { - path: "", - component: () => import("../views/AboutView.vue"), - }, - ...children, - ], - }, - { - path: "/", - name: "home", - component: HomeView, - }, -]; const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), - routes, + routes: [...setupLayouts(routes)], }); -export default router; +// Docs: https://router.vuejs.org/guide/advanced/navigation-guards.html#global-before-guards + +export default router; \ No newline at end of file diff --git a/packages/dashboard/vite.config.ts b/packages/dashboard/vite.config.ts index aea7bf84..ee460ffc 100644 --- a/packages/dashboard/vite.config.ts +++ b/packages/dashboard/vite.config.ts @@ -21,10 +21,10 @@ export default defineConfig({ }, }), Pages({ - dirs: ["./src/plugins/vuetify/pages"], + dirs: ["./src/pages", "./src/modules"], }), Layouts({ - layoutsDirs: "./src/plugins/vuetify/layouts/", + layoutsDirs: "./src/layouts/", }), Components({ dirs: ["src/plugins/vuetify/@core/components"],