import {ref} from 'vue'
import {apiSystemUser} from '@/api/system'

const authList=ref([])
const authCodeOpts=ref([])

export function usePermission(){

  function getPermissionData(){
    apiSystemUser.userPermissionData().then(res=>{
      if(res.Ret===200){
        authList.value=res.Data||[]
        authCodeOpts.value=authList.value.map(item => item.ButtonCode);
      }
    })
  }

  function hasPermission(btn){
    return authCodeOpts.value.includes(btn)
  }



  return {
    authList,
    authCodeOpts,
    getPermissionData,
    hasPermission,
  }
}