支持不同角色自定义首页

This commit is contained in:
pixel
2021-01-14 12:28:13 +08:00
parent 3d01706fb6
commit 7abe6987a5
6 changed files with 56 additions and 16 deletions
@@ -1,7 +1,7 @@
<template>
<div class="router-history">
<el-tabs
:closable="!(historys.length==1&&this.$route.name=='dashboard')"
:closable="!(historys.length==1&&this.$route.name==defaultRouter)"
@contextmenu.prevent.native="openContextMenu($event)"
@tab-click="changeTab"
@tab-remove="removeTab"
@@ -27,12 +27,14 @@
</div>
</template>
<script>
import {mapGetters} from "vuex"
export default {
name: 'HistoryComponent',
data() {
return {
historys: [],
activeValue: 'dashboard',
activeValue: '',
contextMenuVisible: false,
left: 0,
top: 0,
@@ -41,7 +43,15 @@ export default {
rightActive: ''
}
},
computed:{
...mapGetters("user",["userInfo"]),
defaultRouter(){
return this.userInfo.authority.defaultRouter
}
},
created() {
this.activeValue = this.defaultRouter
this.$bus.on('mobile', isMobile => {
this.isMobile = isMobile
})
@@ -50,9 +60,9 @@ export default {
})
const initHistorys = [
{
name: 'dashboard',
name: this.defaultRouter,
meta: {
title: '仪表盘'
title: '首页'
}
}
]
@@ -67,7 +77,7 @@ export default {
},
methods: {
openContextMenu(e) {
if (this.historys.length == 1 && this.$route.name == 'dashboard') {
if (this.historys.length == 1 && this.$route.name == this.defaultRouter) {
return false
}
if (e.srcElement.id) {
@@ -89,13 +99,13 @@ export default {
closeAll() {
this.historys = [
{
name: 'dashboard',
name: this.defaultRouter,
meta: {
title: '仪表盘'
title: '首页'
}
}
]
this.$router.push({ name: 'dashboard' })
this.$router.push({ name: this.defaultRouter })
this.contextMenuVisible = false
sessionStorage.setItem('historys', JSON.stringify(this.historys))
},
@@ -169,7 +179,7 @@ export default {
const index = this.historys.findIndex(item => item.name == tab)
if (this.$route.name == tab) {
if (this.historys.length == 1) {
this.$router.push({ name: 'dashboard' })
this.$router.push({ name: this.defaultRouter })
} else {
if (index < this.historys.length - 1) {
this.$router.push({ name: this.historys[index + 1].name,query:this.historys[index + 1].query,params:this.historys[index + 1].params })
@@ -13,12 +13,28 @@
node-key="ID"
ref="menuTree"
show-checkbox
></el-tree>
>
<span class="custom-tree-node" slot-scope="{ node , data }">
<span>{{ node.label }}</span>
<span>
<el-button
type="text"
size="mini"
:style="{color:row.defaultRouter == data.name?'#E6A23C':'#85ce61'}"
:disabled="!node.checked"
@click="() => setDefault(data)">
{{row.defaultRouter == data.name?"首页":"设为首页"}}
</el-button>
</span>
</span>
</el-tree>
</div>
</template>
<script>
import { getBaseMenuTree, getMenuAuthority, addMenuAuthority } from '@/api/menu'
import {
updateAuthority,
} from "@/api/authority";
export default {
name: 'Menus',
props: {
@@ -43,6 +59,13 @@ export default {
}
},
methods: {
async setDefault(data){
const res = await updateAuthority({authorityId: this.row.authorityId,AuthorityName: this.row.authorityName,parentId: this.row.parentId,defaultRouter:data.name})
if(res.code == 0){
this.$message({type:"success",message:"设置成功"})
this.row.defaultRouter = res.data.authority.defaultRouter
}
},
nodeChange(){
this.needConfirm = true
},