import store from '@/store'
import { Local } from "@/utils/storage";

import SystemConfig from "@/utils/SystemConfig";

export default {
  inserted(el, binding, vnode) {
    const { value } = binding;
    const roles = Local.get(SystemConfig.adminAccess);
    if (roles)
      if (value && value instanceof Array && value.length > 0) {
        const permissionRoles = value;
        let hasPermission = roles.some(role => {
          return permissionRoles.includes(role)
        });
        if (!hasPermission) {
          el.classList.add('is-disabled');
          el.disabled = true;
          vnode.componentInstance.$off('click')
        }
      } else {
        console.warn('为了安全起见还是需要配置权限访问【need roles! Like v-permission="[\'admin\',\'editor】')
        throw new Error(`need roles! Like v-permission="['admin','editor']"`)
      }
  },
}
