fs-button.vue 4.3 KB

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