index.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <button @click="btnClick" :class="['cu-btn',size,icon?'has-icon':'']"
  3. :style="{backgroundColor:bgColor,padding:padding,color:color,borderRadius:round,width:delWidth,border:delBorder}">
  4. <slot></slot>
  5. <view class="image" v-if="icon">
  6. <u--image width="32rpx" height="32rpx" :src="icon" mode="widthFix"
  7. :lazy-load="true">
  8. </u--image>
  9. </view>
  10. </button>
  11. </template>
  12. <script>
  13. import {
  14. debounce
  15. } from '@/utils/common.js'
  16. export default {
  17. data() {
  18. return {
  19. bflag: false,
  20. timer: null,
  21. }
  22. },
  23. props: {
  24. text: {
  25. type: String,
  26. require: true,
  27. default: ''
  28. },
  29. color: {
  30. type: String,
  31. require: true,
  32. default: '#fff'
  33. },
  34. bgColor: {
  35. type: String,
  36. require: true,
  37. default: '#2C6FF3'
  38. },
  39. padding: {
  40. type: String
  41. },
  42. round: {
  43. type: [Number, String],
  44. default: 'none'
  45. },
  46. size: {
  47. type: String,
  48. require: true,
  49. default: 'normal'
  50. },
  51. width: {
  52. type: String
  53. },
  54. borderColor: {
  55. type: String
  56. },
  57. delay: {
  58. type: [Number, String],
  59. require: false,
  60. default: 0
  61. },
  62. icon:{
  63. type: String,
  64. require: false
  65. }
  66. },
  67. computed: {
  68. delWidth() {
  69. let width = this.width;
  70. if (this.size == 'mini' && !this.width) {
  71. width = "auto"
  72. }
  73. if (this.size != 'mini' && !this.width) {
  74. width = "100%"
  75. }
  76. return width
  77. },
  78. delBorder() {
  79. let border = this.borderColor;
  80. if (!this.borderColor) {
  81. border = '0'
  82. } else {
  83. border = `1rpx solid ${border}`
  84. }
  85. return border
  86. }
  87. },
  88. methods: {
  89. btnClick() {
  90. if(this.bflag) return
  91. console.log('确定提交')
  92. this.$emit('click')
  93. this.bflag=true;
  94. this.timer=setTimeout(()=>{
  95. this.bflag=false;
  96. },this.delay)
  97. }
  98. },
  99. destroyed() {
  100. if(this.timer){
  101. clearTimeout(this.timer)
  102. }
  103. }
  104. }
  105. </script>
  106. <style lang="scss" scoped>
  107. .mini {
  108. font-size: 24rpx;
  109. border-radius: 6rpx;
  110. padding: 0 12rpx;
  111. height: 40rpx;
  112. line-height: 38rpx;
  113. display: inline-block;
  114. width: 100rpx;
  115. }
  116. .medium {
  117. font-size: 24rpx;
  118. border-radius: 8rpx;
  119. padding: 0 12rpx;
  120. height: 50rpx;
  121. line-height: 48rpx;
  122. display: inline-block;
  123. width: 100rpx;
  124. }
  125. .normal {
  126. padding: 0 14rpx;
  127. font-size: 26rpx;
  128. height: 60rpx;
  129. line-height: 58rpx;
  130. border-radius: 8rpx;
  131. }
  132. .large {
  133. border-radius: 12rpx;
  134. height:80rpx;
  135. line-height: 80rpx;
  136. font-size: 28rpx;
  137. }
  138. .cu-btn{
  139. &.has-icon{
  140. padding-left: 54rpx;
  141. padding-right: 22rpx;
  142. position: relative;
  143. .image{
  144. width:32rpx;
  145. height:32rpx;
  146. position: absolute;
  147. left:13rpx;
  148. top:50%;
  149. transform: translateY(-50%);
  150. }
  151. }
  152. }
  153. </style>