#
Junjie
2024-07-03 acebf48e2e139f6f298cfbba829cc3c29db3c891
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
import { createRouter, createWebHistory } from 'vue-router'
import { get } from '@/utils/request.js'
 
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: '主页',
      component: () => import('@/views/HomeView.vue'),
      meta: {
        keepAlive: true // 设置keepAlive,让此路由页面被缓存
      },
    },
    {
      path: '/login',
      name: '登录',
      component: () => import('@/views/login/LoginView.vue'),
    },
 
    // {
    //   path: '/system/menu',
    //   name: '菜单管理',
    //   component: () => import('@/views/system/menu/index.vue'),
    //   meta: {
    //     keepAlive: true // 设置keepAlive,让此路由页面被缓存
    //   },
    // },
    // {
    //   path: '/system/userLogin',
    //   name: '登录日志',
    //   component: () => import('@/views/system/userLogin/index.vue'),
    //   meta: {
    //     keepAlive: true // 设置keepAlive,让此路由页面被缓存
    //   },
    // },
    // {
    //   path: '/system/user',
    //   name: '用户管理',
    //   component: () => import('@/views/system/user/index.vue'),
    //   meta: {
    //     keepAlive: true // 设置keepAlive,让此路由页面被缓存
    //   },
    // },
    // {
    //   path: '/system/host',
    //   name: '机构管理',
    //   component: () => import('@/views/system/host/index.vue'),
    //   meta: {
    //     keepAlive: true // 设置keepAlive,让此路由页面被缓存
    //   },
    // },
  ]
})
 
export const initRouter = async () => {
  const modules = import.meta.glob('/src/views/**/index.vue');
  const resp = await get('/api/auth/router', {});
  let result = resp.data;
  if(result.code != 200) {
    return null;
  }
  let data = result.data;
  data.forEach((item) => {
    const module = modules[`/src/views${item.route}/index.vue`];
    if (module) {
      const itemRouter = {
        path: item.route,
        name: item.name,
        component: module,
        meta: {
          keepAlive: true // 设置keepAlive,让此路由页面被缓存
        }
      }
      router.addRoute(itemRouter)
    }
  })
}
 
export default router