quanyawei
2023-09-25 c4aedc3f07326068221ee1b957eee146808afbcb
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
import router from "@/route/router";
import MainLayout from '@/layout/main/MainLayout.vue';
import Vue from "vue";
import { get, post } from "@/util/request";
 
const organization = {
    path: 'organization',
    name: '/organization',
    component: () => import(/* webpackChunkName: "form" */ '@/views/system/organization.vue'),
    meta: {
        routerGuard: true,
        title: '组织管理',
    },
}
 
const usermanage = {
    path: 'users',
    name: '/users',
    component: () => import(/* webpackChunkName: "widgets" */ '@/views/usermanage/index.vue'),
    meta: {
        title: '账户管理',
        routerGuard: true,
    },
}
 
const logmanage = {
    path: '/systems/log',
    name: '/systems/log',
    component: () => import('@/views/systemset/logmanage.vue'),
    meta: {
        routerGuard: true,
        title: '日志管理'
    }
}
 
const dictionaryManage = {
    path: '/systems/Dictionary',
    name: '/systems/Dictionary',
    component: () => import('@/views/systemset/dictionaryManage.vue'),
    meta: {
        routerGuard: true,
        title: '字典管理'
    }
}
 
const role = {
    path: 'role',
    name: '/authority/role',
    component: () => import(/* webpackChunkName: "list" */ '@/views/list/Query.vue'),
    meta: {
        title: '角色配置',
        routerGuard: true
    },
}
 
 
const menu = {
    path: 'menu',
    name: '/authority/menu',
    component: () => import(/* webpackChunkName: "list" */ '@/views/list/Menu.vue'),
    meta: {
        title: '菜单配置',
        routerGuard: true,
    },
}
const unit = {
    path: 'unit',
    name: '/authority/unit',
    component: () => import(/* webpackChunkName: "list" */ '@/views/list/Unit.vue'),
    meta: {
        title: '系统管理',
        routerGuard: true
    },
}
 
const webMenu = {
    path: 'wMenu',
    name: '/wMenu/wMenu',
    component: () => import(/* webpackChunkName: "dashboard" */ '@/views/menu/webMenu.vue'),
    meta: {
        routerGuard: true,
        title: '前端菜单配置'
    },
}
 
const sensor = {
    path: 'sensor',
    name: '/sensor',
    component: () => import(/* webpackChunkName: "dashboard" */ '@/views/sensor/sensor.vue'),
    meta: {
        routerGuard: true,
        title: '传感器配置'
    },
}
 
const sensorBasic = {
    path: 'sensorBasic',
    name: '/sensor/sensorBasic',
    component: () => import(/* webpackChunkName: "dashboard" */ '@/views/list/sensorsBasic.vue'),
    meta: {
        routerGuard: true,
        title: '基本信息'
    },
}
 
const sensorChangeUnit = {
    path: 'sensorChangeUnit',
    name: '/sensor/sensorChangeUnit',
    component: () => import(/* webpackChunkName: "dashboard" */ '@/views/list/sensorChangeUnit.vue'),
    meta: {
        routerGuard: true,
        title: '单位转换'
    },
}
 
const basic = {
    path: 'basic',
    name: '/device/basic',
    component: () => import(/* webpackChunkName: "list" */ '@/views/list/devicesBasic.vue'),
    meta: {
        routerGuard: true,
        title: '设备配置'
    },
}
const road = {
    path: 'road',
    name: '/other/road',
    component: () => import(/* webpackChunkName: "list" */ '@/views/list/road.vue'),
    meta: {
        routerGuard: true,
        title: '路径规划'
    },
}
 
const specialDevice = {
    path: 'specialDevice',
    name: '/device/specialDevice',
    component: () => import(/* webpackChunkName: "list" */ '@/views/list/specialDevice.vue'),
    meta: {
        routerGuard: true,
        title: '特殊设备'
    },
}
 
const deviceVersion = {
    path: 'deviceVersion',
    name: '/device/deviceVersion',
    component: () => import(/* webpackChunkName: "list" */ '@/views/list/devicesVersion.vue'),
    meta: {
        routerGuard: true,
        title: '型号配置'
    },
}
 
const deviceMonitorPoint = {
    path: 'deviceMonitorPoint',
    name: '/device/deviceMonitorPoint',
    component: () => import(/* webpackChunkName: "list" */ '@/views/list/devicesMonitorPoint.vue'),
    meta: {
        routerGuard: true,
        title: '监测站点管理'
    },
}
const govMonitorPoint = {
    path: 'govMonitorPoint',
    name: '/device/govMonitorPoint',
    component: () => import(/* webpackChunkName: "list" */ '@/views/device/govMonitorPoint.vue'),
    meta: {
        routerGuard: true,
        title: '政府站点'
    },
}
const areaConfiguration = {
    path: 'areaConfiguration',
    name: '/device/areaConfiguration',
    component: () => import(/* webpackChunkName: "list" */ '@/views/device/areaConfiguration.vue'),
    meta: {
        routerGuard: true,
        title: '图形扩展区域配置'
    },
}
const routerMap = {
    organization: organization,
    users: usermanage,
    log: logmanage,
    dictionary: dictionaryManage,
    role: role,
    unit: unit,
    menuq: menu,
    wMenu: webMenu,
    sensor: sensor,
    sensorBasic: sensorBasic,
    sensorChangeUnit: sensorChangeUnit,
    basic: basic,
    road:road,
    deviceVersion: deviceVersion,
    deviceMonitorPoint: deviceMonitorPoint,
    specialDevice: specialDevice,
    govMonitorPoint: govMonitorPoint,
    areaConfiguration: areaConfiguration
}
 
 
function getMenus(token: any) {
    get('getAccountInfo', {}).then((res: any) => {
        if (res.data.code === -3) {
            Vue.prototype.$message.warning(res.data.message, 2)
            sessionStorage.clear()
            router.push('/passport/login')
        } else {
            sessionStorage.setItem('userName', res.data.data.userName)
            sessionStorage.setItem('menuData', JSON.stringify(res.data.data.menus))
            sessionStorage.setItem('router', JSON.stringify(router.options.routes))
            let rout = JSON.parse((sessionStorage.getItem('router')))
            if (rout.length === 3) {
                routerDynamic()
            } else {
                return
            }
        }
    })
}
 
function routerDynamic() {
    let menuData = []
    setTimeout(() => {
        menuData = JSON.parse((sessionStorage.getItem('menuData')))
        let rout = JSON.parse((sessionStorage.getItem('router')))
        const currentRoutes = router.options.routes
        if (menuData !== null) {
            menuData.forEach((element: any) => {
                element.meta = {
                        title: element.name,
                        icon: 'profile'
                    }
 
                    element.component = MainLayout
                    element.path = '/' + element.url
                    element.name = '/' + element.url
                    delete element.order
                    delete element.id
                    let child = []
                    if (element.children) {
                        delete element.url
                        child = element.children
                        element.redirect = element.children[0].url
                        delete element.children
                        element.children = []
                    } else {
                        element.redirect = element.url + '' + element.path
                        delete element.url
                        element.children = []
                    }
                    if (currentRoutes) {
                        currentRoutes.splice(currentRoutes.length, 0, element)
                    }
                    if (child.length > 0) {
                        child.forEach((c: any) => {
                            let path = c.url.substr(element.path.length, c.url.length)
                            let temp = routerMap[path]
                            if (temp) {
                                currentRoutes[currentRoutes.length - 1].children.push(temp)
                            }
                        })
                    } else {
                        let path = element.path.substr(1, element.path.length)
                        let temp = routerMap[path]
                        if (temp) {
                            currentRoutes[currentRoutes.length - 1].children.push(temp)
                        }
                    }
 
 
            })
            // const temp = {
            //     path: '*',
            //     redirect: '/notFound/404'
            // }
            // temp.meta =  {
            //     title: '404',
            // }
            // currentRoutes[currentRoutes.length - 1].children.push(temp)
        }
        router.addRoutes(currentRoutes)
    }, 400)
}
 
export default getMenus