btn.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <div :class="{ 'area-btn': disabled }">
  3. <div class="btn-submit" @click="clickBtn" :class="{ 'no': loading, 'disabled': disabled }">
  4. <img :src="require('@/assets/svg/icon-iframe-loading.svg')" alt="" class="loading" v-if="loading && icon" />
  5. <img :src="require('@/assets/svg/icon-btn-box.svg')" alt="" v-if="!loading && icon" />
  6. <span :style="{ 'font-size': fontSize, 'color': txtCorlor, 'font-weight': fontWeight }">{{ txt }}</span>
  7. </div>
  8. <div class="refresh" v-if="disabled">
  9. <img :src="require('@/assets/svg/icon-refresh-treasure.svg')"
  10. :class="{ 'icon-refresh-rotate': refreshRotate }" alt="" @click="refresh" />
  11. </div>
  12. </div>
  13. </template>
  14. <script setup>
  15. import { inject, defineProps, defineEmits, ref } from 'vue'
  16. let refreshRotate = ref(false);
  17. let state = inject('state')
  18. let props = defineProps({
  19. txt: {
  20. type: String,
  21. default: ''
  22. },
  23. loading: {
  24. type: Boolean,
  25. default: false
  26. },
  27. fontSize: {
  28. type: String,
  29. default: '20px'
  30. },
  31. fontWeight: {
  32. type: String,
  33. default: '800'
  34. },
  35. icon: {
  36. type: Boolean,
  37. default: true
  38. },
  39. disabled: {
  40. type: Boolean,
  41. default: false
  42. },
  43. txtCorlor: {
  44. type: String
  45. }
  46. })
  47. const emit = defineEmits(['on-click'])
  48. const clickBtn = () => {
  49. if (props.disabled == false && props.loading == false) {
  50. emit('on-click')
  51. }
  52. }
  53. const refresh = () => {
  54. if (!refreshRotate.value) {
  55. refreshRotate.value = true;
  56. setTimeout(() => {
  57. refreshRotate.value = false;
  58. }, 1000)
  59. state.refreshInit()
  60. }
  61. }
  62. </script>
  63. <style scoped lang="scss">
  64. .btn-submit {
  65. background: #1D9BF0;
  66. border-radius: 100px;
  67. display: flex;
  68. align-items: center;
  69. justify-content: center;
  70. height: 53px;
  71. width: 343px;
  72. margin: 0 auto;
  73. cursor: pointer;
  74. user-select: none;
  75. span {
  76. font-weight: 800;
  77. color: #FFFFFF;
  78. font-size: 20px;
  79. line-height: 24px;
  80. margin-left: 6px;
  81. }
  82. img {
  83. width: 20px;
  84. height: 20px;
  85. }
  86. .loading {
  87. animation: loading 1s infinite linear;
  88. }
  89. }
  90. .area-btn {
  91. display: flex;
  92. .refresh {
  93. display: flex;
  94. justify-content: center;
  95. align-items: center;
  96. img {
  97. cursor: pointer;
  98. margin-left: 12px;
  99. }
  100. .icon-refresh-rotate {
  101. transform: rotate(360deg);
  102. transition-duration: 1s;
  103. }
  104. }
  105. .no {
  106. cursor: no-drop;
  107. }
  108. .disabled {
  109. cursor: no-drop;
  110. background: rgba(56, 154, 255, 0.2);
  111. color: #FFFFFF;
  112. width: 305px;
  113. font-weight: 600;
  114. margin: 0;
  115. span {
  116. font-weight: 600;
  117. color: #FFFFFF;
  118. }
  119. }
  120. @keyframes loading {
  121. from {
  122. transform: rotate(0deg);
  123. }
  124. to {
  125. transform: rotate(360deg);
  126. }
  127. }
  128. }
  129. </style>