index.vue 1.28 KB
<template>
  <el-button
    v-if="hasPermission()"
    :type="type"
    :icon="icon"
    :loading="loading"
    :disabled="disabled"
    size="small"
    @click="clickEvent"
  >
    <slot />
  </el-button>
</template>
<script>
export default {
  name: 'AuthButton',
  props: {
    uid: {
      type: [String, Number],
      default: ''
    },
    type: {
      type: [String, Number],
      default: 'default'
    },
    link: {
      type: Boolean,
      default: false
    },
    icon: {
      type: String,
      default: ''
    },
    loading: {
      type: Boolean,
      default: false
    },
    disabled: {
      type: Boolean,
      default: false
    },
    url: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      currentPath: this.$route.path
    }
  },
  mounted() {},
  methods: {
    // 判断是否有权限
    hasPermission() {
      const id = this.uid
      const list = this.$Common.filterAsycRouter(
        this.$store.getters.asycRouters,
        this.url || this.currentPath
      )
      const idx = list.findIndex((k) => k.rightDes == id)
      if (idx < 0) {
        return false
      } else {
        return true
      }
    },

    // 点击事件
    clickEvent() {
      this.$emit('click')
    }

  }
}
</script>
  <style lang="scss" scoped>
</style>