mirror of
https://github.com/jumpserver/lina.git
synced 2026-01-29 21:28:52 +00:00
feat: 修改权限和路由的计算方法
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
<script>
|
||||
import { mapGetters } from 'vuex'
|
||||
import { hasUUID } from '@/utils/common'
|
||||
import rolec from '@/utils/role'
|
||||
export default {
|
||||
props: {
|
||||
isCollapse: {
|
||||
@@ -41,8 +42,8 @@ export default {
|
||||
'currentRole',
|
||||
'userAdminOrgList'
|
||||
]),
|
||||
hasOrgPermission() {
|
||||
return this.currentRole === 'Admin'
|
||||
inAdminPage() {
|
||||
return (this.currentRole & rolec.PERM_USE) !== rolec.PERM_USE
|
||||
},
|
||||
orgIdMapper() {
|
||||
const mapper = {}
|
||||
@@ -53,13 +54,13 @@ export default {
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
if (this.hasOrgPermission) {
|
||||
if (this.inAdminPage) {
|
||||
this.checkCurrentOrgIsNeedChange()
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
needShow() {
|
||||
return !this.isCollapse && this.userAdminOrgList.length > 1 && this.hasOrgPermission
|
||||
return !this.isCollapse && this.userAdminOrgList.length > 1 && this.inAdminPage
|
||||
},
|
||||
checkCurrentOrgIsNeedChange() {
|
||||
if (!this.currentOrg || typeof this.currentOrg !== 'object') {
|
||||
|
||||
@@ -8,12 +8,14 @@
|
||||
</span>
|
||||
<el-dropdown-menu slot="dropdown">
|
||||
<el-dropdown-item icon="el-icon-user" command="profile">{{ $t('common.nav.Profile') }}</el-dropdown-item>
|
||||
<el-dropdown-item v-if="isInAdminRole && hasAdminRole " icon="el-icon-guide" command="userPage">
|
||||
{{ $t('common.nav.UserPage') }}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item v-if="!isInAdminRole && hasAdminRole " icon="el-icon-guide" command="adminPage">
|
||||
{{ $t('common.nav.AdminPage') }}
|
||||
</el-dropdown-item>
|
||||
<div v-if="currentOrgRoles.length > 1">
|
||||
<el-dropdown-item v-if="isInAdminRole " icon="el-icon-guide" command="userPage">
|
||||
{{ $t('common.nav.UserPage') }}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item v-else icon="el-icon-guide" command="adminPage">
|
||||
{{ $t('common.nav.AdminPage') }}
|
||||
</el-dropdown-item>
|
||||
</div>
|
||||
<el-dropdown-item icon="el-icon-key" command="apiKey">{{ $t('common.nav.APIKey') }}</el-dropdown-item>
|
||||
<el-dropdown-item divided command="logout">{{ $t('common.nav.Logout') }}</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
@@ -25,6 +27,7 @@
|
||||
<script>
|
||||
import { mapGetters } from 'vuex'
|
||||
import ApiKey from './ApiKey'
|
||||
import rolec from '@/utils/role'
|
||||
|
||||
export default {
|
||||
name: 'AccountDropdown',
|
||||
@@ -39,17 +42,21 @@ export default {
|
||||
},
|
||||
computed: {
|
||||
isInAdminRole() {
|
||||
return this.currentRole === 'Admin'
|
||||
console.log(this.currentRole)
|
||||
return (this.currentRole & rolec.PERM_ADMIN) === rolec.PERM_ADMIN
|
||||
},
|
||||
hasAdminRole() {
|
||||
return this.getCurrentOrgRoles.includes('Admin')
|
||||
return this.currentOrgRoles.includes('Admin')
|
||||
},
|
||||
...mapGetters([
|
||||
'currentUser',
|
||||
'currentRole',
|
||||
'getCurrentOrgRoles'
|
||||
'currentOrgRoles'
|
||||
])
|
||||
},
|
||||
mounted() {
|
||||
console.log('Roles: ', this.currentOrgRoles)
|
||||
},
|
||||
methods: {
|
||||
handleClick(val) {
|
||||
switch (val) {
|
||||
@@ -57,11 +64,12 @@ export default {
|
||||
this.$router.push({ name: 'UserProfile' })
|
||||
break
|
||||
case 'adminPage':
|
||||
this.$store.dispatch('users/setCurrentRole', 'Admin')
|
||||
this.$store.dispatch('users/setCurrentRole', this.currentOrgRoles[0])
|
||||
window.location.href = `/ui/`
|
||||
break
|
||||
case 'userPage':
|
||||
this.$store.dispatch('users/setCurrentRole', 'User')
|
||||
this.$store.dispatch('users/setCurrentRole', this.currentOrgRoles[1])
|
||||
console.log('Switch to: ', this.currentOrgRoles[1])
|
||||
window.location.href = `/ui/`
|
||||
break
|
||||
case 'logout':
|
||||
|
||||
Reference in New Issue
Block a user