新增has的directive
This commit is contained in:
parent
7414bc492e
commit
093ef6cb8a
@ -1,3 +1,4 @@
|
|||||||
|
import has from './permission/has'
|
||||||
import hasRole from './permission/hasRole'
|
import hasRole from './permission/hasRole'
|
||||||
import hasPermi from './permission/hasPermi'
|
import hasPermi from './permission/hasPermi'
|
||||||
import dialogDrag from './dialog/drag'
|
import dialogDrag from './dialog/drag'
|
||||||
@ -6,6 +7,7 @@ import dialogDragHeight from './dialog/dragHeight'
|
|||||||
import clipboard from './module/clipboard'
|
import clipboard from './module/clipboard'
|
||||||
|
|
||||||
const install = function(Vue) {
|
const install = function(Vue) {
|
||||||
|
Vue.directive('has', hasRole)
|
||||||
Vue.directive('hasRole', hasRole)
|
Vue.directive('hasRole', hasRole)
|
||||||
Vue.directive('hasPermi', hasPermi)
|
Vue.directive('hasPermi', hasPermi)
|
||||||
Vue.directive('clipboard', clipboard)
|
Vue.directive('clipboard', clipboard)
|
||||||
|
50
ruoyi-ui/src/directive/permission/has.js
Normal file
50
ruoyi-ui/src/directive/permission/has.js
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/**
|
||||||
|
* v-has 操作权限处理
|
||||||
|
* Copyright (c) 2022 码农小易
|
||||||
|
*/
|
||||||
|
|
||||||
|
import store from '@/store'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
inserted(el, binding, vnode) {
|
||||||
|
const { value } = binding;
|
||||||
|
const all_permission = "*:*:*";
|
||||||
|
const super_admin = "admin";
|
||||||
|
|
||||||
|
const permissions = store.getters && store.getters.permissions
|
||||||
|
const roles = store.getters && store.getters.roles
|
||||||
|
|
||||||
|
const R = /R\((.*?)\)/g;
|
||||||
|
const Rs = value.match(R) || [];
|
||||||
|
|
||||||
|
const P = /P\((.*?)\)/g;
|
||||||
|
const Ps = value.match(P) || [];
|
||||||
|
|
||||||
|
if (Ps.length === 0 || Rs.length === 0){
|
||||||
|
throw new Error(`请设置操作权限标签值`);
|
||||||
|
}
|
||||||
|
|
||||||
|
var expression = value;
|
||||||
|
|
||||||
|
for (let i = 0; i < Rs.length; i++) {
|
||||||
|
const hasRole = roles.some(role => {
|
||||||
|
return super_admin === role || Rs[i] === `R(${role})`;
|
||||||
|
})
|
||||||
|
|
||||||
|
expression = hasRole ? expression.replace(Rs[i], 'true') : expression.replace(Rs[i], 'false');
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < Ps.length; i++) {
|
||||||
|
const hasPermi = permissions.some(permission => {
|
||||||
|
return all_permission === permission || Ps[i] === `P(${permission})`;
|
||||||
|
})
|
||||||
|
|
||||||
|
expression = hasPermi ? expression.replace(Ps[i], 'true') : expression.replace(Ps[i], 'false');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!eval(expression)) {
|
||||||
|
el.parentNode && el.parentNode.removeChild(el);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user