My-button.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <view class="button-box" :style="customStyle" :class="disabled && 'disabled'" hover-class="navigator-hover"
  3. hover-start-time="50" 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>
  7. <view v-if="frontIcon && !loading" :style="frontIconStyle" class="iconfont icon" :class="frontIcon" />
  8. {{ loading ? loadingText || text + '中...' : text }}
  9. </view>
  10. </template>
  11. <script setup>
  12. import { defineProps } from 'vue';
  13. const props = defineProps({
  14. frontIcon: {
  15. type: String,
  16. default: ''
  17. },
  18. text: {
  19. type: String,
  20. default: '按钮'
  21. },
  22. loading: {
  23. type: Boolean,
  24. default: false
  25. },
  26. loadingText: {
  27. type: String
  28. },
  29. disabled: {
  30. type: Boolean,
  31. default: false
  32. },
  33. customStyle: {
  34. type: Object
  35. },
  36. frontIconStyle: {
  37. type: Object
  38. },
  39. onClick: {
  40. type: Function,
  41. default: () => { }
  42. },
  43. phonenumber: {
  44. type: [String, Number],
  45. default: ''
  46. }
  47. });
  48. function handleClick() {
  49. if (props.phonenumber) return uni.makePhoneCall({
  50. phoneNumber: String(props.phonenumber),
  51. success: () => {
  52. console.log('拨打电话成功');
  53. },
  54. fail: (err) => {
  55. console.error('拨打电话失败', err);
  56. }
  57. });
  58. // 如果处于加载状态或禁用状态,则不执行任何操作
  59. if (props.loading || props.disabled) return;
  60. // 执行传入的点击事件
  61. props.onClick();
  62. }
  63. </script>
  64. <style lang="scss" scoped>
  65. .button-box {
  66. display: flex;
  67. align-items: center;
  68. justify-content: center;
  69. width: 100%;
  70. height: 80rpx;
  71. background-color: #3874F6;
  72. border: 2rpx solid #3874F6;
  73. color: #FFFFFF;
  74. box-sizing: border-box;
  75. border-radius: 40rpx;
  76. font-family: Microsoft YaHei, Microsoft YaHei;
  77. font-size: 32rpx;
  78. color: #FFFFFF;
  79. .icon {
  80. margin-right: 20rpx;
  81. }
  82. }
  83. .disabled {
  84. opacity: 0.4;
  85. }
  86. </style>