export function hasPriv(code) {
  let raw = sessionStorage.getItem('privItem');
  if (!raw) {
    raw = sessionStorage.getItem('privCollect');
  }
  if (!raw) return false;
  const privObj = JSON.parse(raw);
  if (!privObj) return false;
  // 根节点可能是数组，遍历所有顶层节点
  if (Array.isArray(privObj)) {
    for (const item of privObj) {
      if (hasPermission(item, code)) {
        console.log('[hasPriv] code:', code, 'result: true');
        return true;
      }
    }
    console.log('[hasPriv] code:', code, 'result: false');
    return false;
  }
  const result = hasPermission(privObj, code);
  console.log('[hasPriv] code:', code, 'result:', result);
  return result;
}
function hasPermission(privItem, code) {
  if (!privItem) return false;
  if (code == privItem.code) {
    return true;
  }
  const children = privItem.privList || [];
  for (var index = 0; index < children.length; index++) {
    var result = hasPermission(children[index], code);
    if (result) {
      return true;
    }
  }
  return false;
}
