XButton.vue 1.3 KB

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