import Layout from '@/vab/layouts';

export function handleMenu(asyncRouterMap) {
  // 遍历后台传来的路由字符串，转换为组件对象
  try {
    const accessedRouters = asyncRouterMap.filter(route => {
      var hidden = route.status == 0 ? false : true;
      var icon = route.icon;
      delete route.id;
      delete route.sort;
      delete route.status;
      if (route.component === '') {
        // Layout组件特殊处理
        route.component = Layout;
        if (route.path === '/') {
          route.redirect = '/index';
        }
        route.meta = {
          title: route.name,
          remixIcon: icon,
        };
      } else {
        const component = route.component;
        route.hidden = hidden;
        route.component = () => import('@/views' + component + '.vue');
        route.meta = {
          title: route.name,
          remixIcon: icon,
        };
      }
      if (route.children && route.children.length) {
        route.children = handleMenu(route.children);
      }
      return true;
    });
    return accessedRouters;
  } catch (e) {
    console.log(e);
  }
}
