web
13 小时以前 d20fcd6ad28a534d763273c48381cdc36ff2891f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
 * @Author: Liuyi candymxq888@outlook.com
 * @Date: 2024-08-06 14:47:41
 * @LastEditors: Liuyi candymxq888@outlook.com
 * @LastEditTime: 2024-08-10 10:42:08
 * @FilePath: \water-qinghe-web\src\utils\permission.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import useUserStore from '@/store/modules/user'
 
/**
  * 
  * 按钮权限相关
  * 
  */
//定义自定义指令判断按钮权限
export const btnPerms = (app) => {
  app.directive('has', {
      mounted(el, binding) {
          if (!permsJudge(binding.value)) {
              el.parentNode.removeChild(el);
          }
          function permsJudge(value) {
              let perms = JSON.parse(localStorage.getItem("listPermission")|| '0');
              for (let i in perms) {
                  if(typeof value == 'object'){
                      let val = value[0]
                      let route = value[1]
                      if (route?.path == '/'+perms[i].split('.')[0] && perms[i].split('.')[1] == val ) {
                          return true;
                      }
                  }else{
                      if (perms[i] == value ) {
                          return true;
                      }
                  }
              }
              return false;
          }
      }
  });
}