@@ -31,13 +31,27 @@ export const useTagsViewStore = defineStore('tagsView', {
31
31
} ,
32
32
// 新增tag
33
33
addVisitedView ( view : RouteLocationNormalizedLoaded ) {
34
- if ( this . visitedViews . some ( ( v ) => v . path === view . path ) ) return
34
+ if ( this . visitedViews . some ( ( v ) => v . fullPath === view . fullPath ) ) return
35
35
if ( view . meta ?. noTagsView ) return
36
- this . visitedViews . push (
37
- Object . assign ( { } , view , {
38
- title : view . meta ?. title || 'no-name'
36
+ const visitedView = Object . assign ( { } , view , { title : view . meta ?. title || 'no-name' } )
37
+
38
+ if ( visitedView . meta ) {
39
+ const titleSuffixList : string [ ] = [ ]
40
+ this . visitedViews . forEach ( ( v ) => {
41
+ if ( v . path === visitedView . path && v . meta ?. title === visitedView . meta ?. title ) {
42
+ titleSuffixList . push ( v . meta ?. titleSuffix || '1' )
43
+ }
39
44
} )
40
- )
45
+ if ( titleSuffixList . length ) {
46
+ let titleSuffix = 1
47
+ while ( titleSuffixList . includes ( `${ titleSuffix } ` ) ) {
48
+ titleSuffix += 1
49
+ }
50
+ visitedView . meta . titleSuffix = titleSuffix === 1 ? undefined : `${ titleSuffix } `
51
+ }
52
+ }
53
+
54
+ this . visitedViews . push ( visitedView )
41
55
} ,
42
56
// 新增缓存
43
57
addCachedView ( ) {
@@ -63,7 +77,7 @@ export const useTagsViewStore = defineStore('tagsView', {
63
77
// 删除tag
64
78
delVisitedView ( view : RouteLocationNormalizedLoaded ) {
65
79
for ( const [ i , v ] of this . visitedViews . entries ( ) ) {
66
- if ( v . path === view . path ) {
80
+ if ( v . fullPath === view . fullPath ) {
67
81
this . visitedViews . splice ( i , 1 )
68
82
break
69
83
}
@@ -95,18 +109,18 @@ export const useTagsViewStore = defineStore('tagsView', {
95
109
// 删除其他tag
96
110
delOthersVisitedViews ( view : RouteLocationNormalizedLoaded ) {
97
111
this . visitedViews = this . visitedViews . filter ( ( v ) => {
98
- return v ?. meta ?. affix || v . path === view . path
112
+ return v ?. meta ?. affix || v . fullPath === view . fullPath
99
113
} )
100
114
} ,
101
115
// 删除左侧
102
116
delLeftViews ( view : RouteLocationNormalizedLoaded ) {
103
117
const index = findIndex < RouteLocationNormalizedLoaded > (
104
118
this . visitedViews ,
105
- ( v ) => v . path === view . path
119
+ ( v ) => v . fullPath === view . fullPath
106
120
)
107
121
if ( index > - 1 ) {
108
122
this . visitedViews = this . visitedViews . filter ( ( v , i ) => {
109
- return v ?. meta ?. affix || v . path === view . path || i > index
123
+ return v ?. meta ?. affix || v . fullPath === view . fullPath || i > index
110
124
} )
111
125
this . addCachedView ( )
112
126
}
@@ -115,18 +129,18 @@ export const useTagsViewStore = defineStore('tagsView', {
115
129
delRightViews ( view : RouteLocationNormalizedLoaded ) {
116
130
const index = findIndex < RouteLocationNormalizedLoaded > (
117
131
this . visitedViews ,
118
- ( v ) => v . path === view . path
132
+ ( v ) => v . fullPath === view . fullPath
119
133
)
120
134
if ( index > - 1 ) {
121
135
this . visitedViews = this . visitedViews . filter ( ( v , i ) => {
122
- return v ?. meta ?. affix || v . path === view . path || i < index
136
+ return v ?. meta ?. affix || v . fullPath === view . fullPath || i < index
123
137
} )
124
138
this . addCachedView ( )
125
139
}
126
140
} ,
127
141
updateVisitedView ( view : RouteLocationNormalizedLoaded ) {
128
142
for ( let v of this . visitedViews ) {
129
- if ( v . path === view . path ) {
143
+ if ( v . fullPath === view . fullPath ) {
130
144
v = Object . assign ( v , view )
131
145
break
132
146
}
0 commit comments