tj
2025-06-05 bba272999cc546f65781bf3d20245a3f819af67f
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import Utils from '@/lin/util/util'
import adminConfig from './admin'
import bookConfig from './book' // 引入图书管理路由文件
import pluginsConfig from './plugin'
import sysDictConfig from './sys-dict'
import emailSettingConfig from './email-setting'
import companyConfig from './company'
import diaryConfig from './project-work-diary'
import projectConfig from './project'
import supplierConfig from './supplier'
import todoConfig from './my-todo-list'
import reportConfig from './report'
 
// eslint-disable-next-line import/no-mutable-exports
let homeRouter = [
  {
    title: '首页',
    type: 'view',
    name: Symbol('about'),
    route: '/about',
    filePath: 'view/about/about.vue',
    inNav: true,
    icon: 'iconfont icon-iconset0103',
    isElementIcon: false,
    order: 1,
  },
  {
    title: '日历',
    type: 'view',
    name: Symbol('calendar'),
    route: '/calendar',
    filePath: 'view/calendar/calendar-list.vue',
    inNav: true,
    icon: 'iconfont icon-iconset0103',
    isElementIcon: false,
    order: 1,
  },
  {
    title: '项目看板',
    type: 'view',
    name: Symbol('projectBoard'),
    route: '/project/board',
    filePath: 'view/project-board/project-board-list.vue',
    inNav: true,
    icon: 'iconfont icon-iconset0103',
    isElementIcon: false,
    order: 1,
  },
  // {
  //   title: '统计',
  //   type: 'view',
  //   name: Symbol('statistics'),
  //   route: '/statistics',
  //   filePath: 'view/statistics/statistics.vue',
  //   inNav: true,
  //   icon: 'iconfont icon-iconset0103',
  //   isElementIcon: false,
  //   order: 1,
  // },
 
  {
    title: '日志管理',
    type: 'view',
    name: Symbol('log'),
    route: '/log',
    filePath: 'view/log/log.vue',
    inNav: true,
    icon: 'iconfont icon-rizhiguanli',
    isElementIcon: false,
    order: 2,
    permission: ['查询所有日志'],
  },
  {
    title: '个人中心',
    type: 'view',
    name: Symbol('center'),
    route: '/center',
    filePath: 'view/center/center.vue',
    inNav: false,
    icon: 'iconfont icon-rizhiguanli',
    isElementIcon: false,
  },
  {
    title: '404',
    type: 'view',
    name: Symbol('404'),
    route: '/404',
    filePath: 'view/error-page/404.vue',
    inNav: false,
    icon: 'iconfont icon-rizhiguanli',
    isElementIcon: false,
  },
  // bookConfig,
  sysDictConfig,
  // emailSettingConfig,
  companyConfig,
  projectConfig,
  supplierConfig,
  diaryConfig,
  todoConfig,
  adminConfig,
  reportConfig,
]
 
// 接入插件
const plugins = [...pluginsConfig]
filterPlugin(homeRouter)
// homeRouter = homeRouter.concat(plugins)
 
// 处理顺序
homeRouter = Utils.sortByOrder(homeRouter)
deepReduceName(homeRouter)
 
export default homeRouter
 
/**
 * 筛除已经被添加的插件
 */
function filterPlugin(data) {
  if (plugins.length === 0) {
    return
  }
  if (Array.isArray(data)) {
    data.forEach(item => {
      filterPlugin(item)
    })
  } else {
    const findResult = plugins.findIndex(item => data === item)
    if (findResult >= 0) {
      plugins.splice(findResult, 1)
    }
    if (data.children) {
      filterPlugin(data.children)
    }
  }
}
 
/**
 * 使用 Symbol 处理 name 字段, 保证唯一性
 */
function deepReduceName(target) {
  if (Array.isArray(target)) {
    target.forEach(item => {
      if (typeof item !== 'object') {
        return
      }
      deepReduceName(item)
    })
    return
  }
  if (typeof target === 'object') {
    if (typeof target.name !== 'symbol') {
      target.name = target.name || Utils.getRandomStr()
      target.name = Symbol(target.name)
    }
 
    if (Array.isArray(target.children)) {
      target.children.forEach(item => {
        if (typeof item !== 'object') {
          return
        }
        deepReduceName(item)
      })
    }
  }
}