XButton.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <script lang="ts" name="XButton" setup>
  2. import { PropType } from 'vue'
  3. import { propTypes } from '@/utils/propTypes'
  4. const props = defineProps({
  5. modelValue: propTypes.bool.def(false),
  6. loading: propTypes.bool.def(false),
  7. preIcon: propTypes.string.def(''),
  8. postIcon: propTypes.string.def(''),
  9. title: propTypes.string.def(''),
  10. type: propTypes.oneOf(['', 'primary', 'success', 'warning', 'danger', 'info']).def(''),
  11. link: propTypes.bool.def(false),
  12. circle: propTypes.bool.def(false),
  13. round: propTypes.bool.def(false),
  14. plain: propTypes.bool.def(false),
  15. onClick: { type: Function as PropType<(...args) => any>, default: null }
  16. })
  17. const getBindValue = computed(() => {
  18. const delArr: string[] = ['title', 'preIcon', 'postIcon', 'onClick']
  19. const attrs = useAttrs()
  20. const obj = { ...attrs, ...props }
  21. for (const key in obj) {
  22. if (delArr.indexOf(key) !== -1) {
  23. delete obj[key]
  24. }
  25. }
  26. return obj
  27. })
  28. </script>
  29. <template>
  30. <el-button v-bind="getBindValue" @click="onClick">
  31. <Icon v-if="preIcon" :icon="preIcon" class="mr-1px" />
  32. {{ title ? title : '' }}
  33. <Icon v-if="postIcon" :icon="postIcon" class="mr-1px" />
  34. </el-button>
  35. </template>
  36. <style lang="scss" scoped>
  37. :deep(.el-button.is-text) {
  38. margin-left: 0;
  39. padding: 8px 4px;
  40. }
  41. :deep(.el-button.is-link) {
  42. margin-left: 0;
  43. padding: 8px 4px;
  44. }
  45. </style>