|
@@ -0,0 +1,45 @@
|
|
|
+//按钮权限判断指令
|
|
|
+import Vue from 'vue';
|
|
|
+import {store} from "../main";
|
|
|
+Vue.directive('permission',{
|
|
|
+ inserted(el,binding){
|
|
|
+ const buttonCodes = store.state.permissionButton.permissionButtons.map(item=>item.button_code)
|
|
|
+ const {value} = binding
|
|
|
+ if(value && typeof(value)=='string'){
|
|
|
+ // 字符类型
|
|
|
+ if(!buttonCodes.includes(value)){
|
|
|
+ // 没有权限,删除dom
|
|
|
+ el.parentNode && el.parentNode.removeChild(el)
|
|
|
+ }
|
|
|
+ }else if(Array.isArray(value)){
|
|
|
+ // 数组类型
|
|
|
+ /**
|
|
|
+ * 权限类型 type
|
|
|
+ * or-只要一个满足 and-全部都满足
|
|
|
+ */
|
|
|
+ let type;
|
|
|
+ let hasType=['or','and'].includes(value[value.length-1].toLocaleLowerCase())
|
|
|
+ if(hasType){
|
|
|
+ //参数中有标明type
|
|
|
+ type=value[value.length-1].toLocaleLowerCase()
|
|
|
+ // 去掉最后一个权限类型参数
|
|
|
+ value.pop()
|
|
|
+ // console.log(value,true);
|
|
|
+ let operation = type=='or'?'some':'every'
|
|
|
+ if(!value[operation](item => buttonCodes.includes(item))){
|
|
|
+ // 没有权限,删除dom
|
|
|
+ el.parentNode && el.parentNode.removeChild(el)
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ type='or'
|
|
|
+ // console.log(value,false);
|
|
|
+ if(!value.some(item => buttonCodes.includes(item))){
|
|
|
+ // 没有权限,删除dom
|
|
|
+ el.parentNode && el.parentNode.removeChild(el)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ throw new Error('permission指令参数类型错误')
|
|
|
+ }
|
|
|
+ }
|
|
|
+})
|