Skip to content

Commit c43096b

Browse files
committed
v3.8.4:优化页面内嵌iframe切换tab不刷新数据
1 parent 03771ef commit c43096b

File tree

4 files changed

+62
-26
lines changed

4 files changed

+62
-26
lines changed

src/assets/styles/transition.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@
1212
}
1313

1414
/* fade-transform */
15+
.fade-transform--move,
1516
.fade-transform-leave-active,
1617
.fade-transform-enter-active {
1718
transition: all .5s;
1819
}
1920

21+
.fade-transform-leave-active {
22+
position: absolute;
23+
}
24+
2025
.fade-transform-enter {
2126
opacity: 0;
2227
transform: translateX(-30px);

src/layout/components/AppMain.vue

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22
<section class="app-main">
33
<transition name="fade-transform" mode="out-in">
44
<keep-alive :include="cachedViews">
5-
<router-view :key="key" />
5+
<router-view v-if="!$route.meta.link" :key="key" />
66
</keep-alive>
77
</transition>
8+
<iframe-toggle />
89
</section>
910
</template>
1011

1112
<script>
13+
import iframeToggle from "./IframeToggle/index"
14+
1215
export default {
1316
name: 'AppMain',
17+
components: { iframeToggle },
1418
computed: {
1519
cachedViews() {
1620
return this.$store.state.tagsView.cachedViews
@@ -31,7 +35,7 @@ export default {
3135
overflow: hidden;
3236
}
3337
34-
.fixed-header+.app-main {
38+
.fixed-header + .app-main {
3539
padding-top: 50px;
3640
}
3741
@@ -41,7 +45,7 @@ export default {
4145
min-height: calc(100vh - 84px);
4246
}
4347
44-
.fixed-header+.app-main {
48+
.fixed-header + .app-main {
4549
padding-top: 84px;
4650
}
4751
}
@@ -51,7 +55,7 @@ export default {
5155
// fix css style bug in open el-dialog
5256
.el-popup-parent--hidden {
5357
.fixed-header {
54-
padding-right: 15px;
58+
padding-right: 17px;
5559
}
5660
}
5761
</style>

src/layout/components/TagsView/index.vue

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
<div id="tags-view-container" class="tags-view-container">
33
<scroll-pane ref="scrollPane" class="tags-view-wrapper" @scroll="handleScroll">
44
<router-link
5-
v-for="tag in visitedViews"
6-
ref="tag"
7-
:key="tag.path"
8-
:class="isActive(tag)?'active':''"
9-
:to="{ path: tag.path, query: tag.query, fullPath: tag.fullPath }"
10-
tag="span"
11-
class="tags-view-item"
12-
:style="activeStyle(tag)"
13-
@click.middle.native="!isAffix(tag)?closeSelectedTag(tag):''"
14-
@contextmenu.prevent.native="openMenu(tag,$event)"
5+
v-for="tag in visitedViews"
6+
ref="tag"
7+
:key="tag.path"
8+
:class="isActive(tag)?'active':''"
9+
:to="{ path: tag.path, query: tag.query, fullPath: tag.fullPath }"
10+
tag="span"
11+
class="tags-view-item"
12+
:style="activeStyle(tag)"
13+
@click.middle.native="!isAffix(tag)?closeSelectedTag(tag):''"
14+
@contextmenu.prevent.native="openMenu(tag,$event)"
1515
>
1616
{{ tag.title }}
1717
<span v-if="!isAffix(tag)" class="el-icon-close" @click.prevent.stop="closeSelectedTag(tag)" />
@@ -133,6 +133,9 @@ export default {
133133
const { name } = this.$route
134134
if (name) {
135135
this.$store.dispatch('tagsView/addView', this.$route)
136+
if (this.$route.meta.link) {
137+
this.$store.dispatch('tagsView/addIframeView', this.$route)
138+
}
136139
}
137140
return false
138141
},
@@ -153,6 +156,9 @@ export default {
153156
},
154157
refreshSelectedTag(view) {
155158
this.$tab.refreshPage(view);
159+
if (this.$route.meta.link) {
160+
this.$store.dispatch('tagsView/delIframeView', this.$route)
161+
}
156162
},
157163
closeSelectedTag(view) {
158164
this.$tab.closePage(view).then(({ visitedViews }) => {

src/store/modules/tagsView.js

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
const state = {
22
visitedViews: [],
3-
cachedViews: []
3+
cachedViews: [],
4+
iframeViews: []
45
}
56

67
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+
},
716
ADD_VISITED_VIEW: (state, view) => {
817
if (state.visitedViews.some(v => v.path === view.path)) return
918
state.visitedViews.push(
@@ -18,14 +27,17 @@ const mutations = {
1827
state.cachedViews.push(view.name)
1928
}
2029
},
21-
2230
DEL_VISITED_VIEW: (state, view) => {
2331
for (const [i, v] of state.visitedViews.entries()) {
2432
if (v.path === view.path) {
2533
state.visitedViews.splice(i, 1)
2634
break
2735
}
2836
}
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)
2941
},
3042
DEL_CACHED_VIEW: (state, view) => {
3143
const index = state.cachedViews.indexOf(view.name)
@@ -36,6 +48,7 @@ const mutations = {
3648
state.visitedViews = state.visitedViews.filter(v => {
3749
return v.meta.affix || v.path === view.path
3850
})
51+
state.iframeViews = state.iframeViews.filter(item => item.path === view.path)
3952
},
4053
DEL_OTHERS_CACHED_VIEWS: (state, view) => {
4154
const index = state.cachedViews.indexOf(view.name)
@@ -45,16 +58,15 @@ const mutations = {
4558
state.cachedViews = []
4659
}
4760
},
48-
4961
DEL_ALL_VISITED_VIEWS: state => {
5062
// keep affix tags
5163
const affixTags = state.visitedViews.filter(tag => tag.meta.affix)
5264
state.visitedViews = affixTags
65+
state.iframeViews = []
5366
},
5467
DEL_ALL_CACHED_VIEWS: state => {
5568
state.cachedViews = []
5669
},
57-
5870
UPDATE_VISITED_VIEW: (state, view) => {
5971
for (let v of state.visitedViews) {
6072
if (v.path === view.path) {
@@ -63,7 +75,6 @@ const mutations = {
6375
}
6476
}
6577
},
66-
6778
DEL_RIGHT_VIEWS: (state, view) => {
6879
const index = state.visitedViews.findIndex(v => v.path === view.path)
6980
if (index === -1) {
@@ -77,10 +88,13 @@ const mutations = {
7788
if (i > -1) {
7889
state.cachedViews.splice(i, 1)
7990
}
91+
if(item.meta.link) {
92+
const fi = state.iframeViews.findIndex(v => v.path === item.path)
93+
state.iframeViews.splice(fi, 1)
94+
}
8095
return false
8196
})
8297
},
83-
8498
DEL_LEFT_VIEWS: (state, view) => {
8599
const index = state.visitedViews.findIndex(v => v.path === view.path)
86100
if (index === -1) {
@@ -94,6 +108,10 @@ const mutations = {
94108
if (i > -1) {
95109
state.cachedViews.splice(i, 1)
96110
}
111+
if(item.meta.link) {
112+
const fi = state.iframeViews.findIndex(v => v.path === item.path)
113+
state.iframeViews.splice(fi, 1)
114+
}
97115
return false
98116
})
99117
}
@@ -104,13 +122,15 @@ const actions = {
104122
dispatch('addVisitedView', view)
105123
dispatch('addCachedView', view)
106124
},
125+
addIframeView({ commit }, view) {
126+
commit('ADD_IFRAME_VIEW', view)
127+
},
107128
addVisitedView({ commit }, view) {
108129
commit('ADD_VISITED_VIEW', view)
109130
},
110131
addCachedView({ commit }, view) {
111132
commit('ADD_CACHED_VIEW', view)
112133
},
113-
114134
delView({ dispatch, state }, view) {
115135
return new Promise(resolve => {
116136
dispatch('delVisitedView', view)
@@ -127,13 +147,18 @@ const actions = {
127147
resolve([...state.visitedViews])
128148
})
129149
},
150+
delIframeView({ commit, state }, view) {
151+
return new Promise(resolve => {
152+
commit('DEL_IFRAME_VIEW', view)
153+
resolve([...state.iframeViews])
154+
})
155+
},
130156
delCachedView({ commit, state }, view) {
131157
return new Promise(resolve => {
132158
commit('DEL_CACHED_VIEW', view)
133159
resolve([...state.cachedViews])
134160
})
135161
},
136-
137162
delOthersViews({ dispatch, state }, view) {
138163
return new Promise(resolve => {
139164
dispatch('delOthersVisitedViews', view)
@@ -156,7 +181,6 @@ const actions = {
156181
resolve([...state.cachedViews])
157182
})
158183
},
159-
160184
delAllViews({ dispatch, state }, view) {
161185
return new Promise(resolve => {
162186
dispatch('delAllVisitedViews', view)
@@ -179,18 +203,15 @@ const actions = {
179203
resolve([...state.cachedViews])
180204
})
181205
},
182-
183206
updateVisitedView({ commit }, view) {
184207
commit('UPDATE_VISITED_VIEW', view)
185208
},
186-
187209
delRightTags({ commit }, view) {
188210
return new Promise(resolve => {
189211
commit('DEL_RIGHT_VIEWS', view)
190212
resolve([...state.visitedViews])
191213
})
192214
},
193-
194215
delLeftTags({ commit }, view) {
195216
return new Promise(resolve => {
196217
commit('DEL_LEFT_VIEWS', view)

0 commit comments

Comments
 (0)