const btnList = [
  { label: '', type: '', disFlag: '' },
  { label: '新增', type: 'add', disFlag: 'is_add', icon: 'icon-add' },
  { label: '查看', type: 'read', disFlag: 'is_view' },
  { label: '修改', type: 'edit', disFlag: 'is_edit' },
  { label: '删除', type: 'del', disFlag: 'is_del', icon: 'icon-del' },
  { label: '导出', type: 'output', disFlag: 'is_edit', icon: 'icon-add' }
]
function findNodeByRoute(tree, targetRoute) {
  for (const node of tree) {
    if (node.route === targetRoute) {
      return node // 找到目标节点
    }
    if (node.children && node.children.length > 0) {
      const found = findNodeByRoute(node.children, targetRoute) // 递归检查子节点
      if (found) return found
    }
  }
  return null // 未找到
}
function getBtns(arr) {
  const curPermission = findNodeByRoute(
    JSON.parse(localStorage.getItem('permission')),
    '/' + this.$route.name
  )
  // console.log(findNodeByRoute(JSON.parse(localStorage.getItem('permission')), '/user'), '55')

  // console.log(this.$route, curPermission, localStorage.getItem('permission'), 'curPermission')
  const btns = []
  // console.log(curPermission, 'curPermission')
  btnList.forEach((item) => {
    console.log(item.disFlag, curPermission[item.disFlag], 'curPermission[item.disFlag]')
    if (arr.includes(item.label)) {
      // item.disabled = true
      item.disabled = !Boolean(+curPermission[item.disFlag])
      btns.push(item)
    }
  })
  return btns
}

export { btnList, getBtns }
