Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
江名洋
/
linkwe-scrm
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit f7a5f7c8
authored
Jul 17, 2021
by
xinla
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
面包屑404问题,路由递归优化、支持无限级路由
1 parent
aabca122
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
15 deletions
linkwe-ui/src/layout/components/Breadcrumb/index.vue
linkwe-ui/src/store/modules/permission.js
linkwe-ui/src/layout/components/Breadcrumb/index.vue
View file @
f7a5f7c
...
...
@@ -10,7 +10,11 @@
</el-breadcrumb-item>
<el-breadcrumb-item
v-for=
"(item, index) in levelList"
:key=
"item.path"
>
<span
v-if=
"item.redirect === 'noRedirect' || index == levelList.length - 1"
v-if=
"
item.redirect === 'noRedirect' ||
index == levelList.length - 1 ||
!/^\//gi.test(item.redirect)
"
class=
"no-redirect"
>
{{
item
.
meta
.
title
}}
</span
>
...
...
@@ -35,7 +39,7 @@ import pathToRegexp from 'path-to-regexp'
export
default
{
data
()
{
return
{
levelList
:
null
,
levelList
:
null
}
},
watch
:
{
...
...
@@ -46,12 +50,12 @@ export default {
}
this
.
$store
.
state
.
app
.
busininessDesc
=
''
this
.
getBreadcrumb
()
}
,
}
},
computed
:
{
busininessDesc
()
{
return
this
.
$store
.
state
.
app
.
busininessDesc
}
,
}
},
created
()
{
this
.
getBreadcrumb
()
...
...
@@ -87,13 +91,15 @@ export default {
},
handleLink
(
item
)
{
const
{
redirect
,
path
}
=
item
console
.
log
(
redirect
,
'redirect'
)
if
(
redirect
)
{
this
.
$router
.
push
(
redirect
)
return
}
console
.
log
(
this
.
pathCompile
(
path
))
this
.
$router
.
push
(
this
.
pathCompile
(
path
))
}
,
}
,
}
}
}
</
script
>
...
...
@@ -106,7 +112,7 @@ export default {
margin-left
:
8px
;
.no-redirect
{
color
:
$
blue
;
color
:
#999
;
cursor
:
text
;
}
}
...
...
linkwe-ui/src/store/modules/permission.js
View file @
f7a5f7c
...
...
@@ -6,13 +6,13 @@ import View from '@/layout/components/View'
const
permission
=
{
state
:
{
routes
:
[],
addRoutes
:
[]
,
addRoutes
:
[]
},
mutations
:
{
SET_ROUTES
:
(
state
,
routes
)
=>
{
state
.
addRoutes
=
routes
state
.
routes
=
constantRoutes
.
concat
(
routes
)
}
,
}
},
actions
:
{
// 生成路由
...
...
@@ -26,20 +26,22 @@ const permission = {
resolve
(
accessedRoutes
)
})
})
}
,
}
,
}
}
}
// 遍历后台传来的路由字符串,转换为组件对象
function
filterAsyncRouter
(
asyncRouterMap
,
level
)
{
return
asyncRouterMap
.
filter
((
route
)
=>
{
let
level
=
0
function
filterAsyncRouter
(
asyncRouterMap
)
{
level
++
let
res
=
asyncRouterMap
.
filter
((
route
)
=>
{
if
(
route
.
component
)
{
// Layout组件特殊处理
if
(
route
.
component
===
'Layout'
)
{
if
(
route
.
redirect
===
'noRedirect'
&&
route
.
children
.
length
)
{
route
.
redirect
=
route
.
path
+
'/'
+
route
.
children
[
0
].
path
}
if
(
level
===
2
)
{
if
(
level
!=
1
)
{
route
.
component
=
View
}
else
{
route
.
component
=
Layout
...
...
@@ -49,10 +51,12 @@ function filterAsyncRouter(asyncRouterMap, level) {
}
}
if
(
route
.
children
!=
null
&&
route
.
children
&&
route
.
children
.
length
)
{
route
.
children
=
filterAsyncRouter
(
route
.
children
,
2
)
route
.
children
=
filterAsyncRouter
(
route
.
children
)
}
return
true
})
level
--
return
res
}
export
const
loadView
=
(
view
)
=>
{
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment