rule.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // const update = function(el, binding, vnode) {
  2. // /** 从binding中获取dom元素的value值 */
  3. // const {
  4. // value
  5. // } = binding
  6. // /** 存放value值 */
  7. // const btn_permission = value;
  8. // /** 拿到所有具备权限按钮的集合,通过传入的按钮id进行匹配 */
  9. // const permissions = uni.getStorageSync('permissions');
  10. // /** 利用some查询,只要有一个元素满足条件就返回true,全部不满足返回false */
  11. // var hasPermissions = permissions.some(permission => {
  12. // return btn_permission == permission
  13. // })
  14. // console.log(hasPermissions, btn_permission);
  15. // /** 传入的按钮id不存在集合里面就移除该节点 */
  16. // if (!hasPermissions) {
  17. // el.parentNode && el.parentNode.removeChild(el)
  18. // }
  19. // }
  20. // //注册的一般写法,循环遍历directives,通过vue.directive注册
  21. // export default {
  22. // install(Vue) {
  23. // Vue.directive('permission', update);
  24. // // if (window.Vue) {
  25. // // window['permission'] = inserted
  26. // // Vue.use(install); // eslint-disable-line
  27. // // }
  28. // }
  29. // }
  30. export function permission(key) {
  31. const permissions = uni.getStorageSync('permissions') ?? [];
  32. if(permissions.indexOf(key) !== -1) {
  33. return true;
  34. } else {
  35. return false;
  36. }
  37. }