去除权限控制
当你要开发一个小系统,或一个完全不需要权限控制的,开放后台任意访问的管理面板。
在 src/store/modules/router.js
文件中找到 getRouterList
方法,并做如下调整。
js
import { defineStore } from 'pinia'
import { notFoundRoute } from '@/router/config'
import { formatRoutes, generateMenuList, generateRoutes, getFirstValidRoute } from '@/router/util'
import { findTree } from '@/utils'
import { config } from '@/config'
import router from '@/router'
import apis from '@/apis'
import routes from '@/router/routes'
const useRouterStore = defineStore('router', {
state: () => ({
routeList: [],
menuList: [],
indexRoute: null,
}),
getters: {},
actions: {
/**
* 获取路由列表
* @returns {Promise}
*/
getRouterList() {
return new Promise((resolve, reject) => {
;(async () => {
try {
const { code, data } = await apis.user.getAuthList().catch(() => {
throw new Error()
})
if (config('http.code.success') === code) {
const validRoutes = formatRoutes(routes, data)
const validRoutes = formatRoutes(routes, false)
const menuList = generateMenuList(validRoutes)
const routeList = [...generateRoutes(validRoutes), notFoundRoute]
const indexRoute = getFirstValidRoute(menuList)
routeList.forEach((route) => {
router.addRoute(route)
})
this.routeList = routeList
this.menuList = menuList
this.indexRoute = indexRoute
resolve()
}
} catch (error) {
reject()
}
})()
})
},
/**
* 设置徽标
* @param {string} name 名称
* @param {number} count 数量
*/
setBadge({ name, count } = {}) {
findTree(
this.menuList,
name,
(item) => {
item.meta.badge = count
},
{ key: 'name', children: 'children' }
)
},
},
})
export default useRouterStore
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
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