fs-button.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <template>
  2. <button
  3. hover-class="fs-hover"
  4. class="fs-button"
  5. :class="[
  6. type,
  7. size,
  8. plain ? 'plain' : '',
  9. radius ? 'radius' : '',
  10. round ? 'round' : '',
  11. disabled ? 'disabled' : '',
  12. block ? 'block' : '',
  13. full ? 'block full' : '',
  14. ]"
  15. :style="[
  16. { width: width },
  17. customStyle,
  18. ]"
  19. @click="handleClick"
  20. >
  21. <view class="fs-loader" v-if="loading"></view>
  22. <template v-else>
  23. <slot></slot>
  24. </template>
  25. </button>
  26. </template>
  27. <script setup>
  28. import { computed, useAttrs } from 'vue'
  29. const props = defineProps({
  30. size: {
  31. type: String,
  32. validator(value) {
  33. return ['mini', 'small', 'medium'].includes(value)
  34. }
  35. },
  36. type: {
  37. type: String,
  38. default: 'primary',
  39. validator(value) {
  40. return ['primary', 'success', 'info', 'warning', 'danger', 'default'].includes(value)
  41. }
  42. },
  43. plain: Boolean,
  44. radius: Boolean,
  45. round: Boolean,
  46. disabled: Boolean,
  47. full: Boolean,
  48. block: Boolean,
  49. link: String,
  50. linkType: {
  51. type: String,
  52. default: 'navigateTo'
  53. },
  54. width: String,
  55. customStyle: {
  56. type: Object,
  57. default() {
  58. return {}
  59. }
  60. },
  61. loading: Boolean
  62. })
  63. const emits = defineEmits(['click'])
  64. const handleClick = e => {
  65. if (props.link && !props.disabled) {
  66. uni[props.linkType]({
  67. url: props.link
  68. })
  69. }
  70. !props.disabled && emits('click')
  71. }
  72. </script>
  73. <style lang="scss" scoped>
  74. .fs-button {
  75. font-weight: normal;
  76. font-size: 14px;
  77. color: #fff;
  78. padding: 0 40rpx;
  79. line-height: 1;
  80. text-align: center;
  81. border-radius: 0;
  82. display: inline-block;
  83. vertical-align: bottom;
  84. background-color: #cfcfcf;
  85. margin: 0;
  86. border: 0;
  87. height: 70rpx;
  88. line-height: 70rpx;
  89. &.primary,
  90. &.primary.selected,
  91. &.selected {
  92. background-color: var(--primary);
  93. }
  94. &.success {
  95. background-color: var(--success);
  96. }
  97. &.info {
  98. background-color: var(--info);
  99. }
  100. &.warning {
  101. background-color: var(--warning);
  102. }
  103. &.danger {
  104. background-color: var(--danger);
  105. }
  106. &.plain,
  107. &.plain.selected {
  108. background-color: transparent;
  109. box-shadow: inset 0 0 0 1px currentColor;
  110. color: #999999;
  111. }
  112. &.medium {
  113. // width: auto !important;
  114. height: 60rpx;
  115. line-height: 60rpx;
  116. font-size: 13px;
  117. padding: 0 30rpx;
  118. }
  119. &.small {
  120. width: auto !important;
  121. height: 50rpx;
  122. line-height: 50rpx;
  123. font-size: 12px;
  124. padding: 0 20rpx;
  125. }
  126. &.mini {
  127. width: auto !important;
  128. height: 40rpx;
  129. line-height: 40rpx;
  130. font-size: 12px;
  131. padding: 0 20rpx;
  132. }
  133. &.block {
  134. display: block;
  135. height: 100rpx;
  136. line-height: 100rpx;
  137. margin-left: var(--gutter) !important;
  138. margin-right: var(--gutter) !important;
  139. font-size: 18px;
  140. width: auto;
  141. &.radius {
  142. border-radius: 16rpx;
  143. }
  144. }
  145. &.full {
  146. margin-left: 0 !important;
  147. margin-right: 0 !important;
  148. }
  149. &::after {
  150. border: none;
  151. }
  152. &.radius {
  153. border-radius: 8rpx;
  154. }
  155. &.round {
  156. border-radius: 30px;
  157. }
  158. &.plain.primary,
  159. &.plain.selected {
  160. color: var(--primary);
  161. }
  162. &.plain.success {
  163. color: var(--success);
  164. }
  165. &.plain.warning {
  166. color: var(--warning);
  167. }
  168. &.plain.danger {
  169. color: var(--danger);
  170. }
  171. &.plain.info {
  172. color: var(--info);
  173. }
  174. &.disabled {
  175. opacity: 0.5;
  176. }
  177. }
  178. .fs-hover {
  179. opacity: 0.5;
  180. }
  181. .fs-loader {
  182. display: inline-block;
  183. width: 40rpx;
  184. height: 40rpx;
  185. color: inherit;
  186. vertical-align: middle;
  187. border: 4rpx solid currentcolor;
  188. border-bottom-color: transparent;
  189. border-radius: 50%;
  190. animation: 1s loader linear infinite;
  191. position: relative;
  192. }
  193. @keyframes loader {
  194. 0% {
  195. transform: rotate(0deg);
  196. }
  197. 100% {
  198. transform: rotate(360deg);
  199. }
  200. }
  201. </style>