Commit 49bb49bd by liimin

新增keepalive开关

1 parent 1179c973
// 过渡动画 横向渐变 // 过渡动画 横向渐变
.fade-transverse-leave-active, .fade-transverse-leave-active,
.fade-transverse-enter-active { .fade-transverse-enter-active {
transition: all .2s; transition: all .3s;
} }
.fade-transverse-enter { .fade-transverse-enter {
opacity: 0; opacity: 0;
......
...@@ -276,12 +276,18 @@ ...@@ -276,12 +276,18 @@
.el-button-group { .el-button-group {
.el-button{ .el-button{
border-bottom: none ; border-bottom: none ;
padding: 10px 20px; padding: 10px 12px;
&:first-child { &:first-child {
border-bottom-left-radius: 0px; border-bottom-left-radius: 0px;
border-right: none;
}
&:nth-child(2) {
border-right: none;
border-left: none;
} }
&:last-child { &:last-child {
border-bottom-right-radius: 0px; border-bottom-right-radius: 0px;
border-left: none
} }
} }
// } // }
......
<template> <template>
<el-tooltip <!-- <el-tooltip
effect="dark" effect="dark"
:content="active ? '退出全屏' : '全屏'" :content="active ? '退出全屏' : '全屏'"
placement="bottom"> placement="bottom"> -->
<el-button class="d2-mr btn-text can-hover" type="text" @click="toggle"> <el-button class="d2-mr btn-text can-hover" type="text" @click="toggle">
<d2-el-icon v-if="active" name="aim"/> <d2-el-icon v-if="active" name="aim"/>
<d2-el-icon v-else name="full-screen" style="font-size: 16px"/> <d2-el-icon v-else name="full-screen" style="font-size: 16px"/>
</el-button> </el-button>
</el-tooltip> <!-- </el-tooltip> -->
</template> </template>
<script> <script>
......
<template> <template>
<div> <div>
<el-tooltip <!-- <el-tooltip
effect="dark" effect="dark"
content="主题" content="主题"
placement="bottom"> placement="bottom"> -->
<el-button <el-button
class="d2-ml-0 d2-mr btn-text can-hover" class="d2-ml-0 d2-mr btn-text can-hover"
type="text" type="text"
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
name="magic-stick" name="magic-stick"
style="font-size: 18px"/> style="font-size: 18px"/>
</el-button> </el-button>
</el-tooltip> <!-- </el-tooltip> -->
<el-dialog <el-dialog
title="主题" title="主题"
width="600px" width="600px"
......
...@@ -32,43 +32,17 @@ ...@@ -32,43 +32,17 @@
flex-box="0"> flex-box="0">
<el-button-group> <el-button-group>
<el-button icon="el-icon-error" @click="closeAll"></el-button> <el-button icon="el-icon-error" @click="closeAll"></el-button>
<el-tooltip class="item" effect="dark" :content="cacheTip" placement="bottom">
<el-button :icon="kaIcon" @click="handleCache"></el-button>
</el-tooltip>
<el-button icon="el-icon-refresh" @click="reload" :disabled="current==='/index'"></el-button> <el-button icon="el-icon-refresh" @click="reload" :disabled="current==='/index'"></el-button>
</el-button-group> </el-button-group>
<!-- <el-dropdown
size="default"
split-button
@click="closeAll"
@command="command => handleControlItemClick(command)">
<d2-el-icon name="error"/>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item command="reload">
<d2-el-icon name="refresh"/>
刷新
</el-dropdown-item>
<el-dropdown-item command="left">
<d2-el-icon name="back" class="d2-mr-10"/>
关闭左侧
</el-dropdown-item>
<el-dropdown-item command="right">
<d2-el-icon name="right" class="d2-mr-10"/>
关闭右侧
</el-dropdown-item>
<el-dropdown-item command="other">
<d2-el-icon name="circle-close" class="d2-mr-10"/>
关闭其它
</el-dropdown-item>
<el-dropdown-item command="all">
<d2-el-icon name="error" class="d2-mr-10"/>
全部关闭
</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>-->
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import { mapState, mapActions, mapMutations } from 'vuex' import { mapState, mapActions } from 'vuex'
const CMD_MAP = { const CMD_MAP = {
'left': 'closeLeft', 'left': 'closeLeft',
'right': 'closeRight', 'right': 'closeRight',
...@@ -101,8 +75,20 @@ export default { ...@@ -101,8 +75,20 @@ export default {
computed: { computed: {
...mapState('d2admin/page', [ ...mapState('d2admin/page', [
'opened', 'opened',
'current' 'current',
]) 'keepAlive'
]),
isCached() {
const _curPage = this.opened.find(page => page.fullPath === this.current)
const _cache = _curPage && _curPage.meta.cache
return _cache
},
cacheTip() {
return this.isCached ? '已缓存当前页面数据' : '不缓存当前页面数据'
},
kaIcon() {
return this.isCached ? 'el-icon-star-on' : 'el-icon-star-off'
}
}, },
mounted() { mounted() {
this.$event.$on('e-reload', this.reload) this.$event.$on('e-reload', this.reload)
...@@ -113,15 +99,15 @@ export default { ...@@ -113,15 +99,15 @@ export default {
'closeLeft', 'closeLeft',
'closeRight', 'closeRight',
'closeOther', 'closeOther',
'closeAll' 'closeAll',
'keepAliveRemove',
'keepAlivePush'
]), ]),
...mapMutations('d2admin/page', ['keepAliveRemove', 'keepAlivePush']),
/** /**
* @description 右键菜单功能点击 * @description 右键菜单功能点击
*/ */
handleContextmenu(event) { handleContextmenu(event) {
let target = event.target let target = event.target
// 解决 https://github.com/d2-projects/d2-admin/issues/54
let flag = false let flag = false
if (target.className.indexOf('el-tabs__item') > -1) flag = true if (target.className.indexOf('el-tabs__item') > -1) flag = true
else if (target.parentNode.className.indexOf('el-tabs__item') > -1) { else if (target.parentNode.className.indexOf('el-tabs__item') > -1) {
...@@ -166,16 +152,21 @@ export default { ...@@ -166,16 +152,21 @@ export default {
this.$router.push({ name, params, query }) this.$router.push({ name, params, query })
} }
}, },
handleCache() {
this[this.isCached ? 'keepAliveRemove' : 'keepAlivePush'](this.$router.currentRoute.name)
},
async reload() { async reload() {
if (this.isCached) {
const name = this.$router.currentRoute.name const name = this.$router.currentRoute.name
await this.keepAliveRemove(name) await this.keepAliveRemove(name)
await this.$router.replace('/refresh')
var __timer = setInterval(() => { var __timer = setInterval(() => {
if (this.$router.currentRoute.name === name) { if (this.$router.currentRoute.name === name) {
clearInterval(__timer) clearInterval(__timer)
this.keepAlivePush(name) this.keepAlivePush(name)
} }
}, 10) }, 10)
}
this.$router.replace('/refresh')
}, },
/** /**
* @description 点击 tab 上的删除按钮触发这里 首页的删除按钮已经隐藏 因此这里不用判断是 index * @description 点击 tab 上的删除按钮触发这里 首页的删除按钮已经隐藏 因此这里不用判断是 index
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!