refactor(permission): 优化面包屑控制逻辑
This commit is contained in:
@@ -37,9 +37,11 @@ export const usePermisstionStroe = defineStore('permisstion', () => {
|
|||||||
if (res.code === 1000) {
|
if (res.code === 1000) {
|
||||||
const sRouter = JSON.parse(JSON.stringify(res.data))
|
const sRouter = JSON.parse(JSON.stringify(res.data))
|
||||||
const mData = JSON.parse(JSON.stringify(res.data))
|
const mData = JSON.parse(JSON.stringify(res.data))
|
||||||
// console.log(JSON.parse(JSON.stringify(sRouter)), 'sRouter');
|
|
||||||
const firstFormat = setRouterLevel(JSON.parse(JSON.stringify(sRouter)))
|
const firstFormat = setRouterLevel(JSON.parse(JSON.stringify(sRouter)))
|
||||||
|
|
||||||
|
console.log(firstFormat, 'firstFormat');
|
||||||
asyncRouters.value = formatAsyncRouters(JSON.parse(JSON.stringify(firstFormat)))
|
asyncRouters.value = formatAsyncRouters(JSON.parse(JSON.stringify(firstFormat)))
|
||||||
|
console.log('asyncRouters.value',firstFormat);
|
||||||
menuList.value = [...menuList.value, ...generateMenu(mData)]
|
menuList.value = [...menuList.value, ...generateMenu(mData)]
|
||||||
addAsyncRouters(asyncRouters.value)
|
addAsyncRouters(asyncRouters.value)
|
||||||
isLoadRoutes.value = false
|
isLoadRoutes.value = false
|
||||||
@@ -52,16 +54,23 @@ export const usePermisstionStroe = defineStore('permisstion', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const setRouterLevel = (routers) => {
|
const setRouterLevel = (routers) => {
|
||||||
|
|
||||||
return routers.filter(item=>{
|
return routers.filter(item=>{
|
||||||
if(item.component === 'Layout') {
|
if(item.component === 'Layout') {
|
||||||
if(item.children) {
|
if(item.children) {
|
||||||
|
// console.log("🚀 ~ file: item.children ", item.children )
|
||||||
item.children.forEach(v=>{
|
item.children.forEach(v=>{
|
||||||
if(v.children) {
|
if(v.children) {
|
||||||
slRouters.value = [...toRaw(slRouters.value), ...v.children]
|
// console.log("🚀 ~ file:item.children",item.children)
|
||||||
delete v.children
|
// console.log("🚀 ~ file: v.children ", v.children )
|
||||||
|
// slRouters.value = [ ...toRaw(v.children)]
|
||||||
|
// delete v.children
|
||||||
|
// slRouters.value = [ ...v.children]
|
||||||
|
// return v.children
|
||||||
|
item.children = [...item.children,...v.children]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
item.children = [...item.children, ...toRaw(slRouters.value)]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
@@ -81,6 +90,7 @@ export const usePermisstionStroe = defineStore('permisstion', () => {
|
|||||||
}
|
}
|
||||||
if (route.children !== null && route.children && route.children.length !== 0) {
|
if (route.children !== null && route.children && route.children.length !== 0) {
|
||||||
route.children = formatAsyncRouters(route.children)
|
route.children = formatAsyncRouters(route.children)
|
||||||
|
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
@@ -90,6 +100,8 @@ export const usePermisstionStroe = defineStore('permisstion', () => {
|
|||||||
routers.forEach(route => {
|
routers.forEach(route => {
|
||||||
router.addRoute(route)
|
router.addRoute(route)
|
||||||
})
|
})
|
||||||
|
console.log("🚀 ~ file: ", routers)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const generateMenu = (routes) => {
|
const generateMenu = (routes) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user