提交 057163b3 编写于 作者: Mr.奇淼('s avatar Mr.奇淼(

支持不同角色自定义首页

上级 39bdd95f
......@@ -14,4 +14,5 @@ type SysAuthority struct {
DataAuthorityId []SysAuthority `json:"dataAuthorityId" gorm:"many2many:sys_data_authority_id"`
Children []SysAuthority `json:"children" gorm:"-"`
SysBaseMenus []SysBaseMenu `json:"menus" gorm:"many2many:sys_authority_menus;"`
DefaultRouter string `json:"defaultRouter" gorm:"comment:默认菜单;default:dashboard"`
}
......@@ -13,7 +13,7 @@ router.beforeEach(async(to, from, next) => {
document.title = getPageTitle(to.meta.title)
if (whiteList.indexOf(to.name) > -1) {
if (token) {
next({ path: '/layout/dashboard' })
next({ name: store.getters["user/userInfo"].authority.defaultRouter })
} else {
next()
}
......@@ -21,7 +21,7 @@ router.beforeEach(async(to, from, next) => {
// 不在白名单中并且已经登陆的时候
if (token) {
// 添加flag防止多次获取动态路由和栈溢出
if (!asyncRouterFlag) {
if (!asyncRouterFlag && store.getters['router/asyncRouters'].length == 0) {
asyncRouterFlag++
await store.dispatch('router/SetAsyncRouter')
const asyncRouters = store.getters['router/asyncRouters']
......
......@@ -28,7 +28,7 @@ export const router = {
// 设置动态路由
setAsyncRouter(state, asyncRouters) {
state.asyncRouters = asyncRouters
}
},
},
actions: {
// 从后台获取动态路由
......@@ -73,6 +73,9 @@ export const router = {
},
routerList(state) {
return state.routerList
},
defaultRouter(state) {
return state.defaultRouter
}
}
}
\ No newline at end of file
......@@ -35,16 +35,19 @@ export const user = {
}
},
actions: {
async LoginIn({ commit }, loginInfo) {
async LoginIn({ commit, dispatch, rootGetters, getters }, loginInfo) {
const res = await login(loginInfo)
if (res.code == 0) {
commit('setUserInfo', res.data.user)
commit('setToken', res.data.token)
await dispatch('router/SetAsyncRouter', {}, { root: true })
const asyncRouters = rootGetters['router/asyncRouters']
router.addRoutes(asyncRouters)
const redirect = router.history.current.query.redirect
if (redirect) {
router.push({ path: redirect })
} else {
router.push({ path: '/layout/dashboard' })
router.push({ name: getters["userInfo"].authority.defaultRouter })
}
return true
}
......
<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
},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册