2018-07-23 23:05:14 +08:00
|
|
|
<template>
|
2019-04-27 20:08:40 +08:00
|
|
|
<d2-container>
|
2018-08-11 21:04:50 +08:00
|
|
|
<el-tabs>
|
|
|
|
|
<el-tab-pane label="顶栏菜单">
|
|
|
|
|
<el-button-group class="d2-mb">
|
2018-08-12 08:14:33 +08:00
|
|
|
<el-button @click="handleHeaderSet">设置顶栏空菜单</el-button>
|
|
|
|
|
<el-button @click="headerReset">恢复顶栏菜单</el-button>
|
2018-08-11 21:04:50 +08:00
|
|
|
</el-button-group>
|
2018-08-12 08:14:33 +08:00
|
|
|
<d2-highlight :code="JSON.stringify(header, null, 2)"/>
|
2018-08-11 21:04:50 +08:00
|
|
|
</el-tab-pane>
|
|
|
|
|
<el-tab-pane label="侧栏菜单">
|
|
|
|
|
<el-button-group class="d2-mb">
|
2018-08-12 08:14:33 +08:00
|
|
|
<el-button @click="handleAsideSet">设置侧栏空菜单</el-button>
|
|
|
|
|
<el-button @click="asideReset">恢复侧栏菜单</el-button>
|
2020-04-23 11:00:49 +08:00
|
|
|
<el-button @click="asideTransitionToggle()">{{`${asideTransition ? '关闭' : '开启'}侧栏动画效果`}}</el-button>
|
2018-08-11 21:04:50 +08:00
|
|
|
</el-button-group>
|
2018-08-12 08:14:33 +08:00
|
|
|
<d2-highlight :code="JSON.stringify(aside, null, 2)"/>
|
2018-08-11 21:04:50 +08:00
|
|
|
</el-tab-pane>
|
|
|
|
|
</el-tabs>
|
2018-07-23 23:05:14 +08:00
|
|
|
</d2-container>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2018-08-12 23:18:28 +08:00
|
|
|
import { cloneDeep } from 'lodash'
|
2020-04-23 11:00:49 +08:00
|
|
|
import { mapState, mapMutations, mapActions } from 'vuex'
|
2018-07-23 23:05:14 +08:00
|
|
|
export default {
|
|
|
|
|
data () {
|
|
|
|
|
return {
|
|
|
|
|
menuEmpty: [
|
|
|
|
|
{
|
|
|
|
|
title: '空菜单演示',
|
|
|
|
|
icon: 'folder-o',
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
title: '空菜单 1',
|
|
|
|
|
children: [
|
|
|
|
|
{ title: '空菜单 1-1' },
|
|
|
|
|
{ title: '空菜单 1-2' }
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{ title: '空菜单 2' },
|
|
|
|
|
{ title: '空菜单 3' }
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
],
|
2018-08-12 08:14:33 +08:00
|
|
|
headerChanged: false,
|
|
|
|
|
asideChanged: false,
|
|
|
|
|
headerBak: [],
|
|
|
|
|
asideBak: []
|
2018-07-23 23:05:14 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
computed: {
|
2018-08-12 08:14:33 +08:00
|
|
|
...mapState('d2admin/menu', [
|
|
|
|
|
'header',
|
2020-04-23 11:00:49 +08:00
|
|
|
'aside',
|
|
|
|
|
'asideTransition'
|
2018-08-12 08:14:33 +08:00
|
|
|
])
|
2018-07-23 23:05:14 +08:00
|
|
|
},
|
|
|
|
|
created () {
|
2018-08-12 23:18:28 +08:00
|
|
|
this.headerBak = cloneDeep(this.header)
|
|
|
|
|
this.asideBak = cloneDeep(this.aside)
|
2018-07-23 23:05:14 +08:00
|
|
|
},
|
|
|
|
|
beforeDestroy () {
|
2018-08-12 08:14:33 +08:00
|
|
|
if (this.headerChanged && this.asideChanged) {
|
|
|
|
|
this.headerSet(this.headerBak)
|
|
|
|
|
this.asideSet(this.asideBak)
|
2018-07-23 23:05:14 +08:00
|
|
|
this.$notify({
|
|
|
|
|
title: '菜单恢复',
|
|
|
|
|
message: '对侧边栏和顶栏菜单的修改已经复原',
|
|
|
|
|
type: 'success'
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
2018-08-12 08:14:33 +08:00
|
|
|
if (this.headerChanged) {
|
|
|
|
|
this.headerSet(this.headerBak)
|
2018-07-23 23:05:14 +08:00
|
|
|
this.$notify({
|
|
|
|
|
title: '菜单恢复',
|
|
|
|
|
message: '对顶栏菜单的修改已经复原',
|
|
|
|
|
type: 'success'
|
|
|
|
|
})
|
|
|
|
|
return
|
|
|
|
|
}
|
2018-08-12 08:14:33 +08:00
|
|
|
if (this.asideChanged) {
|
|
|
|
|
this.asideSet(this.asideBak)
|
2018-07-23 23:05:14 +08:00
|
|
|
this.$notify({
|
|
|
|
|
title: '菜单恢复',
|
|
|
|
|
message: '对侧边栏菜单的修改已经复原',
|
|
|
|
|
type: 'success'
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
2018-08-12 08:14:33 +08:00
|
|
|
...mapMutations('d2admin/menu', [
|
|
|
|
|
'headerSet',
|
|
|
|
|
'asideSet'
|
2018-07-23 23:05:14 +08:00
|
|
|
]),
|
2020-04-23 11:00:49 +08:00
|
|
|
...mapActions('d2admin/menu', [
|
|
|
|
|
'asideTransitionToggle'
|
|
|
|
|
]),
|
2018-07-23 23:05:14 +08:00
|
|
|
/**
|
|
|
|
|
* 修改顶栏菜单
|
|
|
|
|
*/
|
2018-08-12 08:14:33 +08:00
|
|
|
handleHeaderSet () {
|
|
|
|
|
this.headerChanged = true
|
|
|
|
|
this.headerSet(this.menuEmpty)
|
2018-07-24 08:47:35 +08:00
|
|
|
this.$notify({
|
|
|
|
|
title: '菜单修改',
|
|
|
|
|
message: '对顶栏菜单的修改已经生效',
|
|
|
|
|
type: 'success'
|
|
|
|
|
})
|
2018-07-23 23:05:14 +08:00
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* 修改侧边栏菜单
|
|
|
|
|
*/
|
2018-08-12 08:14:33 +08:00
|
|
|
handleAsideSet () {
|
|
|
|
|
this.asideChanged = true
|
|
|
|
|
this.asideSet(this.menuEmpty)
|
2018-07-24 08:47:35 +08:00
|
|
|
this.$notify({
|
|
|
|
|
title: '菜单修改',
|
|
|
|
|
message: '对侧边栏菜单的修改已经生效',
|
|
|
|
|
type: 'success'
|
|
|
|
|
})
|
2018-07-23 23:05:14 +08:00
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* 恢复顶栏菜单
|
|
|
|
|
*/
|
2018-08-12 08:14:33 +08:00
|
|
|
headerReset () {
|
|
|
|
|
this.headerSet(this.headerBak)
|
2018-07-24 08:47:35 +08:00
|
|
|
this.$notify({
|
|
|
|
|
title: '菜单恢复',
|
|
|
|
|
message: '对顶栏菜单的修改已经复原',
|
|
|
|
|
type: 'success'
|
|
|
|
|
})
|
2018-07-23 23:05:14 +08:00
|
|
|
},
|
|
|
|
|
/**
|
|
|
|
|
* 恢复侧边栏菜单
|
|
|
|
|
*/
|
2018-08-12 08:14:33 +08:00
|
|
|
asideReset () {
|
|
|
|
|
this.asideSet(this.asideBak)
|
2018-07-24 08:47:35 +08:00
|
|
|
this.$notify({
|
|
|
|
|
title: '菜单恢复',
|
|
|
|
|
message: '对侧边栏菜单的修改已经复原',
|
|
|
|
|
type: 'success'
|
|
|
|
|
})
|
2018-07-23 23:05:14 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|