All Downloads are FREE. Search and download functionalities are using the official Maven repository.

web.src.utils.common.ts Maven / Gradle / Ivy

There is a newer version: 2.0.4
Show newest version
/**
 * @name: 通用方法
 * @author: itmobai
 * @date: 2023-03-14 16:55
 * @description:通用方法
 * @update: 2023-03-14 16:55
 */
/**
 * 根据列表值获取名字
 * @param list
 * @param value
 */
export const getLabelByValue = (list: {label: string, value: string | number}[], value: string | number) => {
  if(!list || list.length == 0 || value === null || value === undefined || value === "") {
    return ""
  }
  return list.find(item => item.value === value)!["label"]
}

/**
 * 将后端返回的带单转换成可用的路由
 * @param routeList 后端路由数据
 * @returns
 */
export const generateRoutes = (routeList: any) => {
  const routes: any = [];
  routeList.forEach((item: any) => {
    const route: any = {};
    route.path = item.path;
    route.name = item.name;
    if (item.pid === 0) {
      route.component =() => import('@/layout/index.vue');
    } else {
      route.component =() => import(`@/views${item.component}.vue`);
    }
    route.meta = {
      title: item.meta.title,
      icon: item.meta.icon
    };
    if (item.children) {
      route.children = generateRoutes(item.children);
    }
    routes.push(route);
  });
  return routes;
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy