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 b50f40eb
authored
Jul 17, 2021
by
xinla
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
面包屑404问题,路由递归优化、支持无限级路由
1 parent
86c72412
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 @
b50f40e
...
@@ -10,7 +10,11 @@
...
@@ -10,7 +10,11 @@
</el-breadcrumb-item>
</el-breadcrumb-item>
<el-breadcrumb-item
v-for=
"(item, index) in levelList"
:key=
"item.path"
>
<el-breadcrumb-item
v-for=
"(item, index) in levelList"
:key=
"item.path"
>
<span
<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"
class=
"no-redirect"
>
{{
item
.
meta
.
title
}}
</span
>
{{
item
.
meta
.
title
}}
</span
>
>
...
@@ -35,7 +39,7 @@ import pathToRegexp from 'path-to-regexp'
...
@@ -35,7 +39,7 @@ import pathToRegexp from 'path-to-regexp'
export
default
{
export
default
{
data
()
{
data
()
{
return
{
return
{
levelList
:
null
,
levelList
:
null
}
}
},
},
watch
:
{
watch
:
{
...
@@ -46,12 +50,12 @@ export default {
...
@@ -46,12 +50,12 @@ export default {
}
}
this
.
$store
.
state
.
app
.
busininessDesc
=
''
this
.
$store
.
state
.
app
.
busininessDesc
=
''
this
.
getBreadcrumb
()
this
.
getBreadcrumb
()
}
,
}
},
},
computed
:
{
computed
:
{
busininessDesc
()
{
busininessDesc
()
{
return
this
.
$store
.
state
.
app
.
busininessDesc
return
this
.
$store
.
state
.
app
.
busininessDesc
}
,
}
},
},
created
()
{
created
()
{
this
.
getBreadcrumb
()
this
.
getBreadcrumb
()
...
@@ -87,13 +91,15 @@ export default {
...
@@ -87,13 +91,15 @@ export default {
},
},
handleLink
(
item
)
{
handleLink
(
item
)
{
const
{
redirect
,
path
}
=
item
const
{
redirect
,
path
}
=
item
console
.
log
(
redirect
,
'redirect'
)
if
(
redirect
)
{
if
(
redirect
)
{
this
.
$router
.
push
(
redirect
)
this
.
$router
.
push
(
redirect
)
return
return
}
}
console
.
log
(
this
.
pathCompile
(
path
))
this
.
$router
.
push
(
this
.
pathCompile
(
path
))
this
.
$router
.
push
(
this
.
pathCompile
(
path
))
}
,
}
}
,
}
}
}
</
script
>
</
script
>
...
@@ -106,7 +112,7 @@ export default {
...
@@ -106,7 +112,7 @@ export default {
margin-left
:
8px
;
margin-left
:
8px
;
.no-redirect
{
.no-redirect
{
color
:
$
blue
;
color
:
#999
;
cursor
:
text
;
cursor
:
text
;
}
}
}
}
...
...
linkwe-ui/src/store/modules/permission.js
View file @
b50f40e
...
@@ -6,13 +6,13 @@ import View from '@/layout/components/View'
...
@@ -6,13 +6,13 @@ import View from '@/layout/components/View'
const
permission
=
{
const
permission
=
{
state
:
{
state
:
{
routes
:
[],
routes
:
[],
addRoutes
:
[]
,
addRoutes
:
[]
},
},
mutations
:
{
mutations
:
{
SET_ROUTES
:
(
state
,
routes
)
=>
{
SET_ROUTES
:
(
state
,
routes
)
=>
{
state
.
addRoutes
=
routes
state
.
addRoutes
=
routes
state
.
routes
=
constantRoutes
.
concat
(
routes
)
state
.
routes
=
constantRoutes
.
concat
(
routes
)
}
,
}
},
},
actions
:
{
actions
:
{
// 生成路由
// 生成路由
...
@@ -26,20 +26,22 @@ const permission = {
...
@@ -26,20 +26,22 @@ const permission = {
resolve
(
accessedRoutes
)
resolve
(
accessedRoutes
)
})
})
})
})
}
,
}
}
,
}
}
}
// 遍历后台传来的路由字符串,转换为组件对象
// 遍历后台传来的路由字符串,转换为组件对象
function
filterAsyncRouter
(
asyncRouterMap
,
level
)
{
let
level
=
0
return
asyncRouterMap
.
filter
((
route
)
=>
{
function
filterAsyncRouter
(
asyncRouterMap
)
{
level
++
let
res
=
asyncRouterMap
.
filter
((
route
)
=>
{
if
(
route
.
component
)
{
if
(
route
.
component
)
{
// Layout组件特殊处理
// Layout组件特殊处理
if
(
route
.
component
===
'Layout'
)
{
if
(
route
.
component
===
'Layout'
)
{
if
(
route
.
redirect
===
'noRedirect'
&&
route
.
children
.
length
)
{
if
(
route
.
redirect
===
'noRedirect'
&&
route
.
children
.
length
)
{
route
.
redirect
=
route
.
path
+
'/'
+
route
.
children
[
0
].
path
route
.
redirect
=
route
.
path
+
'/'
+
route
.
children
[
0
].
path
}
}
if
(
level
===
2
)
{
if
(
level
!=
1
)
{
route
.
component
=
View
route
.
component
=
View
}
else
{
}
else
{
route
.
component
=
Layout
route
.
component
=
Layout
...
@@ -49,10 +51,12 @@ function filterAsyncRouter(asyncRouterMap, level) {
...
@@ -49,10 +51,12 @@ function filterAsyncRouter(asyncRouterMap, level) {
}
}
}
}
if
(
route
.
children
!=
null
&&
route
.
children
&&
route
.
children
.
length
)
{
if
(
route
.
children
!=
null
&&
route
.
children
&&
route
.
children
.
length
)
{
route
.
children
=
filterAsyncRouter
(
route
.
children
,
2
)
route
.
children
=
filterAsyncRouter
(
route
.
children
)
}
}
return
true
return
true
})
})
level
--
return
res
}
}
export
const
loadView
=
(
view
)
=>
{
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