d2-auth-btn.vue 1.52 KB
<template>
  <el-button
    :size="size"
    :type="type"
    :loading="loading"
    v-if="isInRole"
    @click="handleClick"
  >{{label}}
    <input v-if="label == '导入'"
      type="file"
      class="import-input"
      :accept="accept"
      @change="handleImport" />
  </el-button>
</template>

<script>
import { mapGetters } from 'vuex'
export default {
  name: 'AuthButton',
  props: {
    label: {
      type: String,
      default: 'Button'
    },
    size: {
      type: String,
      default: 'mini'
    },
    type: {
      type: String,
      default: 'text'
    },
    loading: {
      type: Boolean,
      default: false
    },
    disabled: {
      type: Boolean,
      default: false
    },
    id: {
      type: String,
      default: null
    },
    accept: {
      type: String,
      default: null
    }
  },
  computed: {
    ...mapGetters('d2admin/auth', ['curBtns'])
  },
  data () {
    return {
      isInRole: false
    }
  },
  created () {
    //  this.$vrm.setRoles(this.btnIdAll)
    if(this.curBtns){
      // const { action, operation } = this.curBtns
      // console.log(this.label);
      this.isInRole = this.curBtns.find(obj => obj.id === this.id || obj.label === this.label)
    }
  },
  methods: {
    handleClick: function () {
      this.$emit('e-auth-click', {})
    },
    handleImport(e) {
      this.$emit('import-file', e)
    }
  }
}
</script>

<style scoped>
.import-input {
  opacity: 0;
  position: absolute;
  left: 0;
  top: 0;
  width: 70px;
  height: 100%;
  cursor: pointer;
  font-size:0
}
</style>