💪 optimize: 优化面包屑代码

This commit is contained in:
wangsongsole 2024-01-26 16:25:40 +08:00
parent 2034bb4525
commit 7c17278cd8
1 changed files with 45 additions and 39 deletions

View File

@ -1,9 +1,9 @@
import React from "react" import React from "react"
import "./main.less"
import { Pop } from "zent"
import MouseMenu from "../mouseMenu/main.js"
import Bus from "../../assets/eventBus.js"
import { Link } from "react-router-dom" import { Link } from "react-router-dom"
import { Pop } from "zent"
import Bus from "../../assets/eventBus.js"
import MouseMenu from "../mouseMenu/main.js"
import "./main.less"
export default class topNav extends React.Component { export default class topNav extends React.Component {
constructor(props) { constructor(props) {
super(props) super(props)
@ -86,43 +86,49 @@ export default class topNav extends React.Component {
let breaknav = JSON.parse(sessionStorage.getItem("breaknav")) let breaknav = JSON.parse(sessionStorage.getItem("breaknav"))
let urlHref = window.location.href.replace(/^\/|\/$/g, "") let urlHref = window.location.href.replace(/^\/|\/$/g, "")
const pathname = urlHref.lastIndexOf("/") const pathname = urlHref.lastIndexOf("/")
const pathnamestr = urlHref.substr(pathname) const pathNameString = urlHref.substr(pathname)
let breakflag = const breakFlagRoutes = [
pathnamestr.includes("add") || "add",
pathnamestr.includes("aid") || "aid",
pathnamestr.includes("exchangecode-exchangecodeAdd") || "exchangecode-exchangecodeAdd",
pathnamestr.includes("distributor-edit") || "distributor-edit",
pathnamestr.includes("key-list") || "key-list",
pathnamestr.includes("key-detail") || "key-detail",
pathnamestr.includes("key-edit") || "key-edit",
pathnamestr.includes("key-addEdit") || "key-addEdit",
pathnamestr.includes("plan-edit") || "plan-edit",
pathnamestr.includes("product-edit") || "product-edit",
pathnamestr.includes("distributor-merchant") || "distributor-merchant",
pathnamestr.includes("callback-message") || "callback-message",
pathnamestr.includes("coupon-commodity") "coupon-commodity"
let sedcbreakflag = pathnamestr.includes("plan-create") ]
let planbreakflag = pathnamestr.includes("mytempMould") const backShowRoutes = [
let editbreakflag = pathnamestr.includes("edittemplate") "account-add",
let backshow = "role-add",
pathnamestr.includes("account-add") || "distributor-add",
pathnamestr.includes("role-add") || "subaccount-add",
pathnamestr.includes("distributor-add") || "plan-edit",
pathnamestr.includes("subaccount-add") || "key-list",
pathnamestr.includes("plan-edit") || "exchange-addcommodity"
pathnamestr.includes("key-list") || ]
pathnamestr.includes("exchange-addcommodity") const breakChangeRoutes = [
let breakchange = "exchangecode-add",
pathnamestr.includes("exchangecode-add") || "key-edit",
pathnamestr.includes("key-edit") || "key-addEdit",
pathnamestr.includes("key-addEdit") || "key-detail",
pathnamestr.includes("key-detail") || "product-edit",
pathnamestr.includes("product-edit") || "plan-edit"
pathnamestr.includes("plan-edit") ]
let breakflag = breakFlagRoutes.some((keyword) => pathNameString.includes(keyword))
let backshow = backShowRoutes.some((keyword) => pathNameString.includes(keyword))
let breakchange = breakChangeRoutes.some((keyword) => pathNameString.includes(keyword))
let sedcbreakflag = pathNameString.includes("plan-create")
let planbreakflag = pathNameString.includes("mytempMould")
let editbreakflag = pathNameString.includes("edittemplate")
if (breakchange) { if (breakchange) {
breaknav = JSON.parse(sessionStorage.getItem("breakchangenav")) breaknav = JSON.parse(sessionStorage.getItem("breakchangenav"))
} }
if (pathnamestr.includes("aid")) { if (pathNameString.includes("aid")) {
breaknav = JSON.parse(sessionStorage.getItem("subbreaknav")) breaknav = JSON.parse(sessionStorage.getItem("subbreaknav"))
} }
let accPath = null let accPath = null
@ -186,7 +192,7 @@ export default class topNav extends React.Component {
to={item.router} to={item.router}
onClick={() => this.btnfn(item)} onClick={() => this.btnfn(item)}
className={ className={
item.router.includes(pathnamestr) && item.router.includes(pathNameString) &&
this.state.menulinklist.filter((it) => it.level == 5).length > 1 this.state.menulinklist.filter((it) => it.level == 5).length > 1
? "menuactive" ? "menuactive"
: "" : ""