You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

154 lines
4.6 KiB

4 years ago
  1. <template>
  2. <view
  3. class="mix-btn-content"
  4. :class="{
  5. disabled: loading || disabled || dead,
  6. }"
  7. :style="[
  8. {marginTop: marginTop}
  9. ]"
  10. @click="confirm"
  11. >
  12. <image v-if="loading" class="loading-icon" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAE3UlEQVRoQ82Z7ZEQNwyGrQoCFQQqgFRAqCBcBSEVQCqAqyBJBTkqACoAKsilAo4KQioQ8+zIO16tvbaWM4P/7lrSq2/JkiYeVX2SUnpmLP4SkTez2MkswgbitaN/MQvMTCBo/xcH5IOI/DxDeWEgqvq0cJfLloZV9X1K6VEEiKo+NNpvo5YLAYm4SxSIqt5JKf2TUrqXUvosIncjlosCqbnLTUrpJxH5XDI+AeRlSumF0Qi7YBTIn4VblXLjYgiynggQVcUKWAOrcB6LCK45fKJAYPixQh1rYBWss5wgELIbqZrzSkSIw9AJATEBW1Z5IyIXUSCqShZ7Z/f+Tyk9LBUyiuYMEMyP5n+oMFldYtQiqopLka04OxedBsSsgun/rjC5EZH7o65lqTzT+WTW2CSN00CKtgKCtBXVoGtoHL6/iciVql6llH51glAflliwdEu85QBf7vUEt8SQvPttXMv5a6YJcUy+BrIJUvp2yX9JnQ1apeuVsdZNtwacvi1nx02744GUubwUDuvAGAutpm9ofRXKwOQMdJWta0L9VzAg4123rKGqWBbZyJr5/C4iyLQcD+R5SumPA/NilZci8qpwDx/43cbQ3COncZQD390xRVAkfX8G/+elUj0Q/JWYeNDxVf5BI9cmFFpHW6vWB3ydTEWq3cWFWQyF+nrywRS5i9tq+rVsgtlqKbaUsav9HiD/XVWxABbKSYBfqC9YoJkMmnXEtIJf5sGoJlM3SEeBWOdLhS/jgOuXxKfv5TzdbkE010ETviWH1m0C8YnmrVlhky1biukCyRct8AD0Y0Hs1lzL6hf0yYpPpzaNlqlyYL+PMht1szP/DVvkDPFveWcBYnHg24mWHPRTSx35no5YtqADjZxmEYsQqf1rsYJSy/R7RJaO4BIgrbbkUCYRmeKWqkrrMgoiy7gA6bUlNUCfRMTn+681xnJfVdFwr7PwvC4AAnqWCrU6UROOKvtkZsayVD+qGGL2ZnUPA5QntRYR1jTNLnWU84z/pvj5DEF7NMNArKmjraZ1oAM+NZp6wcwjyFb/nnHbYSCWFmmtyyBfR9eexnrf3ZBGzKKkoT4L2l0gB8MN92c2jdCnNGym0pZCjtp4NM9scLQsO72+aRRDBKcclHMQrssscthN7IAUQ74fbkrerG4gfusPN8afoc63TEyFKK661amNumz9WmmYGsKQ4/e8xA7AYUJr300AqsodVkMIVxt3SSjw8fWtutWJLB92A79VYt/ibLYb1suxh1rrj1sV7fbGpelt7IZHOQdxh9XSSnMECAM/brQrhJUlGzKsQFz7s8aT3Su3L4eLa/sfi+dnhw2fXdZy7Uo3Dip7LVzvXnYtt43cZLhKs9p9SrBxI7t1ex3Uy/XO5MSRb/83a88OEHo8rJxdhonzcUSG8t9uHWkRVlWSQrk429WUIyAWX34ZPrT/rcl0CkjjLXHnGj0gBqZ8NK0+441Y6SwQ1p1lq1IN1kEgfhl+qsiGgVSCtPnKNALErFI+QRym43CL0mghCNDyTYPfmhoMAMG6BH5uTcLviCGLVBYVh69Mo0BqhTW6EwgBMYb5rb078gaBlC8B4a46DMTAEKDXvZ4qAiS7Mu3L1MFqJAVWpr4ytYa1HOF5yiKjDFq91uj9yH9TgZgbLiPB7O3LF2dInShyDo35AAAAAElFTkSuQmCC"></image>
  13. <text v-if="icon" class="mix-icon" :class="icon" :style="{fontSize: iconSize + 'rpx'}"></text>
  14. <text class="mix-text">{{ text }}</text>
  15. </view>
  16. </template>
  17. <script>
  18. /**
  19. * 按钮组件
  20. * @prop text 按钮显示文字
  21. * @prop icon 按钮图标
  22. * @prop iconSize 按钮显示文字
  23. * @prop isConfirm 点击后是否处理loading状态
  24. * @prop disabled 按钮禁用
  25. * @prop marginTop 按钮上边距
  26. */
  27. let stopTimer = null;
  28. export default {
  29. name: 'MixButton',
  30. data() {
  31. return {
  32. dead: false,
  33. loading: false
  34. };
  35. },
  36. props: {
  37. text: {
  38. type: String,
  39. default: '提交'
  40. },
  41. icon: {
  42. type: String,
  43. default: ''
  44. },
  45. iconSize: {
  46. type: Number,
  47. default: 32
  48. },
  49. isConfirm: {
  50. type: Boolean,
  51. default: true
  52. },
  53. disabled: {
  54. type: Boolean,
  55. default: false
  56. },
  57. marginTop: {
  58. type: String,
  59. default: '0rpx'
  60. }
  61. },
  62. methods: {
  63. stop(){
  64. if(stopTimer){
  65. clearTimeout(stopTimer);
  66. stopTimer = null;
  67. }
  68. this.loading = false;
  69. },
  70. death(){
  71. this.loading = false;
  72. this.dead = true;
  73. },
  74. confirm(){
  75. if(this.dead){
  76. return;
  77. }
  78. if(this.loading || this.disabled){
  79. return;
  80. }
  81. if(this.isConfirm){
  82. this.loading = true;
  83. stopTimer = setTimeout(()=>{
  84. this.loading = false;
  85. clearTimeout(stopTimer);
  86. stopTimer = null;
  87. }, 10000)
  88. }
  89. this.$emit('onConfirm');
  90. }
  91. }
  92. }
  93. </script>
  94. <style scoped lang='scss'>
  95. .mix-btn-content{
  96. display: flex;
  97. align-items: center;
  98. justify-content: center;
  99. width: 610rpx;
  100. height: 88rpx;
  101. margin: 0 auto;
  102. font-size: 32rpx;
  103. color: #fff;
  104. border-radius: 100rpx;
  105. background-color: $base-color;
  106. position: relative;
  107. &:after{
  108. content: '';
  109. position: absolute;
  110. left: 50%;
  111. top: 25%;
  112. transform: translateX(-50%);
  113. width: 85%;
  114. height: 85%;
  115. background: linear-gradient(131deg, rgba(255,115,138,1) 0%, rgba(255,83,111,1) 100%);
  116. border-radius: 100rpx;
  117. opacity: 0.4;
  118. filter:blur(10rpx);
  119. }
  120. &.disabled {
  121. opacity: .65;
  122. }
  123. .mix-text{
  124. position: relative;
  125. z-index: 1;
  126. }
  127. .mix-icon{
  128. position: relative;
  129. z-index: 1;
  130. margin-right: 8rpx;
  131. }
  132. .loading-icon{
  133. width: 34rpx;
  134. height: 34rpx;
  135. transform-origin:50% 50%;
  136. margin-right: 16rpx;
  137. animation: rotate 2s linear infinite;
  138. position: relative;
  139. z-index: 1;
  140. }
  141. }
  142. @keyframes rotate{
  143. from {
  144. transform:rotate(0deg)
  145. }
  146. to {
  147. transform:rotate(360deg)
  148. }
  149. }
  150. </style>