My-button.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <template>
  2. <view class="button-box" :style="customStyle" :class="disabled && 'disabled'" hover-class="navigator-hover" hover-start-time="50"
  3. hover-stay-time="200" @click="handleClick">
  4. <view v-if="loading" style="margin-right: 10rpx;">
  5. <up-loading-icon size="18" mode="circle" />
  6. </view>{{ loading ? loadingText || text + '中...' : text }}
  7. </view>
  8. </template>
  9. <script setup>
  10. import { defineProps } from 'vue';
  11. const props = defineProps({
  12. text: {
  13. type: String,
  14. default: '按钮'
  15. },
  16. loading: {
  17. type: Boolean,
  18. default: false
  19. },
  20. loadingText: {
  21. type: String
  22. },
  23. disabled: {
  24. type: Boolean,
  25. default: false
  26. },
  27. customStyle: {
  28. type: Object
  29. },
  30. onClick: {
  31. type: Function,
  32. default: () => { }
  33. }
  34. });
  35. function handleClick() {
  36. // 如果处于加载状态或禁用状态,则不执行任何操作
  37. if (props.loading || props.disabled) return;
  38. // 执行传入的点击事件
  39. props.onClick();
  40. }
  41. </script>
  42. <style lang="scss" scoped>
  43. .button-box {
  44. display: flex;
  45. align-items: center;
  46. justify-content: center;
  47. width: 100%;
  48. height: 80rpx;
  49. background-color: #3874F6;
  50. color: #FFFFFF;
  51. box-sizing: border-box;
  52. border-radius: 40rpx;
  53. font-family: Microsoft YaHei, Microsoft YaHei;
  54. font-size: 32rpx;
  55. color: #FFFFFF;
  56. }
  57. .disabled {
  58. opacity: 0.4;
  59. }
  60. </style>