seatonwan9
2025-09-02 83d5b2be8fdf0ac0b59cacf6b344c8815ab4d040
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { RouteRecordRaw } from 'vue-router'
 
const pageTitle = (name: String): string => {
  return `pagesTitle.${name}`
}
 
// 自动引入modules下的所有路由信息
const moduleFiles = import.meta.globEager('./modules/*.ts')
// 通过 reduce 去搜集所有的模块的导出内容
const configRoutes = Object.keys(moduleFiles).reduce(
  (routes: any = [], filepath) => {
    // 因为moduleFiles是一个函数,那么可以接受一个参数(string:文件的相对路径),调用其从而获取到对应路径下的模块的导出对象
    // 导出的对象中有一个属性:default,可以获取到默认导出的所有内容
    const value = moduleFiles[filepath].default
 
    // 我们判断导出的是不是数组,是则进行拓展解构
    if (Array.isArray(value)) {
      routes.push(...value)
    } else {
      // 否则直接加到routes中
      routes.push(value)
    }
    return routes
  },
  []
)
 
/* 静态路由 */
const staticRoutes: Array<RouteRecordRaw> = [
  {
    // 管理后台首页
    path: '/',
    name: 'Layout',
    redirect: '/home',
    component: () => import('@/views/layout/index.vue'),
    meta: {
      title: '产业数字化资源能力平台',
    },
    children: [
      {
        // 首页
        path: 'home',
        name: 'home',
        component: () => import('@/views/home/index.vue'),
        meta: {
          title: '产业数字化资源能力平台',
        },
      },
       
      ...configRoutes,
       
      // 404页面
      {
        path: '/404',
        name: '404',
        component: () => import('@/views/common/404.vue'),
      },
      // 所有匹配不到的页面都跳转到404页面
      {
        path: '/:pathMatch(.*)',
        redirect: '/404',
      },
    ],
  },
  // {
  //   // 管理后台登录
  //   path: '/login',
  //   name: 'login',
  //   component: () => import('../views/login/index.vue'),
  //   meta: {
  //     title: '请登录',
  //   },
  // },
  {
    // 管理后台登录
    path: '/loginT',
    name: 'loginT',
    component: () => import('../views/loginT/index.vue'),
    meta: {
      title: '产业数字化资源能力平台',
    },
  },
]
export { staticRoutes }