My-button.vue 2.1 KB

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