This is an automated email from the ASF dual-hosted git repository.

zhongjiajie pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git


The following commit(s) were added to refs/heads/dev by this push:
     new 7aeb12c  feat: Added the configuration of routes (#7433)
7aeb12c is described below

commit 7aeb12c5de8e67273af45d61f284a356f32f6af1
Author: labbomb <[email protected]>
AuthorDate: Thu Dec 16 10:22:15 2021 +0800

    feat: Added the configuration of routes (#7433)
---
 dolphinscheduler-ui-next/index.html                |  8 ++++
 dolphinscheduler-ui-next/src/router/index.ts       | 45 +++++++++++--------
 .../src/router/{index.ts => routes.ts}             | 42 ++++++++++++-----
 .../{router/index.ts => utils/classification.ts}   | 52 ++++++++++++----------
 .../login/login.module.scss => utils/index.ts}     | 12 ++---
 .../login.module.scss => home/index.module.scss}   |  8 ++--
 .../{login/login.module.scss => home/index.tsx}    | 19 +++++---
 .../login/{login.module.scss => index.module.scss} |  0
 .../src/views/login/{Login.tsx => index.tsx}       |  4 +-
 dolphinscheduler-ui-next/tsconfig.json             |  3 +-
 10 files changed, 120 insertions(+), 73 deletions(-)

diff --git a/dolphinscheduler-ui-next/index.html 
b/dolphinscheduler-ui-next/index.html
index 625b9c2..0c857b6 100644
--- a/dolphinscheduler-ui-next/index.html
+++ b/dolphinscheduler-ui-next/index.html
@@ -28,4 +28,12 @@
     <div id="app"></div>
     <script type="module" src="/src/main.ts"></script>
   </body>
+  <style>
+    html, body {
+      margin: 0;
+      padding: 0;
+      width: 100%;
+      height: 100%;
+    }
+  </style>
 </html>
diff --git a/dolphinscheduler-ui-next/src/router/index.ts 
b/dolphinscheduler-ui-next/src/router/index.ts
index 801f411..df0e37c 100644
--- a/dolphinscheduler-ui-next/src/router/index.ts
+++ b/dolphinscheduler-ui-next/src/router/index.ts
@@ -15,26 +15,35 @@
  * limitations under the License.
  */
 
-import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
+import { createRouter, createWebHistory, RouteRecordRaw, NavigationGuardNext, 
RouteLocationNormalized } from 'vue-router'
+import routes from './routes'
 
-const routes: RouteRecordRaw[] = [
-  {
-    path: '/login',
-    redirect: { name: 'Login' },
-    component: () => import('@/layouts/content/Content'),
-    children: [
-      {
-        path: '/login',
-        name: 'Login',
-        component: () => import('@/views/login/Login'),
-      },
-    ],
-  },
-]
+// NProgress
+import NProgress from 'nprogress'
+import 'nprogress/nprogress.css'
 
-const index = createRouter({
+const router = createRouter({
   history: createWebHistory(),
-  routes,
+  routes
 })
 
-export default index
+/**
+ * Routing to intercept
+ */
+router.beforeEach(
+  async (
+    to: RouteLocationNormalized,
+    from: RouteLocationNormalized,
+    next: NavigationGuardNext
+  ) => {
+    NProgress.start()
+    next()
+    NProgress.done()
+  }
+)
+
+router.afterEach(() => {
+  NProgress.done()
+})
+
+export default router
\ No newline at end of file
diff --git a/dolphinscheduler-ui-next/src/router/index.ts 
b/dolphinscheduler-ui-next/src/router/routes.ts
similarity index 55%
copy from dolphinscheduler-ui-next/src/router/index.ts
copy to dolphinscheduler-ui-next/src/router/routes.ts
index 801f411..bb92803 100644
--- a/dolphinscheduler-ui-next/src/router/index.ts
+++ b/dolphinscheduler-ui-next/src/router/routes.ts
@@ -15,26 +15,44 @@
  * limitations under the License.
  */
 
-import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
+import type { RouteRecordRaw } from 'vue-router'
+import type { Component } from 'vue'
+import utils from '@/utils'
 
-const routes: RouteRecordRaw[] = [
+// All TSX files under the views folder automatically generate mapping 
relationship
+const modules = import.meta.glob('/src/views/**/**.tsx')
+const components: { [key: string]: Component } = utils.classification(modules)
+
+/**
+ * Basic page
+ */
+const basePage: RouteRecordRaw[] = [
   {
-    path: '/login',
-    redirect: { name: 'Login' },
+    path: '/',
+    redirect: { name: 'home' },
     component: () => import('@/layouts/content/Content'),
     children: [
       {
-        path: '/login',
-        name: 'Login',
-        component: () => import('@/views/login/Login'),
+        path: '/home',
+        name: 'home',
+        component: components['home'],
       },
     ],
   },
 ]
 
-const index = createRouter({
-  history: createWebHistory(),
-  routes,
-})
+/**
+ * Login page
+ */
+ const loginPage: RouteRecordRaw[] = [
+  {
+    path: '/login',
+    name: 'login',
+    component: components['login']
+  }
+]
+
+const routes: RouteRecordRaw[] = [...basePage, ...loginPage]
 
-export default index
+// 重新组织后导出
+export default routes
\ No newline at end of file
diff --git a/dolphinscheduler-ui-next/src/router/index.ts 
b/dolphinscheduler-ui-next/src/utils/classification.ts
similarity index 50%
copy from dolphinscheduler-ui-next/src/router/index.ts
copy to dolphinscheduler-ui-next/src/utils/classification.ts
index 801f411..9e03e2a 100644
--- a/dolphinscheduler-ui-next/src/router/index.ts
+++ b/dolphinscheduler-ui-next/src/utils/classification.ts
@@ -15,26 +15,32 @@
  * limitations under the License.
  */
 
-import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
-
-const routes: RouteRecordRaw[] = [
-  {
-    path: '/login',
-    redirect: { name: 'Login' },
-    component: () => import('@/layouts/content/Content'),
-    children: [
-      {
-        path: '/login',
-        name: 'Login',
-        component: () => import('@/views/login/Login'),
-      },
-    ],
-  },
-]
-
-const index = createRouter({
-  history: createWebHistory(),
-  routes,
-})
-
-export default index
+import type { Component } from 'vue'
+
+interface modules extends Object {
+  [key: string]: any
+}
+
+const classification = (modules: modules) => {
+  const components: { [key: string]: Component } = {}
+  // All TSX files under the views folder automatically generate mapping 
relationship
+  Object.keys(modules).forEach((key: string) => {
+    const nameMatch: string[] | null = key.match(/^\/src\/views\/(.+)\.tsx/)
+
+    if (!nameMatch) {
+      return
+    }
+
+    // If the page is named Index, the parent folder is used as the name
+    const indexMatch: string[] | null = nameMatch[1].match(/(.*)\/Index$/i)
+
+    let name: string = indexMatch ? indexMatch[1] : nameMatch[1]
+
+    ;[name] = name.split('/').splice(-1)
+
+    components[name] = modules[key]
+  })
+  return components
+}
+
+export default classification
diff --git a/dolphinscheduler-ui-next/src/views/login/login.module.scss 
b/dolphinscheduler-ui-next/src/utils/index.ts
similarity index 87%
copy from dolphinscheduler-ui-next/src/views/login/login.module.scss
copy to dolphinscheduler-ui-next/src/utils/index.ts
index b71f6b6..c9f8c51 100644
--- a/dolphinscheduler-ui-next/src/views/login/login.module.scss
+++ b/dolphinscheduler-ui-next/src/utils/index.ts
@@ -15,10 +15,10 @@
  * limitations under the License.
  */
 
-.container {
-  width: 100%;
-  height: 100vh;
-  display: flex;
-  justify-content: center;
-  align-items: center;
+import classification from './classification'
+
+const utils = {
+  classification
 }
+
+export default utils
diff --git a/dolphinscheduler-ui-next/src/views/login/login.module.scss 
b/dolphinscheduler-ui-next/src/views/home/index.module.scss
similarity index 99%
copy from dolphinscheduler-ui-next/src/views/login/login.module.scss
copy to dolphinscheduler-ui-next/src/views/home/index.module.scss
index b71f6b6..cf9cc8d 100644
--- a/dolphinscheduler-ui-next/src/views/login/login.module.scss
+++ b/dolphinscheduler-ui-next/src/views/home/index.module.scss
@@ -16,9 +16,9 @@
  */
 
 .container {
-  width: 100%;
-  height: 100vh;
   display: flex;
-  justify-content: center;
   align-items: center;
-}
+  justify-content: center;
+  width: 100%;
+  height: 100vh;
+}
\ No newline at end of file
diff --git a/dolphinscheduler-ui-next/src/views/login/login.module.scss 
b/dolphinscheduler-ui-next/src/views/home/index.tsx
similarity index 76%
copy from dolphinscheduler-ui-next/src/views/login/login.module.scss
copy to dolphinscheduler-ui-next/src/views/home/index.tsx
index b71f6b6..82f1038 100644
--- a/dolphinscheduler-ui-next/src/views/login/login.module.scss
+++ b/dolphinscheduler-ui-next/src/views/home/index.tsx
@@ -15,10 +15,15 @@
  * limitations under the License.
  */
 
-.container {
-  width: 100%;
-  height: 100vh;
-  display: flex;
-  justify-content: center;
-  align-items: center;
-}
+import { defineComponent } from 'vue'
+import styles from './index.module.scss'
+
+export default defineComponent({
+    name: 'home',
+    setup() {},
+    render() {
+      return <div class={styles.container}>
+        Home Test
+      </div>
+    }
+})
\ No newline at end of file
diff --git a/dolphinscheduler-ui-next/src/views/login/login.module.scss 
b/dolphinscheduler-ui-next/src/views/login/index.module.scss
similarity index 100%
rename from dolphinscheduler-ui-next/src/views/login/login.module.scss
rename to dolphinscheduler-ui-next/src/views/login/index.module.scss
diff --git a/dolphinscheduler-ui-next/src/views/login/Login.tsx 
b/dolphinscheduler-ui-next/src/views/login/index.tsx
similarity index 96%
rename from dolphinscheduler-ui-next/src/views/login/Login.tsx
rename to dolphinscheduler-ui-next/src/views/login/index.tsx
index 488127e..12910d7 100644
--- a/dolphinscheduler-ui-next/src/views/login/Login.tsx
+++ b/dolphinscheduler-ui-next/src/views/login/index.tsx
@@ -16,13 +16,13 @@
  */
 
 import { defineComponent } from 'vue'
-import styles from './login.module.scss'
+import styles from './index.module.scss'
 import { useI18n } from 'vue-i18n'
 import { NButton } from 'naive-ui'
 import { useThemeStore } from '@/store/theme/theme'
 
 const Login = defineComponent({
-  name: 'Login',
+  name: 'login',
   setup() {
     const { t, locale } = useI18n()
     const themeStore = useThemeStore()
diff --git a/dolphinscheduler-ui-next/tsconfig.json 
b/dolphinscheduler-ui-next/tsconfig.json
index cc9ac7a..a203ad7 100644
--- a/dolphinscheduler-ui-next/tsconfig.json
+++ b/dolphinscheduler-ui-next/tsconfig.json
@@ -12,7 +12,8 @@
     "baseUrl": ".",
     "paths": {
       "@/*": ["src/*"]
-    }
+    },
+    "types": ["vite/client"]
   },
   "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"]
 }

Reply via email to