feat: 优化合并的代码 完成刷新单页面功能

This commit is contained in:
FairyEver
2020-08-25 15:34:13 +08:00
parent 8560f87e8a
commit 5e3eadf0eb
3 changed files with 13 additions and 13 deletions

View File

@@ -27,9 +27,6 @@
</div> </div>
</div> </div>
<div class="d2-multiple-page-control-btn" flex-box="0"> <div class="d2-multiple-page-control-btn" flex-box="0">
<el-button @click="handleRefresh">
<d2-icon name="refresh"/>
</el-button>
<el-dropdown <el-dropdown
size="default" size="default"
split-button split-button
@@ -77,6 +74,7 @@ export default {
{ icon: 'times-circle', title: '关闭全部', value: 'all' } { icon: 'times-circle', title: '关闭全部', value: 'all' }
], ],
contextmenuList: [ contextmenuList: [
{ icon: 'refresh', title: '刷新', value: 'refresh' },
{ icon: 'arrow-left', title: '关闭左侧', value: 'left' }, { icon: 'arrow-left', title: '关闭左侧', value: 'left' },
{ icon: 'arrow-right', title: '关闭右侧', value: 'right' }, { icon: 'arrow-right', title: '关闭右侧', value: 'right' },
{ icon: 'times', title: '关闭其它', value: 'other' }, { icon: 'times', title: '关闭其它', value: 'other' },
@@ -100,14 +98,6 @@ export default {
'closeAll', 'closeAll',
'openedSort' 'openedSort'
]), ]),
/**
* @description 仅刷新当前router组件 不影响其他已缓存的组件
*/
handleRefresh () {
this.$router.push({
name: 'refresh'
})
},
/** /**
* @description 计算某个标签页是否可关闭 * @description 计算某个标签页是否可关闭
* @param {Object} page 其中一个标签页 * @param {Object} page 其中一个标签页
@@ -153,6 +143,7 @@ export default {
if (tagName) this.contextmenuFlag = false if (tagName) this.contextmenuFlag = false
const params = { pageSelect: tagName } const params = { pageSelect: tagName }
switch (command) { switch (command) {
case 'refresh': this.$router.push({ name: 'refresh' }); break
case 'left': this.closeLeft(params); break case 'left': this.closeLeft(params); break
case 'right': this.closeRight(params); break case 'right': this.closeRight(params); break
case 'other': this.closeOther(params); break case 'other': this.closeOther(params); break

View File

@@ -63,7 +63,7 @@
<div class="d2-theme-container-main-body" flex-box="1"> <div class="d2-theme-container-main-body" flex-box="1">
<transition :name="transitionActive ? 'fade-transverse' : ''"> <transition :name="transitionActive ? 'fade-transverse' : ''">
<keep-alive :include="keepAlive"> <keep-alive :include="keepAlive">
<router-view :key="$route.path + $route.meta[$route.path]" /> <router-view :key="routerViewKey" />
</keep-alive> </keep-alive>
</transition> </transition>
</div> </div>
@@ -126,6 +126,15 @@ export default {
...mapGetters('d2admin', { ...mapGetters('d2admin', {
themeActiveSetting: 'theme/activeSetting' themeActiveSetting: 'theme/activeSetting'
}), }),
/**
* @description 用来实现带参路由的缓存
*/
routerViewKey () {
// 默认情况下 key 类似 __transition-n-/foo
// 这里的字符串操作是为了最终 key 的格式和原来相同 类似 __transition-n-__stamp-time-/foo
const stamp = this.$route.meta[`__stamp-${this.$route.path}`] || ''
return `${stamp ? `__stamp-${stamp}-` : ''}${this.$route.path}`
},
/** /**
* @description 最外层容器的背景图片样式 * @description 最外层容器的背景图片样式
*/ */

View File

@@ -1,6 +1,6 @@
export default { export default {
beforeRouteEnter (to, from, next) { beforeRouteEnter (to, from, next) {
from.meta[from.path] = Date.now() from.meta[`__stamp-${from.path}`] = Date.now()
next(instance => instance.$router.replace({ path: from.fullPath, meta: from.meta })) next(instance => instance.$router.replace({ path: from.fullPath, meta: from.meta }))
}, },
render: h => h() render: h => h()