顶部导航样式调整

main
yupeng 1 month ago
parent d8c754d3da
commit 648ead93b1

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

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

Loading…
Cancel
Save