perf: 同步完整版代码

This commit is contained in:
xiaoxian521
2022-04-18 11:15:46 +08:00
parent 736f1c27cd
commit 77049fdbd7
12 changed files with 527 additions and 393 deletions

View File

@@ -24,6 +24,7 @@ const {
toggleSideBar,
pureApp,
username,
avatarsStyle,
getDropdownItemStyle
} = useNav();
@@ -93,8 +94,8 @@ function translationEn() {
<!-- 退出登陆 -->
<el-dropdown trigger="click">
<span class="el-dropdown-link">
<img :src="avatars" />
<p>{{ username }}</p>
<img v-if="avatars" :src="avatars" :style="avatarsStyle" />
<p v-if="username">{{ username }}</p>
</span>
<template #dropdown>
<el-dropdown-menu class="logout">
@@ -169,7 +170,6 @@ function translationEn() {
}
.el-dropdown-link {
width: 100px;
height: 48px;
padding: 10px;
display: flex;

View File

@@ -30,6 +30,7 @@ const {
handleResize,
menuSelect,
username,
avatarsStyle,
getDropdownItemStyle
} = useNav();
@@ -46,6 +47,13 @@ watch(
}
);
watch(
() => route.path,
() => {
menuSelect(route.path, routers);
}
);
function translationCh() {
instance.locale = { locale: "zh" };
locale.value = "zh";
@@ -114,8 +122,8 @@ function translationEn() {
<!-- 退出登陆 -->
<el-dropdown trigger="click">
<span class="el-dropdown-link">
<img :src="avatars" />
<p>{{ username }}</p>
<img v-if="avatars" :src="avatars" :style="avatarsStyle" />
<p v-if="username">{{ username }}</p>
</span>
<template #dropdown>
<el-dropdown-menu class="logout">

View File

@@ -33,6 +33,7 @@ const {
resolvePath,
pureApp,
username,
avatarsStyle,
getDropdownItemStyle
} = useNav();
@@ -166,8 +167,8 @@ function translationEn() {
<!-- 退出登陆 -->
<el-dropdown trigger="click">
<span class="el-dropdown-link">
<img :src="avatars" />
<p>{{ username }}</p>
<img v-if="avatars" :src="avatars" :style="avatarsStyle" />
<p v-if="username">{{ username }}</p>
</span>
<template #dropdown>
<el-dropdown-menu class="logout">

View File

@@ -1,11 +1,11 @@
<script setup lang="ts">
import { ref, PropType, nextTick, computed, CSSProperties } from "vue";
import path from "path";
import { useNav } from "../../hooks/nav";
import { childrenType } from "../../types";
import { transformI18n } from "/@/plugins/i18n";
import { useAppStoreHook } from "/@/store/modules/app";
import { useRenderIcon } from "/@/components/ReIcon/src/hooks";
import { ref, PropType, nextTick, computed, CSSProperties } from "vue";
const { pureApp } = useNav();
const menuMode = ["vertical", "mix"].includes(pureApp.layout);

View File

@@ -51,6 +51,7 @@ watch(
() => route.path,
() => {
getSubMenuData(route.path);
menuSelect(route.path, routers);
}
);
</script>

View File

@@ -9,6 +9,8 @@ import { storageSession } from "/@/utils/storage";
import { useAppStoreHook } from "/@/store/modules/app";
import { useEpThemeStoreHook } from "/@/store/modules/epTheme";
const errorInfo = "当前路由配置不正确,请检查配置";
export function useNav() {
const pureApp = useAppStoreHook();
// 用户名
@@ -24,6 +26,10 @@ export function useNav() {
};
});
const avatarsStyle = computed(() => {
return username ? { marginRight: "10px" } : "";
});
const isCollapse = computed(() => {
return !pureApp.getSidebarStatus;
});
@@ -59,6 +65,7 @@ export function useNav() {
}
function resolvePath(route) {
if (!route.children) return console.error(errorInfo);
const httpReg = /^http(s?):\/\//;
const routeChildPath = route.children[0]?.path;
if (httpReg.test(routeChildPath)) {
@@ -77,6 +84,7 @@ export function useNav() {
}
// 找到当前路由的信息
function findCurrentRoute(indexPath: string, routes) {
if (!routes) return console.error(errorInfo);
return routes.map(item => {
if (item.path === indexPath) {
if (item.redirect) {
@@ -113,6 +121,7 @@ export function useNav() {
isCollapse,
pureApp,
username,
avatarsStyle,
getDropdownItemStyle
};
}

View File

@@ -1,7 +1,11 @@
import { createProdMockServer } from "vite-plugin-mock/es/createProdMockServer";
import asyncRoutesMock from "../mock/asyncRoutes";
export const mockModules = [...asyncRoutesMock];
const modules = import.meta.globEager("../mock/*.ts");
const mockModules = [];
Object.keys(modules).forEach(key => {
mockModules.push(...modules[key].default);
});
export function setupProdMockServer() {
createProdMockServer(mockModules);

View File

@@ -36,7 +36,12 @@
z-index: 99999 !important;
}
// 自定义popover的类名
/* 重置button中icon的margin */
.reset-margin [class*="el-icon"] + span {
margin-left: 2px !important;
}
/* 自定义popover的类名 */
.pure-popper {
padding: 0 !important;
}

View File

@@ -241,7 +241,6 @@
}
.el-dropdown-link {
width: 100px;
height: 48px;
padding: 10px;
display: flex;

View File

@@ -117,3 +117,59 @@ export function appendFieldByUniqueId(
}
return menuTree;
}
/**
* 构造树型结构数据
* @param {*} data 数据源
* @param {*} id id字段 默认 'id'
* @param {*} parentId 父节点字段 默认 'parentId'
* @param {*} children 孩子节点字段 默认 'children'
*/
export function handleTree(
data,
id?: string,
parentId?: string,
children?: string
) {
const config = {
id: id || "id",
parentId: parentId || "parentId",
childrenList: children || "children"
};
const childrenListMap = {};
const nodeIds = {};
const tree = [];
for (const d of data) {
const parentId = d[config.parentId];
if (childrenListMap[parentId] == null) {
childrenListMap[parentId] = [];
}
nodeIds[d[config.id]] = d;
childrenListMap[parentId].push(d);
}
for (const d of data) {
const parentId = d[config.parentId];
if (nodeIds[parentId] == null) {
tree.push(d);
}
}
for (const t of tree) {
adaptToChildrenList(t);
}
function adaptToChildrenList(o) {
if (childrenListMap[o[config.id]] !== null) {
o[config.childrenList] = childrenListMap[o[config.id]];
}
if (o[config.childrenList]) {
for (const c of o[config.childrenList]) {
adaptToChildrenList(c);
}
}
}
return tree;
}