Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
c1924d56
authored
Oct 27, 2024
by
芋道源码
Committed by
Gitee
Oct 27, 2024
Browse files
Options
Browse Files
Download
Plain Diff
!570 【新增】TagsView 支持多个 path 相同但 fullPath 不相同情况。
Merge pull request !570 from 半栈幼儿员/hotfix/tagsView
parents
b4139676
a401d8ed
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
19 deletions
+35
-19
src/layout/components/TagsView/src/TagsView.vue
+6
-7
src/store/modules/tagsView.ts
+26
-12
types/router.d.ts
+3
-0
No files found.
src/layout/components/TagsView/src/TagsView.vue
View file @
c1924d56
...
...
@@ -127,12 +127,8 @@ const toLastView = () => {
const
moveToCurrentTag
=
async
()
=>
{
await
nextTick
()
for
(
const
v
of
unref
(
visitedViews
))
{
if
(
v
.
fullPath
===
unref
(
currentRoute
).
p
ath
)
{
if
(
v
.
fullPath
===
unref
(
currentRoute
).
fullP
ath
)
{
moveToTarget
(
v
)
if
(
v
.
fullPath
!==
unref
(
currentRoute
).
fullPath
)
{
tagsViewStore
.
updateVisitedView
(
unref
(
currentRoute
))
}
break
}
}
...
...
@@ -207,7 +203,7 @@ const moveToTarget = (currentTag: RouteLocationNormalizedLoaded) => {
// 是否是当前tag
const
isActive
=
(
route
:
RouteLocationNormalizedLoaded
):
boolean
=>
{
return
route
.
path
===
unref
(
currentRoute
).
p
ath
return
route
.
fullPath
===
unref
(
currentRoute
).
fullP
ath
}
// 所有右键菜单组件的元素
...
...
@@ -373,7 +369,10 @@ watch(
:size=
"12"
class=
"mr-5px"
/>
{{
t
(
item
?.
meta
?.
title
as
string
)
}}
{{
t
(
item
?.
meta
?.
title
as
string
)
+
(
item
?.
meta
?.
titleSuffix
?
` (${item?.meta?.titleSuffix
}
)`
:
''
)
}}
<
Icon
:
class
=
"
`${prefixCls
}
__item--close`"
:size="
12
"
...
...
src/store/modules/tagsView.ts
View file @
c1924d56
...
...
@@ -31,13 +31,27 @@ export const useTagsViewStore = defineStore('tagsView', {
},
// 新增tag
addVisitedView
(
view
:
RouteLocationNormalizedLoaded
)
{
if
(
this
.
visitedViews
.
some
((
v
)
=>
v
.
path
===
view
.
p
ath
))
return
if
(
this
.
visitedViews
.
some
((
v
)
=>
v
.
fullPath
===
view
.
fullP
ath
))
return
if
(
view
.
meta
?.
noTagsView
)
return
this
.
visitedViews
.
push
(
Object
.
assign
({},
view
,
{
title
:
view
.
meta
?.
title
||
'no-name'
const
visitedView
=
Object
.
assign
({},
view
,
{
title
:
view
.
meta
?.
title
||
'no-name'
})
if
(
visitedView
.
meta
)
{
const
titleSuffixList
:
string
[]
=
[]
this
.
visitedViews
.
forEach
((
v
)
=>
{
if
(
v
.
path
===
visitedView
.
path
&&
v
.
meta
?.
title
===
visitedView
.
meta
?.
title
)
{
titleSuffixList
.
push
(
v
.
meta
?.
titleSuffix
||
'1'
)
}
})
)
if
(
titleSuffixList
.
length
)
{
let
titleSuffix
=
1
while
(
titleSuffixList
.
includes
(
`
${
titleSuffix
}
`
))
{
titleSuffix
+=
1
}
visitedView
.
meta
.
titleSuffix
=
titleSuffix
===
1
?
undefined
:
`
${
titleSuffix
}
`
}
}
this
.
visitedViews
.
push
(
visitedView
)
},
// 新增缓存
addCachedView
()
{
...
...
@@ -63,7 +77,7 @@ export const useTagsViewStore = defineStore('tagsView', {
// 删除tag
delVisitedView
(
view
:
RouteLocationNormalizedLoaded
)
{
for
(
const
[
i
,
v
]
of
this
.
visitedViews
.
entries
())
{
if
(
v
.
path
===
view
.
p
ath
)
{
if
(
v
.
fullPath
===
view
.
fullP
ath
)
{
this
.
visitedViews
.
splice
(
i
,
1
)
break
}
...
...
@@ -95,18 +109,18 @@ export const useTagsViewStore = defineStore('tagsView', {
// 删除其他tag
delOthersVisitedViews
(
view
:
RouteLocationNormalizedLoaded
)
{
this
.
visitedViews
=
this
.
visitedViews
.
filter
((
v
)
=>
{
return
v
?.
meta
?.
affix
||
v
.
path
===
view
.
p
ath
return
v
?.
meta
?.
affix
||
v
.
fullPath
===
view
.
fullP
ath
})
},
// 删除左侧
delLeftViews
(
view
:
RouteLocationNormalizedLoaded
)
{
const
index
=
findIndex
<
RouteLocationNormalizedLoaded
>
(
this
.
visitedViews
,
(
v
)
=>
v
.
path
===
view
.
p
ath
(
v
)
=>
v
.
fullPath
===
view
.
fullP
ath
)
if
(
index
>
-
1
)
{
this
.
visitedViews
=
this
.
visitedViews
.
filter
((
v
,
i
)
=>
{
return
v
?.
meta
?.
affix
||
v
.
path
===
view
.
p
ath
||
i
>
index
return
v
?.
meta
?.
affix
||
v
.
fullPath
===
view
.
fullP
ath
||
i
>
index
})
this
.
addCachedView
()
}
...
...
@@ -115,18 +129,18 @@ export const useTagsViewStore = defineStore('tagsView', {
delRightViews
(
view
:
RouteLocationNormalizedLoaded
)
{
const
index
=
findIndex
<
RouteLocationNormalizedLoaded
>
(
this
.
visitedViews
,
(
v
)
=>
v
.
path
===
view
.
p
ath
(
v
)
=>
v
.
fullPath
===
view
.
fullP
ath
)
if
(
index
>
-
1
)
{
this
.
visitedViews
=
this
.
visitedViews
.
filter
((
v
,
i
)
=>
{
return
v
?.
meta
?.
affix
||
v
.
path
===
view
.
p
ath
||
i
<
index
return
v
?.
meta
?.
affix
||
v
.
fullPath
===
view
.
fullP
ath
||
i
<
index
})
this
.
addCachedView
()
}
},
updateVisitedView
(
view
:
RouteLocationNormalizedLoaded
)
{
for
(
let
v
of
this
.
visitedViews
)
{
if
(
v
.
path
===
view
.
p
ath
)
{
if
(
v
.
fullPath
===
view
.
fullP
ath
)
{
v
=
Object
.
assign
(
v
,
view
)
break
}
...
...
types/router.d.ts
View file @
c1924d56
...
...
@@ -15,6 +15,8 @@ import { defineComponent } from 'vue'
title: 'title' 设置该路由在侧边栏和面包屑中展示的名字
titleSuffix: '2' 当 path 和 title 重复时的后缀或备注
icon: 'svg-name' 设置该路由的图标
noCache: true 如果设置为true,则不会被 <keep-alive> 缓存(默认 false)
...
...
@@ -37,6 +39,7 @@ declare module 'vue-router' {
hidden
?:
boolean
alwaysShow
?:
boolean
title
?:
string
titleSuffix
?:
string
icon
?:
string
noCache
?:
boolean
breadcrumb
?:
boolean
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment