web.src.utils.common.ts Maven / Gradle / Ivy
/**
* @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;
}