SHARE
TWEET

Untitled

a guest Jun 26th, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * recursively resolve children if exits
  3.  * obj = {
  4.  *  name,
  5.  *  icon,
  6.  * } ->{
  7.  *  ...obj,
  8.  *  meta:{title:name, icon:icon}
  9.  * }
  10.  * @param Object obj
  11.  */
  12.  
  13. const parseSimedRouteConfigObj = (obj)=>{
  14.     const {
  15.         icon,
  16.         invisible,
  17.     } = obj
  18.     let {
  19.         children,
  20.         path,
  21.         name,
  22.         redirect,
  23.     } = obj
  24.     const title = name
  25.     path = `/simed${path}`
  26.     name = `simed_${name}`
  27.     if(redirect)redirect = `/simed${redirect}`
  28.     if(children){
  29.         children = children.map(parseSimedRouteConfigObj)
  30.     }
  31.     const nxt = {
  32.         ...obj,
  33.         hidden:invisible,
  34.         name,
  35.         path,
  36.         children,
  37.         meta:{title, icon},
  38.         redirect,
  39.     }
  40.     return nxt
  41. }
  42.  
  43. /**
  44.  *
  45.  * @param array routes
  46.  */
  47. const getSimedRouteConfigArray = (
  48.     simedRoutes
  49. ) => {
  50.    const frontPage = simedRoutes.filter(o=>o.name==='首页')[0]
  51.    let children = frontPage.children;
  52.    children = children.map(parseSimedRouteConfigObj)
  53.    return children
  54. }
  55. export default {
  56.     parseSimedRouteConfigObj,
  57.     getSimedRouteConfigArray,
  58. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top