|
@@ -8,7 +8,7 @@ import { getMenuList } from '@/api/system/menu'
|
|
|
const modules = import.meta.glob('@/views/**/*.vue')
|
|
|
export const Layout = () => import('@/layout/index.vue') // todo...
|
|
|
// export const Layout = () => import('@/layout/index_old.vue.vue')
|
|
|
-// export const Test = () => import('@/layout/test.vue')
|
|
|
+// export const RouteView = () => import('@/layout/RouteView.vue')
|
|
|
// export const Layout = () => import('@/layouts/index.vue')
|
|
|
|
|
|
// const hasPermission = (roles: string[], route: AppRouteRecordRaw) => {
|
|
@@ -35,7 +35,7 @@ export const filterAsyncRoutes = (routes: AppRouteRecordRaw[], roles: string[])
|
|
|
// console.warn(tmp.component, 'tmp.component')
|
|
|
// 特殊Layout 配置 标识
|
|
|
/*if (!tmp.component) {
|
|
|
- tmp.component = Test
|
|
|
+ tmp.component = RouteView
|
|
|
} else*/ if (!tmp.component || tmp.component === 'Layout') {
|
|
|
tmp.component = Layout
|
|
|
} else {
|
|
@@ -62,7 +62,8 @@ const getShowMenuList = (menuList: AppRouteRecordRaw[], parentPath = '') => {
|
|
|
return menuList.filter(item => {
|
|
|
// console.error(item, 'item')
|
|
|
item.meta = item.meta ? item.meta : {}
|
|
|
- item.meta.icon = item.meta.icon || 'Menu'
|
|
|
+ // 默认icon
|
|
|
+ item.meta.icon = item.meta.icon || 'menu'
|
|
|
// path全链 重组
|
|
|
item.path = /\/.*/.test(item.path) ? item.path : `${parentPath}/${item.path}`
|
|
|
if (!item.meta.hidden) {
|
|
@@ -72,6 +73,14 @@ const getShowMenuList = (menuList: AppRouteRecordRaw[], parentPath = '') => {
|
|
|
return false
|
|
|
})
|
|
|
}
|
|
|
+// 可展示的路由平铺
|
|
|
+const getMenuListFlat = (menuList: AppRouteRecordRaw[]) => {
|
|
|
+ const _menuList = JSON.parse(JSON.stringify(menuList))
|
|
|
+ return _menuList.flatMap((v: AppRouteRecordRaw) => {
|
|
|
+ const _children = v.children || []
|
|
|
+ return [v, ...getMenuListFlat(_children)]
|
|
|
+ })
|
|
|
+}
|
|
|
|
|
|
const usePermissionStore = defineStore({
|
|
|
id: 'permission',
|
|
@@ -82,7 +91,7 @@ const usePermissionStore = defineStore({
|
|
|
}),
|
|
|
getters: {
|
|
|
// 有效的 菜单列表
|
|
|
- showMenuList: state => getShowMenuList(JSON.parse(JSON.stringify([...constantMenuList, ...state.menuList])))
|
|
|
+ showMenuList: state => getShowMenuList(JSON.parse(JSON.stringify([...constantMenuList, ...state.menuList]))),
|
|
|
/*getShowMenuList([
|
|
|
...JSON.parse(JSON.stringify(state.menuList)),
|
|
|
// 测试
|
|
@@ -95,6 +104,10 @@ const usePermissionStore = defineStore({
|
|
|
}
|
|
|
])*/
|
|
|
// showMenuList: state => getShowMenuList(JSON.parse(JSON.stringify(state.routes)))
|
|
|
+ // 菜单权限列表 ==> 扁平化之后的一维数组菜单,主要用来添加动态路由
|
|
|
+ showMenuListFlat() {
|
|
|
+ return getMenuListFlat(this.showMenuList)
|
|
|
+ }
|
|
|
},
|
|
|
actions: {
|
|
|
setRoutes(menuList: AppRouteRecordRaw[]) {
|
|
@@ -119,8 +132,10 @@ const usePermissionStore = defineStore({
|
|
|
queryMenuList(roles: string[]) {
|
|
|
return getMenuList().then((data: any) => {
|
|
|
console.error(data, 'menuList')
|
|
|
- const menuList = filterAsyncRoutes(data!.menu.filter((v: any) => /\/.*/.test(v.path)), roles)
|
|
|
- console.warn(menuList, data, 'xxxxxxxxxxx')
|
|
|
+ const menuList = filterAsyncRoutes(
|
|
|
+ data!.menu.filter((v: any) => /\/.*/.test(v.path)),
|
|
|
+ roles
|
|
|
+ )
|
|
|
this.setRoutes(menuList)
|
|
|
return menuList
|
|
|
})
|