|
@@ -0,0 +1,51 @@
|
|
|
+//按钮权限指令
|
|
|
+//eg: v-permission="buttonCode"
|
|
|
+import {useAuthBtnStore} from '@/store/modules/authBtn'
|
|
|
+export default {
|
|
|
+ mounted(el, binding) {
|
|
|
+ let {
|
|
|
+ value
|
|
|
+ } = binding
|
|
|
+ // 拿出所有按钮的code
|
|
|
+ const authBtnStore = useAuthBtnStore()
|
|
|
+ let buttonCodes = authBtnStore.authBtnList.map(item => item.ButtonCode)
|
|
|
+ console.log('test',buttonCodes)
|
|
|
+ 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指令参数类型错误')
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+}
|