feat: add directive[v-action]
This commit is contained in:
parent
a6a671def5
commit
192e2f512f
6
resources/admin/directives/index.ts
Normal file
6
resources/admin/directives/index.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import type { App } from 'vue'
|
||||||
|
|
||||||
|
import action from './permission/action'
|
||||||
|
export function bootstrapDirectives(app: App): void {
|
||||||
|
app.directive('action', action)
|
||||||
|
}
|
33
resources/admin/directives/permission/action.ts
Normal file
33
resources/admin/directives/permission/action.ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import { useUserStore } from '/admin/stores/modules/user'
|
||||||
|
import { MenuType } from '/admin/enum/app'
|
||||||
|
function checkAction(el: any, action: any) {
|
||||||
|
if (action.value && typeof action.value === 'string') {
|
||||||
|
const userStore = useUserStore()
|
||||||
|
const permissions = userStore.getPermissions
|
||||||
|
|
||||||
|
action = action.value.replace('@', '.').toLowerCase()
|
||||||
|
const hasAction = permissions?.some(permission => {
|
||||||
|
if (permission.type === MenuType.Button_Type) {
|
||||||
|
const a: string = permission.module + '.' + permission.permission_mark.replace('@', '.')
|
||||||
|
return action === a.toLowerCase()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!hasAction) {
|
||||||
|
// el.style.display = 'none'
|
||||||
|
el.parentNode && el.parentNode.removeChild(el)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Error(`need action! Like v-action="module.controller.action" || v-action="module@controller@action" `)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
mounted(el: any, binding: any) {
|
||||||
|
checkAction(el, binding)
|
||||||
|
},
|
||||||
|
|
||||||
|
updated(el: any, binding: any) {
|
||||||
|
checkAction(el, binding)
|
||||||
|
},
|
||||||
|
}
|
@ -8,6 +8,7 @@ import { bootstrapStore } from '/admin/stores'
|
|||||||
import Cache from './cache'
|
import Cache from './cache'
|
||||||
import { bootstrapI18n } from '/admin/i18n'
|
import { bootstrapI18n } from '/admin/i18n'
|
||||||
import guard from '/admin/router/guard'
|
import guard from '/admin/router/guard'
|
||||||
|
import { bootstrapDirectives } from '/admin/directives'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* catchadmin
|
* catchadmin
|
||||||
@ -31,7 +32,7 @@ export default class CatchAdmin {
|
|||||||
* admin boot
|
* admin boot
|
||||||
*/
|
*/
|
||||||
bootstrap(): void {
|
bootstrap(): void {
|
||||||
this.useElementPlus().usePinia().useI18n().useRouter().mount()
|
this.useElementPlus().usePinia().useI18n().installDirectives().useRouter().mount()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -86,4 +87,15 @@ export default class CatchAdmin {
|
|||||||
|
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* install directives
|
||||||
|
*
|
||||||
|
* @protected
|
||||||
|
*/
|
||||||
|
protected installDirectives(): CatchAdmin {
|
||||||
|
bootstrapDirectives(this.app)
|
||||||
|
|
||||||
|
return this
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user