mirror of
https://github.com/iczer/vue-antd-admin
synced 2025-04-06 04:00:06 +08:00
fix: the problem that v-auth directive doesn't take effect in native html element; 🐛
修复:v-auth 指令在原生 HTML 元素上不生效的 bug;
This commit is contained in:
parent
38363f2ec2
commit
4241156903
@ -42,33 +42,33 @@ const auth = function(authConfig, permission, role, permissions, roles) {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 阻止的 click 事件监听
|
|
||||||
* @param event
|
|
||||||
* @returns {boolean}
|
|
||||||
*/
|
|
||||||
const preventClick = function (event) {
|
|
||||||
event.preventDefault()
|
|
||||||
event.stopPropagation()
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
const checkInject = function (el, binding,vnode) {
|
const checkInject = function (el, binding,vnode) {
|
||||||
const type = binding.arg
|
const type = binding.arg
|
||||||
const check = binding.value
|
const check = binding.value
|
||||||
const instance = vnode.context
|
const instance = vnode.context
|
||||||
const $auth = instance.$auth
|
const $auth = instance.$auth
|
||||||
if (!$auth || !$auth(check, type)) {
|
if (!$auth || !$auth(check, type)) {
|
||||||
el.classList.add('disabled')
|
addDisabled(el)
|
||||||
el.setAttribute('title', '无此权限')
|
|
||||||
el.addEventListener('click', preventClick, true)
|
|
||||||
} else {
|
} else {
|
||||||
el.classList.remove('disabled')
|
removeDisabled(el)
|
||||||
el.removeAttribute('title')
|
|
||||||
el.removeEventListener('click', preventClick, true)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const addDisabled = function (el) {
|
||||||
|
if (el.tagName === 'BUTTON') {
|
||||||
|
el.setAttribute('disabled', 'disabled')
|
||||||
|
} else {
|
||||||
|
el.classList.add('disabled')
|
||||||
|
}
|
||||||
|
el.setAttribute('title', '无此权限')
|
||||||
|
}
|
||||||
|
|
||||||
|
const removeDisabled = function (el) {
|
||||||
|
el.classList.remove('disabled')
|
||||||
|
el.removeAttribute('disabled')
|
||||||
|
el.removeAttribute('title')
|
||||||
|
}
|
||||||
|
|
||||||
const AuthorityPlugin = {
|
const AuthorityPlugin = {
|
||||||
install(Vue) {
|
install(Vue) {
|
||||||
Vue.directive('auth', {
|
Vue.directive('auth', {
|
||||||
@ -77,6 +77,9 @@ const AuthorityPlugin = {
|
|||||||
},
|
},
|
||||||
update(el, binding,vnode) {
|
update(el, binding,vnode) {
|
||||||
checkInject(el, binding, vnode)
|
checkInject(el, binding, vnode)
|
||||||
|
},
|
||||||
|
unbind(el) {
|
||||||
|
removeDisabled(el)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
Vue.mixin({
|
Vue.mixin({
|
||||||
|
@ -36,6 +36,9 @@ function parseRoutes(routesConfig, routerMap) {
|
|||||||
page: routeCfg.page || router.page
|
page: routeCfg.page || router.page
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (routeCfg.invisible || router.invisible) {
|
||||||
|
route.meta.invisible = true
|
||||||
|
}
|
||||||
if (routeCfg.children && routeCfg.children.length > 0) {
|
if (routeCfg.children && routeCfg.children.length > 0) {
|
||||||
route.children = parseRoutes(routeCfg.children, routerMap)
|
route.children = parseRoutes(routeCfg.children, routerMap)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user