tui-button.vue 7.4 KB

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