Commit 1a60d0ceb3a79a815ce78981abd1bf36ed4e516c
1 parent
1999ac4e
v3.8.4:优化页面内嵌iframe切换tab不刷新数据
Showing
4 changed files
with
62 additions
and
26 deletions
yudao-ui-admin/src/assets/styles/transition.scss
| ... | ... | @@ -12,11 +12,16 @@ |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | /* fade-transform */ |
| 15 | +.fade-transform--move, | |
| 15 | 16 | .fade-transform-leave-active, |
| 16 | 17 | .fade-transform-enter-active { |
| 17 | 18 | transition: all .5s; |
| 18 | 19 | } |
| 19 | 20 | |
| 21 | +.fade-transform-leave-active { | |
| 22 | + position: absolute; | |
| 23 | +} | |
| 24 | + | |
| 20 | 25 | .fade-transform-enter { |
| 21 | 26 | opacity: 0; |
| 22 | 27 | transform: translateX(-30px); | ... | ... |
yudao-ui-admin/src/layout/components/AppMain.vue
| ... | ... | @@ -2,15 +2,19 @@ |
| 2 | 2 | <section class="app-main"> |
| 3 | 3 | <transition name="fade-transform" mode="out-in"> |
| 4 | 4 | <keep-alive :include="cachedViews"> |
| 5 | - <router-view :key="key" /> | |
| 5 | + <router-view v-if="!$route.meta.link" :key="key" /> | |
| 6 | 6 | </keep-alive> |
| 7 | 7 | </transition> |
| 8 | + <iframe-toggle /> | |
| 8 | 9 | </section> |
| 9 | 10 | </template> |
| 10 | 11 | |
| 11 | 12 | <script> |
| 13 | +import iframeToggle from "./IframeToggle/index" | |
| 14 | + | |
| 12 | 15 | export default { |
| 13 | 16 | name: 'AppMain', |
| 17 | + components: { iframeToggle }, | |
| 14 | 18 | computed: { |
| 15 | 19 | cachedViews() { |
| 16 | 20 | return this.$store.state.tagsView.cachedViews |
| ... | ... | @@ -31,7 +35,7 @@ export default { |
| 31 | 35 | overflow: hidden; |
| 32 | 36 | } |
| 33 | 37 | |
| 34 | -.fixed-header+.app-main { | |
| 38 | +.fixed-header + .app-main { | |
| 35 | 39 | padding-top: 50px; |
| 36 | 40 | } |
| 37 | 41 | |
| ... | ... | @@ -41,7 +45,7 @@ export default { |
| 41 | 45 | min-height: calc(100vh - 84px); |
| 42 | 46 | } |
| 43 | 47 | |
| 44 | - .fixed-header+.app-main { | |
| 48 | + .fixed-header + .app-main { | |
| 45 | 49 | padding-top: 84px; |
| 46 | 50 | } |
| 47 | 51 | } |
| ... | ... | @@ -51,7 +55,7 @@ export default { |
| 51 | 55 | // fix css style bug in open el-dialog |
| 52 | 56 | .el-popup-parent--hidden { |
| 53 | 57 | .fixed-header { |
| 54 | - padding-right: 15px; | |
| 58 | + padding-right: 17px; | |
| 55 | 59 | } |
| 56 | 60 | } |
| 57 | 61 | </style> | ... | ... |
yudao-ui-admin/src/layout/components/TagsView/index.vue
| ... | ... | @@ -2,16 +2,16 @@ |
| 2 | 2 | <div id="tags-view-container" class="tags-view-container"> |
| 3 | 3 | <scroll-pane ref="scrollPane" class="tags-view-wrapper" @scroll="handleScroll"> |
| 4 | 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 | 16 | {{ tag.title }} |
| 17 | 17 | <span v-if="!isAffix(tag)" class="el-icon-close" @click.prevent.stop="closeSelectedTag(tag)" /> |
| ... | ... | @@ -133,6 +133,9 @@ export default { |
| 133 | 133 | const { name } = this.$route |
| 134 | 134 | if (name) { |
| 135 | 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 | 140 | return false |
| 138 | 141 | }, |
| ... | ... | @@ -153,6 +156,9 @@ export default { |
| 153 | 156 | }, |
| 154 | 157 | refreshSelectedTag(view) { |
| 155 | 158 | this.$tab.refreshPage(view); |
| 159 | + if (this.$route.meta.link) { | |
| 160 | + this.$store.dispatch('tagsView/delIframeView', this.$route) | |
| 161 | + } | |
| 156 | 162 | }, |
| 157 | 163 | closeSelectedTag(view) { |
| 158 | 164 | this.$tab.closePage(view).then(({ visitedViews }) => { | ... | ... |
yudao-ui-admin/src/store/modules/tagsView.js
| 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,7 +27,6 @@ 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) { |
| ... | ... | @@ -26,6 +34,10 @@ const mutations = { |
| 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) | ... | ... |