顶部导航样式调整

main
yupeng 1 month ago
parent d8c754d3da
commit 648ead93b1

@ -1,9 +1,8 @@
import React, { useState, useEffect } from 'react';
import { Breadcrumb } from 'antd';
import { CloseOutlined } from '@ant-design/icons';
import { history, useLocation, matchRoutes } from '@umijs/max';
import { CloseCircleOutlined } from '@ant-design/icons';
import { history, useLocation } from '@umijs/max';
import './breadcrumb.less';
import routes from '../../../config/routes';
const CustomBreadcrumb = () => {
// sessionStorageVue
@ -15,6 +14,24 @@ const CustomBreadcrumb = () => {
const location = useLocation();
// window.dynamicRoute
const findMatchedRoute = (routes, pathname) => {
for (const route of routes) {
//
if (route.key === pathname) {
return route;
}
//
if (route.children && route.children.length > 0) {
const matchedChild = findMatchedRoute(route.children, pathname);
if (matchedChild) {
return matchedChild;
}
}
}
return null;
};
//
const getCurrentRoute = () => {
const pathname = location.pathname || '/';
@ -22,23 +39,22 @@ const CustomBreadcrumb = () => {
console.log('当前路径:', pathname);
// 使matchRoutes
const matchedRoutes = matchRoutes(routes, pathname);
console.log('匹配的路由:', matchedRoutes);
//
if (matchedRoutes && matchedRoutes.length > 0) {
const matchedRoute = matchedRoutes[matchedRoutes.length - 1]; //
const routeConfig = matchedRoute.route;
// 使window.dynamicRoute
let matchedRoute = null;
if (window.dynamicRoute && Array.isArray(window.dynamicRoute)) {
matchedRoute = findMatchedRoute(window.dynamicRoute, pathname);
}
console.log('匹配的路由配置:', routeConfig);
console.log('匹配的路由:', matchedRoute);
// 使routeConfig.name
const routeTitle = routeConfig.name || '未知页面';
//
if (matchedRoute) {
// 使route.labelroute.key
const routeTitle = matchedRoute.label || '未知页面';
const routeKey = matchedRoute.key || pathname;
return {
name: routeConfig.name || pathname.replace(/\//g, '_').slice(1) || 'home',
name: routeKey.replace(/\//g, '_').slice(1) || 'home',
path: pathname,
href,
fullPath: href,
@ -49,18 +65,37 @@ const CustomBreadcrumb = () => {
};
}
// 使matchRoutes
const pathSegments = pathname.split('/').filter(Boolean);
const lastSegment = pathSegments[pathSegments.length - 1] || 'home';
// window.dynamicRoute使
// /
const parts = pathname.split('/').filter(Boolean);
//
//
if (parts.length === 0) {
return {
name: lastSegment,
name: 'home',
path: pathname,
href,
fullPath: href,
meta: {
title: lastSegment === 'home' ? '首页' : lastSegment,
title: '首页',
affix: true
}
};
}
//
const lastPart = parts[parts.length - 1];
// 使
const routeTitle = lastPart || '未知页面';
return {
name: lastPart.replace(/\//g, '_') || 'home',
path: pathname,
href,
fullPath: href,
meta: {
title: routeTitle,
affix: pathname === '/'
}
};
@ -214,8 +249,8 @@ const CustomBreadcrumb = () => {
className={`breadcrumb-item ${item.name === currentRouterName ? 'breadcrumb-item-active' : ''}`}
>
<span className="breadcrumb-item-content">
<span className="breadcrumb-item-text">{item.title}</span>
<CloseOutlined
<span className={`breadcrumb-item-text ${item.name === currentRouterName ? 'breadcrumb-item-text-active' : ''}`}>{item.title}</span>
<CloseCircleOutlined
className="breadcrumb-close-icon"
onClick={(e) => {
e.stopPropagation();

@ -47,9 +47,10 @@
.breadcrumb-item {
height: 32px;
padding: 0 12px;
border-radius: 16px;
background-color: #fff;
border: 1px solid #E8E8E8;
border-radius: 8px;
// 使用rgba格式设置带透明度的背景色最后一个参数0.13表示13%的透明度
background-color: rgba(186, 186, 186, 0.13);
// border: 1px solid #E8E8E8;
margin-right: 8px;
display: flex;
align-items: center;
@ -91,8 +92,8 @@
// 面包屑项选中状态样式
.breadcrumb-item-active {
background-color: #ECF2FF;
border-color: #0056FF;
background-color: rgba(94, 121, 246, 0.13);
// border-color: #0056FF;
.ant-breadcrumb-link {
color: #0056FF !important;
@ -100,6 +101,12 @@
}
}
// 面包屑文本选中状态样式 - 对应第252行代码中的条件样式
.breadcrumb-item-text-active {
color: #0056FF !important;
font-weight: 500;
}
// 面包屑项内容容器
.breadcrumb-item-content {
display: flex;
@ -112,17 +119,22 @@
// 面包屑项文本样式
.breadcrumb-item-text {
font-size: 14px;
font-weight: 500;
font-size: 16px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
flex: 1;
.breadcrumb-item-text-active {
color: #0056FF !important;
}
}
// 关闭图标样式
.breadcrumb-close-icon {
font-size: 14px;
color: #7D9CD8;
// color: #7D9CD8;
margin-left: 8px;
display: flex;
align-items: center;

Loading…
Cancel
Save