Commit 1a60d0ceb3a79a815ce78981abd1bf36ed4e516c

Authored by YunaiV
1 parent 1999ac4e

v3.8.4:优化页面内嵌iframe切换tab不刷新数据

yudao-ui-admin/src/assets/styles/transition.scss
@@ -12,11 +12,16 @@ @@ -12,11 +12,16 @@
12 } 12 }
13 13
14 /* fade-transform */ 14 /* fade-transform */
  15 +.fade-transform--move,
15 .fade-transform-leave-active, 16 .fade-transform-leave-active,
16 .fade-transform-enter-active { 17 .fade-transform-enter-active {
17 transition: all .5s; 18 transition: all .5s;
18 } 19 }
19 20
  21 +.fade-transform-leave-active {
  22 + position: absolute;
  23 +}
  24 +
20 .fade-transform-enter { 25 .fade-transform-enter {
21 opacity: 0; 26 opacity: 0;
22 transform: translateX(-30px); 27 transform: translateX(-30px);
yudao-ui-admin/src/layout/components/AppMain.vue
@@ -2,15 +2,19 @@ @@ -2,15 +2,19 @@
2 <section class="app-main"> 2 <section class="app-main">
3 <transition name="fade-transform" mode="out-in"> 3 <transition name="fade-transform" mode="out-in">
4 <keep-alive :include="cachedViews"> 4 <keep-alive :include="cachedViews">
5 - <router-view :key="key" /> 5 + <router-view v-if="!$route.meta.link" :key="key" />
6 </keep-alive> 6 </keep-alive>
7 </transition> 7 </transition>
  8 + <iframe-toggle />
8 </section> 9 </section>
9 </template> 10 </template>
10 11
11 <script> 12 <script>
  13 +import iframeToggle from "./IframeToggle/index"
  14 +
12 export default { 15 export default {
13 name: 'AppMain', 16 name: 'AppMain',
  17 + components: { iframeToggle },
14 computed: { 18 computed: {
15 cachedViews() { 19 cachedViews() {
16 return this.$store.state.tagsView.cachedViews 20 return this.$store.state.tagsView.cachedViews
@@ -31,7 +35,7 @@ export default { @@ -31,7 +35,7 @@ export default {
31 overflow: hidden; 35 overflow: hidden;
32 } 36 }
33 37
34 -.fixed-header+.app-main { 38 +.fixed-header + .app-main {
35 padding-top: 50px; 39 padding-top: 50px;
36 } 40 }
37 41
@@ -41,7 +45,7 @@ export default { @@ -41,7 +45,7 @@ export default {
41 min-height: calc(100vh - 84px); 45 min-height: calc(100vh - 84px);
42 } 46 }
43 47
44 - .fixed-header+.app-main { 48 + .fixed-header + .app-main {
45 padding-top: 84px; 49 padding-top: 84px;
46 } 50 }
47 } 51 }
@@ -51,7 +55,7 @@ export default { @@ -51,7 +55,7 @@ export default {
51 // fix css style bug in open el-dialog 55 // fix css style bug in open el-dialog
52 .el-popup-parent--hidden { 56 .el-popup-parent--hidden {
53 .fixed-header { 57 .fixed-header {
54 - padding-right: 15px; 58 + padding-right: 17px;
55 } 59 }
56 } 60 }
57 </style> 61 </style>
yudao-ui-admin/src/layout/components/TagsView/index.vue
@@ -2,16 +2,16 @@ @@ -2,16 +2,16 @@
2 <div id="tags-view-container" class="tags-view-container"> 2 <div id="tags-view-container" class="tags-view-container">
3 <scroll-pane ref="scrollPane" class="tags-view-wrapper" @scroll="handleScroll"> 3 <scroll-pane ref="scrollPane" class="tags-view-wrapper" @scroll="handleScroll">
4 <router-link 4 <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)"
15 > 15 >
16 {{ tag.title }} 16 {{ tag.title }}
17 <span v-if="!isAffix(tag)" class="el-icon-close" @click.prevent.stop="closeSelectedTag(tag)" /> 17 <span v-if="!isAffix(tag)" class="el-icon-close" @click.prevent.stop="closeSelectedTag(tag)" />
@@ -133,6 +133,9 @@ export default { @@ -133,6 +133,9 @@ export default {
133 const { name } = this.$route 133 const { name } = this.$route
134 if (name) { 134 if (name) {
135 this.$store.dispatch('tagsView/addView', this.$route) 135 this.$store.dispatch('tagsView/addView', this.$route)
  136 + if (this.$route.meta.link) {
  137 + this.$store.dispatch('tagsView/addIframeView', this.$route)
  138 + }
136 } 139 }
137 return false 140 return false
138 }, 141 },
@@ -153,6 +156,9 @@ export default { @@ -153,6 +156,9 @@ export default {
153 }, 156 },
154 refreshSelectedTag(view) { 157 refreshSelectedTag(view) {
155 this.$tab.refreshPage(view); 158 this.$tab.refreshPage(view);
  159 + if (this.$route.meta.link) {
  160 + this.$store.dispatch('tagsView/delIframeView', this.$route)
  161 + }
156 }, 162 },
157 closeSelectedTag(view) { 163 closeSelectedTag(view) {
158 this.$tab.closePage(view).then(({ visitedViews }) => { 164 this.$tab.closePage(view).then(({ visitedViews }) => {
yudao-ui-admin/src/store/modules/tagsView.js
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)) return
  10 + state.iframeViews.push(
  11 + Object.assign({}, view, {
  12 + title: view.meta.title || 'no-name'
  13 + })
  14 + )
  15 + },
7 ADD_VISITED_VIEW: (state, view) => { 16 ADD_VISITED_VIEW: (state, view) => {
8 if (state.visitedViews.some(v => v.path === view.path)) return 17 if (state.visitedViews.some(v => v.path === view.path)) return
9 state.visitedViews.push( 18 state.visitedViews.push(
@@ -18,7 +27,6 @@ const mutations = { @@ -18,7 +27,6 @@ const mutations = {
18 state.cachedViews.push(view.name) 27 state.cachedViews.push(view.name)
19 } 28 }
20 }, 29 },
21 -  
22 DEL_VISITED_VIEW: (state, view) => { 30 DEL_VISITED_VIEW: (state, view) => {
23 for (const [i, v] of state.visitedViews.entries()) { 31 for (const [i, v] of state.visitedViews.entries()) {
24 if (v.path === view.path) { 32 if (v.path === view.path) {
@@ -26,6 +34,10 @@ const mutations = { @@ -26,6 +34,10 @@ const mutations = {
26 break 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 DEL_CACHED_VIEW: (state, view) => { 42 DEL_CACHED_VIEW: (state, view) => {
31 const index = state.cachedViews.indexOf(view.name) 43 const index = state.cachedViews.indexOf(view.name)
@@ -36,6 +48,7 @@ const mutations = { @@ -36,6 +48,7 @@ const mutations = {
36 state.visitedViews = state.visitedViews.filter(v => { 48 state.visitedViews = state.visitedViews.filter(v => {
37 return v.meta.affix || v.path === view.path 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 DEL_OTHERS_CACHED_VIEWS: (state, view) => { 53 DEL_OTHERS_CACHED_VIEWS: (state, view) => {
41 const index = state.cachedViews.indexOf(view.name) 54 const index = state.cachedViews.indexOf(view.name)
@@ -45,16 +58,15 @@ const mutations = { @@ -45,16 +58,15 @@ const mutations = {
45 state.cachedViews = [] 58 state.cachedViews = []
46 } 59 }
47 }, 60 },
48 -  
49 DEL_ALL_VISITED_VIEWS: state => { 61 DEL_ALL_VISITED_VIEWS: state => {
50 // keep affix tags 62 // keep affix tags
51 const affixTags = state.visitedViews.filter(tag => tag.meta.affix) 63 const affixTags = state.visitedViews.filter(tag => tag.meta.affix)
52 state.visitedViews = affixTags 64 state.visitedViews = affixTags
  65 + state.iframeViews = []
53 }, 66 },
54 DEL_ALL_CACHED_VIEWS: state => { 67 DEL_ALL_CACHED_VIEWS: state => {
55 state.cachedViews = [] 68 state.cachedViews = []
56 }, 69 },
57 -  
58 UPDATE_VISITED_VIEW: (state, view) => { 70 UPDATE_VISITED_VIEW: (state, view) => {
59 for (let v of state.visitedViews) { 71 for (let v of state.visitedViews) {
60 if (v.path === view.path) { 72 if (v.path === view.path) {
@@ -63,7 +75,6 @@ const mutations = { @@ -63,7 +75,6 @@ const mutations = {
63 } 75 }
64 } 76 }
65 }, 77 },
66 -  
67 DEL_RIGHT_VIEWS: (state, view) => { 78 DEL_RIGHT_VIEWS: (state, view) => {
68 const index = state.visitedViews.findIndex(v => v.path === view.path) 79 const index = state.visitedViews.findIndex(v => v.path === view.path)
69 if (index === -1) { 80 if (index === -1) {
@@ -77,10 +88,13 @@ const mutations = { @@ -77,10 +88,13 @@ const mutations = {
77 if (i > -1) { 88 if (i > -1) {
78 state.cachedViews.splice(i, 1) 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 return false 95 return false
81 }) 96 })
82 }, 97 },
83 -  
84 DEL_LEFT_VIEWS: (state, view) => { 98 DEL_LEFT_VIEWS: (state, view) => {
85 const index = state.visitedViews.findIndex(v => v.path === view.path) 99 const index = state.visitedViews.findIndex(v => v.path === view.path)
86 if (index === -1) { 100 if (index === -1) {
@@ -94,6 +108,10 @@ const mutations = { @@ -94,6 +108,10 @@ const mutations = {
94 if (i > -1) { 108 if (i > -1) {
95 state.cachedViews.splice(i, 1) 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 return false 115 return false
98 }) 116 })
99 } 117 }
@@ -104,13 +122,15 @@ const actions = { @@ -104,13 +122,15 @@ const actions = {
104 dispatch('addVisitedView', view) 122 dispatch('addVisitedView', view)
105 dispatch('addCachedView', view) 123 dispatch('addCachedView', view)
106 }, 124 },
  125 + addIframeView({ commit }, view) {
  126 + commit('ADD_IFRAME_VIEW', view)
  127 + },
107 addVisitedView({ commit }, view) { 128 addVisitedView({ commit }, view) {
108 commit('ADD_VISITED_VIEW', view) 129 commit('ADD_VISITED_VIEW', view)
109 }, 130 },
110 addCachedView({ commit }, view) { 131 addCachedView({ commit }, view) {
111 commit('ADD_CACHED_VIEW', view) 132 commit('ADD_CACHED_VIEW', view)
112 }, 133 },
113 -  
114 delView({ dispatch, state }, view) { 134 delView({ dispatch, state }, view) {
115 return new Promise(resolve => { 135 return new Promise(resolve => {
116 dispatch('delVisitedView', view) 136 dispatch('delVisitedView', view)
@@ -127,13 +147,18 @@ const actions = { @@ -127,13 +147,18 @@ const actions = {
127 resolve([...state.visitedViews]) 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 delCachedView({ commit, state }, view) { 156 delCachedView({ commit, state }, view) {
131 return new Promise(resolve => { 157 return new Promise(resolve => {
132 commit('DEL_CACHED_VIEW', view) 158 commit('DEL_CACHED_VIEW', view)
133 resolve([...state.cachedViews]) 159 resolve([...state.cachedViews])
134 }) 160 })
135 }, 161 },
136 -  
137 delOthersViews({ dispatch, state }, view) { 162 delOthersViews({ dispatch, state }, view) {
138 return new Promise(resolve => { 163 return new Promise(resolve => {
139 dispatch('delOthersVisitedViews', view) 164 dispatch('delOthersVisitedViews', view)
@@ -156,7 +181,6 @@ const actions = { @@ -156,7 +181,6 @@ const actions = {
156 resolve([...state.cachedViews]) 181 resolve([...state.cachedViews])
157 }) 182 })
158 }, 183 },
159 -  
160 delAllViews({ dispatch, state }, view) { 184 delAllViews({ dispatch, state }, view) {
161 return new Promise(resolve => { 185 return new Promise(resolve => {
162 dispatch('delAllVisitedViews', view) 186 dispatch('delAllVisitedViews', view)
@@ -179,18 +203,15 @@ const actions = { @@ -179,18 +203,15 @@ const actions = {
179 resolve([...state.cachedViews]) 203 resolve([...state.cachedViews])
180 }) 204 })
181 }, 205 },
182 -  
183 updateVisitedView({ commit }, view) { 206 updateVisitedView({ commit }, view) {
184 commit('UPDATE_VISITED_VIEW', view) 207 commit('UPDATE_VISITED_VIEW', view)
185 }, 208 },
186 -  
187 delRightTags({ commit }, view) { 209 delRightTags({ commit }, view) {
188 return new Promise(resolve => { 210 return new Promise(resolve => {
189 commit('DEL_RIGHT_VIEWS', view) 211 commit('DEL_RIGHT_VIEWS', view)
190 resolve([...state.visitedViews]) 212 resolve([...state.visitedViews])
191 }) 213 })
192 }, 214 },
193 -  
194 delLeftTags({ commit }, view) { 215 delLeftTags({ commit }, view) {
195 return new Promise(resolve => { 216 return new Promise(resolve => {
196 commit('DEL_LEFT_VIEWS', view) 217 commit('DEL_LEFT_VIEWS', view)