import Vue from 'vue';

function getPermission(permission, permissionObj) {
  if (!permissionObj) return true;

  if (permission instanceof Array) return permission.find(item => {
    return permissionObj[item]
  });
  return permissionObj[permission];
}

function permissionInit(value) {
  let items = ['AllowView', 'AllowAdd', 'AllowEdit', 'AllowDel'];
  let _items = ['allowView', 'allowAdd', 'allowEdit', 'allowDel'];
  let permission = [];
  items.forEach(function (item) {
    permission.push(getPermission(item,value));
  });
  permission.forEach(function (item, index) {
    Vue.prototype[_items[index]] = item;
    // console.log(_items[index], item);
  });

}
export default permissionInit