Skip to content

Instantly share code, notes, and snippets.

@xsthunder
Created June 14, 2019 13:41
Show Gist options
  • Save xsthunder/7878665589082f5c74d60b03d1e6586a to your computer and use it in GitHub Desktop.
Save xsthunder/7878665589082f5c74d60b03d1e6586a to your computer and use it in GitHub Desktop.
/**
* recursively resolve children if exits
* obj = {
* name,
* icon,
* } ->{
* ...obj,
* meta:{title:name, icon:icon}
* }
* @param Object obj
*/
const parseSimedRouteConfigObj = (obj)=>{
const {
icon,
invisible,
} = obj
let {
children,
path,
name,
redirect,
} = obj
const title = name
path = `/simed${path}`
name = `simed_${name}`
if(redirect)redirect = `/simed${redirect}`
if(children){
children = children.map(parseSimedRouteConfigObj)
}
const nxt = {
...obj,
hidden:invisible,
name,
path,
children,
meta:{title, icon},
redirect,
}
return nxt
}
/**
*
* @param array routes
*/
const getSimedRouteConfigArray = (
simedRoutes
) => {
const frontPage = simedRoutes.filter(o=>o.name==='首页')[0]
let children = frontPage.children;
children = children.map(parseSimedRouteConfigObj)
return children
}
export default {
parseSimedRouteConfigObj,
getSimedRouteConfigArray,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment