feat: 添加菜单权限 (#730)
Some checks are pending
sync2gitee / repo-sync (push) Waiting to run
Typos Check / Spell Check with Typos (push) Waiting to run

This commit is contained in:
shaohuzhang1 2024-07-10 12:22:41 +08:00 committed by GitHub
parent db34290889
commit dd924964e8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 6 deletions

View File

@ -12,7 +12,7 @@
<span>{{ menu.meta?.title as string }}</span>
</template>
<sidebar-item
v-hasPermission="menu.meta?.permission"
v-hasPermission="child.meta?.permission"
v-for="(child, index) in menu?.children"
:key="index"
:menu="child"

View File

@ -1,6 +1,6 @@
import { hasPermission } from '@/utils/permission/index'
import Layout from '@/layout/layout-template/SystemLayout.vue'
import { Role } from '@/utils/permission/type'
import { Role, ComplexPermission } from '@/utils/permission/type'
const settingRouter = {
path: '/setting',
name: 'setting',
@ -74,7 +74,7 @@ const settingRouter = {
activeMenu: '/setting',
parentPath: '/setting',
parentName: 'setting',
permission: new Role('ADMIN')
permission: new ComplexPermission(['ADMIN'], ['x-pack'], 'AND')
},
component: () => import('@/views/theme/index.vue')
},
@ -86,7 +86,7 @@ const settingRouter = {
activeMenu: '/setting',
parentPath: '/setting',
parentName: 'setting',
permission: new Role('ADMIN')
permission: new ComplexPermission(['ADMIN'], ['x-pack'], 'AND')
},
component: () => import('@/views/authentication/index.vue')
},

View File

@ -8,6 +8,7 @@ export interface userStateTypes {
token: any
version?: string
accessToken?: string
XPACK_LICENSE_IS_VALID: false
isXPack: false
}
@ -18,11 +19,12 @@ const useUserStore = defineStore({
userInfo: null,
token: '',
version: '',
XPACK_LICENSE_IS_VALID: false,
isXPack: false
}),
actions: {
isEnterprise() {
return this.userInfo?.IS_XPACK && this.userInfo?.XPACK_LICENSE_IS_VALID
return this.isXPack && this.XPACK_LICENSE_IS_VALID
},
getToken(): String | null {
if (this.token) {
@ -40,7 +42,9 @@ const useUserStore = defineStore({
getPermissions() {
if (this.userInfo) {
return this.userInfo?.permissions
return this.isXPack && this.XPACK_LICENSE_IS_VALID
? [...this.userInfo?.permissions, 'x-pack']
: this.userInfo?.permissions
} else {
return []
}
@ -59,6 +63,8 @@ const useUserStore = defineStore({
async asyncGetVersion() {
return UserApi.getVersion().then((ok) => {
this.version = ok.data?.version || '-'
this.isXPack = ok.data?.IS_XPACK
this.XPACK_LICENSE_IS_VALID = ok.data?.XPACK_LICENSE_IS_VALID
})
},