button.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. <template>
  2. <button class="tui-btn-class tui-btn" :class="[plain?'tui-'+type+'-outline':'tui-btn-'+(type || 'primary'),getDisabledClass(disabled,type),getShapeClass(shape,plain),getShadowClass(type,shadow,plain)]"
  3. :hover-class="getHoverClass(disabled,type,plain)" :style="{width:width,height:height,lineHeight:height,fontSize:size+'rpx'}"
  4. :loading="loading" :disabled="disabled" @tap="handleClick">
  5. <slot></slot>
  6. </button>
  7. </template>
  8. <script>
  9. export default {
  10. name: "tuiButton",
  11. props: {
  12. //样式类型 primary, white, danger, warning, green,blue, gray,black
  13. type: {
  14. type: String,
  15. default: 'primary'
  16. },
  17. //是否加阴影
  18. shadow: {
  19. type: Boolean,
  20. default: false
  21. },
  22. // 宽度 rpx或 %
  23. width: {
  24. type: String,
  25. default: '100%'
  26. },
  27. //高度 rpx
  28. height: {
  29. type: String,
  30. default: '94rpx'
  31. },
  32. //字体大小 rpx
  33. size: {
  34. type: Number,
  35. default: 32
  36. },
  37. //形状 circle(圆角), square(默认方形),rightAngle(平角)
  38. shape: {
  39. type: String,
  40. default: 'square'
  41. },
  42. plain: {
  43. type: Boolean,
  44. default: false
  45. },
  46. disabled: {
  47. type: Boolean,
  48. default: false
  49. },
  50. loading: {
  51. type: Boolean,
  52. default: false
  53. }
  54. },
  55. methods: {
  56. handleClick() {
  57. if (this.disabled) {
  58. return false;
  59. }
  60. this.$emit('click', {})
  61. },
  62. getShadowClass: function(type, shadow,plain) {
  63. let className = '';
  64. if (shadow && type != 'white' && !plain) {
  65. className = 'tui-shadow-' + type;
  66. }
  67. return className;
  68. },
  69. getDisabledClass: function(disabled, type) {
  70. let className = '';
  71. if (disabled && type != 'white' && type != 'gray') {
  72. className = 'tui-dark-disabled';
  73. }
  74. return className;
  75. },
  76. getShapeClass: function(shape, plain) {
  77. let className = '';
  78. if (shape == 'circle') {
  79. className = plain ? 'tui-outline-fillet' : 'tui-fillet';
  80. } else if (shape == "rightAngle") {
  81. className = plain ? 'tui-outline-rightAngle' : 'tui-rightAngle';
  82. }
  83. return className;
  84. },
  85. getHoverClass: function(disabled, type, plain) {
  86. let className = '';
  87. if (!disabled) {
  88. className = plain ? 'tui-outline-hover' : ('tui-' + (type || 'primary') + '-hover');
  89. }
  90. return className;
  91. }
  92. }
  93. }
  94. </script>
  95. <style>
  96. .tui-btn-primary {
  97. background: #1582AD !important;
  98. color: #fff;
  99. }
  100. .tui-shadow-primary {
  101. box-shadow: 0 10rpx 14rpx 0 rgba(15, 96, 128, 0.14);
  102. }
  103. .tui-btn-danger {
  104. background: #EB0909 !important;
  105. color: #fff;
  106. }
  107. .tui-shadow-danger {
  108. box-shadow: 0 10rpx 14rpx 0 rgba(235, 9, 9, 0.2);
  109. }
  110. .tui-btn-warning {
  111. background: #fc872d !important;
  112. color: #fff;
  113. }
  114. .tui-shadow-warning {
  115. box-shadow: 0 10rpx 14rpx 0 rgba(252, 135, 45, 0.2);
  116. }
  117. .tui-btn-green {
  118. background: #35b06a !important;
  119. color: #fff;
  120. }
  121. .tui-shadow-green {
  122. box-shadow: 0 10rpx 14rpx 0 rgba(53,176,106, 0.2);
  123. }
  124. .tui-btn-blue {
  125. background: #C74547 !important;
  126. color: #fff;
  127. }
  128. .tui-shadow-blue {
  129. box-shadow: 0 10rpx 14rpx 0 rgba(86,119,252, 0.2);
  130. }
  131. .tui-btn-white {
  132. background: #fff !important;
  133. color: #333 !important;
  134. }
  135. .tui-btn-gray {
  136. background: #BFBFBF !important;
  137. color: #fff !important;
  138. }
  139. .tui-btn-black {
  140. background: #333 !important;
  141. color: #fff !important;
  142. }
  143. .tui-shadow-gray {
  144. box-shadow: 0 10rpx 14rpx 0 rgba(191,191,191, 0.2);
  145. }
  146. .tui-hover-gray {
  147. background: #f7f7f9 !important;
  148. }
  149. /* button start*/
  150. .tui-btn {
  151. width: 100%;
  152. position: relative;
  153. border: 0 !important;
  154. border-radius: 6rpx;
  155. padding-left: 0;
  156. padding-right: 0;
  157. overflow: visible;
  158. }
  159. .tui-btn::after {
  160. content: "";
  161. position: absolute;
  162. width: 200%;
  163. height: 200%;
  164. transform-origin: 0 0;
  165. transform: scale(0.5, 0.5) translateZ(0);
  166. box-sizing: border-box;
  167. left: 0;
  168. top: 0;
  169. border-radius: 12rpx;
  170. border: 0;
  171. }
  172. .tui-btn-white::after {
  173. border: 1rpx solid #BFBFBF;
  174. }
  175. .tui-white-hover {
  176. background: #e5e5e5 !important;
  177. color: #2e2e2e !important;
  178. }
  179. .tui-dark-disabled {
  180. opacity: 0.6 !important;
  181. color: #fafbfc !important;
  182. }
  183. .tui-dark-disabled.tui-btn-danger {
  184. opacity: 1 !important;
  185. background: #FC8888 !important;
  186. }
  187. .tui-outline-hover {
  188. opacity: 0.5;
  189. }
  190. .tui-primary-hover {
  191. background: #126f93 !important;
  192. color: #e5e5e5 !important;
  193. }
  194. .tui-primary-outline::after {
  195. border: 1rpx solid #1582AD !important;
  196. }
  197. .tui-primary-outline {
  198. color: #1582AD !important;
  199. background: none;
  200. }
  201. .tui-danger-hover {
  202. background: #c80808 !important;
  203. color: #e5e5e5 !important;
  204. }
  205. .tui-danger-outline {
  206. color: #EB0909 !important;
  207. background: none;
  208. }
  209. .tui-danger-outline::after {
  210. border: 1rpx solid #EB0909 !important;
  211. }
  212. .tui-warning-hover {
  213. background: #d67326 !important;
  214. color: #e5e5e5 !important;
  215. }
  216. .tui-warning-outline {
  217. color: #fc872d !important;
  218. background: none;
  219. }
  220. .tui-warning-outline::after {
  221. border: 1px solid #fc872d !important;
  222. }
  223. .tui-green-hover {
  224. background: #2d965a !important;
  225. color: #e5e5e5 !important;
  226. }
  227. .tui-green-outline {
  228. color: #35b06a !important;
  229. background: none;
  230. }
  231. .tui-green-outline::after {
  232. border: 1rpx solid #35b06a !important;
  233. }
  234. .tui-blue-hover {
  235. background: #a2383a !important;
  236. color: #e5e5e5 !important;
  237. }
  238. .tui-blue-outline {
  239. color: #C74547 !important;
  240. background: none;
  241. }
  242. .tui-blue-outline::after {
  243. border: 1rpx solid #C74547 !important;
  244. }
  245. .tui-gray-hover {
  246. background: #a3a3a3 !important;
  247. color: #898989;
  248. }
  249. .tui-gray-outline {
  250. color: #999 !important;
  251. background: none !important;
  252. }
  253. .tui-white-outline{
  254. color: #fff !important;
  255. background: none !important;
  256. }
  257. .tui-black-outline {
  258. background: none !important;
  259. color: #333 !important;
  260. }
  261. .tui-gray-outline::after {
  262. border: 1rpx solid #ccc !important;
  263. }
  264. .tui-white-outline::after {
  265. border: 1px solid #fff !important;
  266. }
  267. .tui-black-outline::after {
  268. border: 1px solid #333 !important;
  269. }
  270. /*圆角 */
  271. .tui-fillet {
  272. border-radius: 50rpx;
  273. }
  274. .tui-btn-white.tui-fillet::after {
  275. border-radius: 98rpx;
  276. }
  277. .tui-outline-fillet::after {
  278. border-radius: 98rpx;
  279. }
  280. /*平角*/
  281. .tui-rightAngle {
  282. border-radius: 0;
  283. }
  284. .tui-btn-white.tui-rightAngle::after {
  285. border-radius: 0;
  286. }
  287. .tui-outline-rightAngle::after {
  288. border-radius: 0;
  289. }
  290. </style>