chore: detail optimization

This commit is contained in:
vben
2020-10-14 21:08:07 +08:00
parent 7437896034
commit 31e2715e67
27 changed files with 304 additions and 93 deletions

View File

@@ -4,7 +4,6 @@ import type { MenuModule, Menu, AppRouteRecordRaw } from '/@/router/types';
import { findPath, forEach, treeMap, treeToList } from './treeHelper';
import { cloneDeep } from 'lodash-es';
//
export function getAllParentPath(treeData: any[], path: string) {
const menuList = findPath(treeData, (n) => n.path === path) as Menu[];
return (menuList || []).map((item) => item.path);
@@ -14,6 +13,7 @@ export function flatMenus(menus: Menu[]) {
return treeToList(menus);
}
// 拼接父级路径
function joinParentPath(list: any, node: any) {
let allPaths = getAllParentPath(list, node.path);
@@ -26,7 +26,6 @@ function joinParentPath(list: any, node: any) {
parentPath += /^\//.test(p) ? p : `/${p}`;
});
}
node.path = `${parentPath}${/^\//.test(node.path) ? node.path : `/${node.path}`}`.replace(
/\/\//g,
'/'
@@ -34,6 +33,7 @@ function joinParentPath(list: any, node: any) {
return node;
}
// 解析菜单模块
export function transformMenuModule(menuModule: MenuModule): Menu {
const { menu } = menuModule;

View File

@@ -1,11 +1,23 @@
import type { AppRouteModule, AppRouteRecordRaw } from '/@/router/types';
import type { RouteRecordRaw } from 'vue-router';
import type { RouteLocationNormalized, RouteRecordRaw } from 'vue-router';
import { appStore } from '/@/store/modules/app';
import { tabStore } from '/@/store/modules/tab';
import { createRouter, createWebHashHistory } from 'vue-router';
import { toRaw } from 'vue';
import { PAGE_LAYOUT_COMPONENT } from '/@/router/constant';
let currentTo: RouteLocationNormalized | null = null;
export function getCurrentTo() {
return currentTo;
}
export function setCurrentTo(to: RouteLocationNormalized) {
currentTo = to;
}
// 转化路由模块
// 将多级转成2层。keepAlive问题
export function genRouteModule(moduleList: AppRouteModule[]) {
const ret: AppRouteRecordRaw[] = [];
for (const routeMod of moduleList) {
@@ -27,6 +39,7 @@ export function genRouteModule(moduleList: AppRouteModule[]) {
return ret as RouteRecordRaw[];
}
// 动态引入
function asyncImportRoute(routes: AppRouteRecordRaw[]) {
routes.forEach((item) => {
const { component, children } = item;
@@ -37,6 +50,7 @@ function asyncImportRoute(routes: AppRouteRecordRaw[]) {
});
}
// 将后台对象转成路由对象
export function transformObjToRoute(routeList: AppRouteModule[]) {
routeList.forEach((route) => {
asyncImportRoute(route.routes);
@@ -48,6 +62,7 @@ export function transformObjToRoute(routeList: AppRouteModule[]) {
return routeList;
}
//
export function getIsOpenTab(toPath: string) {
const { openKeepAlive, multiTabsSetting: { show } = {} } = appStore.getProjectConfig;
@@ -57,3 +72,13 @@ export function getIsOpenTab(toPath: string) {
}
return false;
}
export function getParams(data: any = {}) {
const { params = {} } = data;
let ret = '';
Object.keys(params).forEach((key) => {
const p = params[key];
ret += `/${p}`;
});
return ret;
}