feat: 添加菜单权限 (#730)

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

View File

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

View File

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