btn.vue 3.3 KB

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