浏览代码

Merge pull request #53 from aqa510415008/patch-1

feat: add `v-action:add`  action permission directive
Anan Yang 6 年之前
父节点
当前提交
87fdea169c
共有 1 个文件被更改,包括 34 次插入0 次删除
  1. 34 0
      src/permission.js

+ 34 - 0
src/permission.js

@@ -66,3 +66,37 @@ router.beforeEach((to, from, next) => {
 router.afterEach(() => {
   NProgress.done() // finish progress bar
 })
+
+
+
+
+/**Action 权限指令**/
+const action = Vue.directive('action', {
+  bind: function (el, binding, vnode) {
+    const actionName = binding.arg
+    const roles = store.getters.roles
+    const permissionId = vnode.context.$route.meta.permission
+    let actions = []
+    roles.permissions.forEach(p => {
+      if (p.permissionId != permissionId) {
+        return
+      }
+      actions = p.actionList
+    })
+    if (actions.indexOf(actionName) < 0) {
+      setTimeout(() => {
+        if(el.parentNode == null){
+          el.style.display = 'none'
+        }
+        else{
+            el.parentNode.removeChild(el)
+        }
+      }, 10)
+
+    }
+  }
+})
+
+export {
+  action
+}