<template>
  <el-button v-if="hasPermission" v-bind="$attrs" @click="$emit('click')">
    <slot />
  </el-button>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { usePermissionStore } from '@/stores/permission'
import { hasAuthCode } from '@/utils/global'

const props = defineProps<{
  code?: string
}>()

defineEmits(['click'])

const permStore = usePermissionStore()

const hasPermission = computed(() => {
  if (!props.code) return true
  return hasAuthCode(props.code)
})
</script>
