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