1
1
const state = {
2
2
visitedViews : [ ] ,
3
- cachedViews : [ ]
3
+ cachedViews : [ ] ,
4
+ iframeViews : [ ]
4
5
}
5
6
6
7
const mutations = {
8
+ ADD_IFRAME_VIEW : ( state , view ) => {
9
+ if ( state . iframeViews . some ( v => v . path === view . path ) ) return
10
+ state . iframeViews . push (
11
+ Object . assign ( { } , view , {
12
+ title : view . meta . title || 'no-name'
13
+ } )
14
+ )
15
+ } ,
7
16
ADD_VISITED_VIEW : ( state , view ) => {
8
17
if ( state . visitedViews . some ( v => v . path === view . path ) ) return
9
18
state . visitedViews . push (
@@ -18,14 +27,17 @@ const mutations = {
18
27
state . cachedViews . push ( view . name )
19
28
}
20
29
} ,
21
-
22
30
DEL_VISITED_VIEW : ( state , view ) => {
23
31
for ( const [ i , v ] of state . visitedViews . entries ( ) ) {
24
32
if ( v . path === view . path ) {
25
33
state . visitedViews . splice ( i , 1 )
26
34
break
27
35
}
28
36
}
37
+ state . iframeViews = state . iframeViews . filter ( item => item . path !== view . path )
38
+ } ,
39
+ DEL_IFRAME_VIEW : ( state , view ) => {
40
+ state . iframeViews = state . iframeViews . filter ( item => item . path !== view . path )
29
41
} ,
30
42
DEL_CACHED_VIEW : ( state , view ) => {
31
43
const index = state . cachedViews . indexOf ( view . name )
@@ -36,6 +48,7 @@ const mutations = {
36
48
state . visitedViews = state . visitedViews . filter ( v => {
37
49
return v . meta . affix || v . path === view . path
38
50
} )
51
+ state . iframeViews = state . iframeViews . filter ( item => item . path === view . path )
39
52
} ,
40
53
DEL_OTHERS_CACHED_VIEWS : ( state , view ) => {
41
54
const index = state . cachedViews . indexOf ( view . name )
@@ -45,16 +58,15 @@ const mutations = {
45
58
state . cachedViews = [ ]
46
59
}
47
60
} ,
48
-
49
61
DEL_ALL_VISITED_VIEWS : state => {
50
62
// keep affix tags
51
63
const affixTags = state . visitedViews . filter ( tag => tag . meta . affix )
52
64
state . visitedViews = affixTags
65
+ state . iframeViews = [ ]
53
66
} ,
54
67
DEL_ALL_CACHED_VIEWS : state => {
55
68
state . cachedViews = [ ]
56
69
} ,
57
-
58
70
UPDATE_VISITED_VIEW : ( state , view ) => {
59
71
for ( let v of state . visitedViews ) {
60
72
if ( v . path === view . path ) {
@@ -63,7 +75,6 @@ const mutations = {
63
75
}
64
76
}
65
77
} ,
66
-
67
78
DEL_RIGHT_VIEWS : ( state , view ) => {
68
79
const index = state . visitedViews . findIndex ( v => v . path === view . path )
69
80
if ( index === - 1 ) {
@@ -77,10 +88,13 @@ const mutations = {
77
88
if ( i > - 1 ) {
78
89
state . cachedViews . splice ( i , 1 )
79
90
}
91
+ if ( item . meta . link ) {
92
+ const fi = state . iframeViews . findIndex ( v => v . path === item . path )
93
+ state . iframeViews . splice ( fi , 1 )
94
+ }
80
95
return false
81
96
} )
82
97
} ,
83
-
84
98
DEL_LEFT_VIEWS : ( state , view ) => {
85
99
const index = state . visitedViews . findIndex ( v => v . path === view . path )
86
100
if ( index === - 1 ) {
@@ -94,6 +108,10 @@ const mutations = {
94
108
if ( i > - 1 ) {
95
109
state . cachedViews . splice ( i , 1 )
96
110
}
111
+ if ( item . meta . link ) {
112
+ const fi = state . iframeViews . findIndex ( v => v . path === item . path )
113
+ state . iframeViews . splice ( fi , 1 )
114
+ }
97
115
return false
98
116
} )
99
117
}
@@ -104,13 +122,15 @@ const actions = {
104
122
dispatch ( 'addVisitedView' , view )
105
123
dispatch ( 'addCachedView' , view )
106
124
} ,
125
+ addIframeView ( { commit } , view ) {
126
+ commit ( 'ADD_IFRAME_VIEW' , view )
127
+ } ,
107
128
addVisitedView ( { commit } , view ) {
108
129
commit ( 'ADD_VISITED_VIEW' , view )
109
130
} ,
110
131
addCachedView ( { commit } , view ) {
111
132
commit ( 'ADD_CACHED_VIEW' , view )
112
133
} ,
113
-
114
134
delView ( { dispatch, state } , view ) {
115
135
return new Promise ( resolve => {
116
136
dispatch ( 'delVisitedView' , view )
@@ -127,13 +147,18 @@ const actions = {
127
147
resolve ( [ ...state . visitedViews ] )
128
148
} )
129
149
} ,
150
+ delIframeView ( { commit, state } , view ) {
151
+ return new Promise ( resolve => {
152
+ commit ( 'DEL_IFRAME_VIEW' , view )
153
+ resolve ( [ ...state . iframeViews ] )
154
+ } )
155
+ } ,
130
156
delCachedView ( { commit, state } , view ) {
131
157
return new Promise ( resolve => {
132
158
commit ( 'DEL_CACHED_VIEW' , view )
133
159
resolve ( [ ...state . cachedViews ] )
134
160
} )
135
161
} ,
136
-
137
162
delOthersViews ( { dispatch, state } , view ) {
138
163
return new Promise ( resolve => {
139
164
dispatch ( 'delOthersVisitedViews' , view )
@@ -156,7 +181,6 @@ const actions = {
156
181
resolve ( [ ...state . cachedViews ] )
157
182
} )
158
183
} ,
159
-
160
184
delAllViews ( { dispatch, state } , view ) {
161
185
return new Promise ( resolve => {
162
186
dispatch ( 'delAllVisitedViews' , view )
@@ -179,18 +203,15 @@ const actions = {
179
203
resolve ( [ ...state . cachedViews ] )
180
204
} )
181
205
} ,
182
-
183
206
updateVisitedView ( { commit } , view ) {
184
207
commit ( 'UPDATE_VISITED_VIEW' , view )
185
208
} ,
186
-
187
209
delRightTags ( { commit } , view ) {
188
210
return new Promise ( resolve => {
189
211
commit ( 'DEL_RIGHT_VIEWS' , view )
190
212
resolve ( [ ...state . visitedViews ] )
191
213
} )
192
214
} ,
193
-
194
215
delLeftTags ( { commit } , view ) {
195
216
return new Promise ( resolve => {
196
217
commit ( 'DEL_LEFT_VIEWS' , view )
0 commit comments