Skip to content

Commit

Permalink
feat: add usePermission composable
Browse files Browse the repository at this point in the history
  • Loading branch information
flingyp committed Sep 8, 2023
1 parent 189af69 commit 20be43a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/composables/common/usePermission/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const usePermission = (permissionKeys: string[]) => {
const routeMenuStore = useRouteMenuStore()
const { account } = storeToRefs(routeMenuStore)
const accountPermissionList = account.value.permissions
const isHavePermission = permissionKeys.every((permission) => {
if (accountPermissionList.includes(permission)) return true
return false
})
return isHavePermission
}
2 changes: 1 addition & 1 deletion src/directives/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { App } from 'vue'

import permissionDirective from './permission-button'
import permissionDirective from './permission'

export default async (app: App) => {
permissionDirective(app)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export default (app: App) => {
app.directive('permission', (el: HTMLElement, binding: DirectiveBinding<string | string[]>) => {
const { account } = storeToRefs(useRouteMenuStore())
const accountPermissionList = account.value.permissions
const buttonPermissionList = typeof binding.value === 'string' ? [binding.value] : binding.value
const isHavePermission = buttonPermissionList.every((permission) => {
const permissionList = typeof binding.value === 'string' ? [binding.value] : binding.value
const isHavePermission = permissionList.every((permission) => {
if (accountPermissionList.includes(permission)) return true
return false
})
Expand Down

0 comments on commit 20be43a

Please sign in to comment.