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

支持不同角色自定义首页

上级 39bdd95f
...@@ -14,4 +14,5 @@ type SysAuthority struct { ...@@ -14,4 +14,5 @@ type SysAuthority struct {
DataAuthorityId []SysAuthority `json:"dataAuthorityId" gorm:"many2many:sys_data_authority_id"` DataAuthorityId []SysAuthority `json:"dataAuthorityId" gorm:"many2many:sys_data_authority_id"`
Children []SysAuthority `json:"children" gorm:"-"` Children []SysAuthority `json:"children" gorm:"-"`
SysBaseMenus []SysBaseMenu `json:"menus" gorm:"many2many:sys_authority_menus;"` 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) => { ...@@ -13,7 +13,7 @@ router.beforeEach(async(to, from, next) => {
document.title = getPageTitle(to.meta.title) document.title = getPageTitle(to.meta.title)
if (whiteList.indexOf(to.name) > -1) { if (whiteList.indexOf(to.name) > -1) {
if (token) { if (token) {
next({ path: '/layout/dashboard' }) next({ name: store.getters["user/userInfo"].authority.defaultRouter })
} else { } else {
next() next()
} }
...@@ -21,7 +21,7 @@ router.beforeEach(async(to, from, next) => { ...@@ -21,7 +21,7 @@ router.beforeEach(async(to, from, next) => {
// 不在白名单中并且已经登陆的时候 // 不在白名单中并且已经登陆的时候
if (token) { if (token) {
// 添加flag防止多次获取动态路由和栈溢出 // 添加flag防止多次获取动态路由和栈溢出
if (!asyncRouterFlag) { if (!asyncRouterFlag && store.getters['router/asyncRouters'].length == 0) {
asyncRouterFlag++ asyncRouterFlag++
await store.dispatch('router/SetAsyncRouter') await store.dispatch('router/SetAsyncRouter')
const asyncRouters = store.getters['router/asyncRouters'] const asyncRouters = store.getters['router/asyncRouters']
......
...@@ -28,7 +28,7 @@ export const router = { ...@@ -28,7 +28,7 @@ export const router = {
// 设置动态路由 // 设置动态路由
setAsyncRouter(state, asyncRouters) { setAsyncRouter(state, asyncRouters) {
state.asyncRouters = asyncRouters state.asyncRouters = asyncRouters
} },
}, },
actions: { actions: {
// 从后台获取动态路由 // 从后台获取动态路由
...@@ -73,6 +73,9 @@ export const router = { ...@@ -73,6 +73,9 @@ export const router = {
}, },
routerList(state) { routerList(state) {
return state.routerList return state.routerList
},
defaultRouter(state) {
return state.defaultRouter
} }
} }
} }
\ No newline at end of file
...@@ -35,16 +35,19 @@ export const user = { ...@@ -35,16 +35,19 @@ export const user = {
} }
}, },
actions: { actions: {
async LoginIn({ commit }, loginInfo) { async LoginIn({ commit, dispatch, rootGetters, getters }, loginInfo) {
const res = await login(loginInfo) const res = await login(loginInfo)
if (res.code == 0) { if (res.code == 0) {
commit('setUserInfo', res.data.user) commit('setUserInfo', res.data.user)
commit('setToken', res.data.token) 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 const redirect = router.history.current.query.redirect
if (redirect) { if (redirect) {
router.push({ path: redirect }) router.push({ path: redirect })
} else { } else {
router.push({ path: '/layout/dashboard' }) router.push({ name: getters["userInfo"].authority.defaultRouter })
} }
return true return true
} }
......
<template> <template>
<div class="router-history"> <div class="router-history">
<el-tabs <el-tabs
:closable="!(historys.length==1&&this.$route.name=='dashboard')" :closable="!(historys.length==1&&this.$route.name==defaultRouter)"
@contextmenu.prevent.native="openContextMenu($event)" @contextmenu.prevent.native="openContextMenu($event)"
@tab-click="changeTab" @tab-click="changeTab"
@tab-remove="removeTab" @tab-remove="removeTab"
...@@ -27,12 +27,14 @@ ...@@ -27,12 +27,14 @@
</div> </div>
</template> </template>
<script> <script>
import {mapGetters} from "vuex"
export default { export default {
name: 'HistoryComponent', name: 'HistoryComponent',
data() { data() {
return { return {
historys: [], historys: [],
activeValue: 'dashboard', activeValue: '',
contextMenuVisible: false, contextMenuVisible: false,
left: 0, left: 0,
top: 0, top: 0,
...@@ -41,7 +43,15 @@ export default { ...@@ -41,7 +43,15 @@ export default {
rightActive: '' rightActive: ''
} }
}, },
computed:{
...mapGetters("user",["userInfo"]),
defaultRouter(){
return this.userInfo.authority.defaultRouter
}
},
created() { created() {
this.activeValue = this.defaultRouter
this.$bus.on('mobile', isMobile => { this.$bus.on('mobile', isMobile => {
this.isMobile = isMobile this.isMobile = isMobile
}) })
...@@ -50,9 +60,9 @@ export default { ...@@ -50,9 +60,9 @@ export default {
}) })
const initHistorys = [ const initHistorys = [
{ {
name: 'dashboard', name: this.defaultRouter,
meta: { meta: {
title: '仪表盘' title: '首页'
} }
} }
] ]
...@@ -67,7 +77,7 @@ export default { ...@@ -67,7 +77,7 @@ export default {
}, },
methods: { methods: {
openContextMenu(e) { openContextMenu(e) {
if (this.historys.length == 1 && this.$route.name == 'dashboard') { if (this.historys.length == 1 && this.$route.name == this.defaultRouter) {
return false return false
} }
if (e.srcElement.id) { if (e.srcElement.id) {
...@@ -89,13 +99,13 @@ export default { ...@@ -89,13 +99,13 @@ export default {
closeAll() { closeAll() {
this.historys = [ this.historys = [
{ {
name: 'dashboard', name: this.defaultRouter,
meta: { meta: {
title: '仪表盘' title: '首页'
} }
} }
] ]
this.$router.push({ name: 'dashboard' }) this.$router.push({ name: this.defaultRouter })
this.contextMenuVisible = false this.contextMenuVisible = false
sessionStorage.setItem('historys', JSON.stringify(this.historys)) sessionStorage.setItem('historys', JSON.stringify(this.historys))
}, },
...@@ -169,7 +179,7 @@ export default { ...@@ -169,7 +179,7 @@ export default {
const index = this.historys.findIndex(item => item.name == tab) const index = this.historys.findIndex(item => item.name == tab)
if (this.$route.name == tab) { if (this.$route.name == tab) {
if (this.historys.length == 1) { if (this.historys.length == 1) {
this.$router.push({ name: 'dashboard' }) this.$router.push({ name: this.defaultRouter })
} else { } else {
if (index < this.historys.length - 1) { 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 }) 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 @@ ...@@ -13,12 +13,28 @@
node-key="ID" node-key="ID"
ref="menuTree" ref="menuTree"
show-checkbox 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> </div>
</template> </template>
<script> <script>
import { getBaseMenuTree, getMenuAuthority, addMenuAuthority } from '@/api/menu' import { getBaseMenuTree, getMenuAuthority, addMenuAuthority } from '@/api/menu'
import {
updateAuthority,
} from "@/api/authority";
export default { export default {
name: 'Menus', name: 'Menus',
props: { props: {
...@@ -43,6 +59,13 @@ export default { ...@@ -43,6 +59,13 @@ export default {
} }
}, },
methods: { 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(){ nodeChange(){
this.needConfirm = true this.needConfirm = true
}, },
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册