Created
June 14, 2019 13:41
-
-
Save xsthunder/7878665589082f5c74d60b03d1e6586a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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