tui-button.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  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. bold ? 'tui-text-bold' : '',
  8. link ? 'tui-btn__link' : '',
  9. width==='100%' || !width || width===true?'tui-btn__flex-1':''
  10. ]" :hover-class="getHoverClass(disabled, type, plain)"
  11. :style="{ width: width, height: height, lineHeight: height, fontSize: size + 'rpx', margin: margin }"
  12. :loading="loading" :form-type="formType" :open-type="openType" @getuserinfo="bindgetuserinfo"
  13. @getphonenumber="bindgetphonenumber" @contact="bindcontact" @error="binderror" :disabled="disabled"
  14. @tap.stop="handleClick">
  15. <slot></slot>
  16. </button>
  17. </template>
  18. <script>
  19. export default {
  20. name: 'tuiButton',
  21. emits: ['click', 'getuserinfo', 'contact', 'getphonenumber', 'error'],
  22. // #ifndef VUE3
  23. // #ifndef MP-QQ
  24. behaviors: ['wx://form-field-button'],
  25. // #endif
  26. // #endif
  27. props: {
  28. //样式类型 primary, white, danger, warning, green,blue, gray,black,brown,gray-primary,gray-danger,gray-warning,gray-green
  29. type: {
  30. type: String,
  31. default: 'primary'
  32. },
  33. //是否加阴影
  34. shadow: {
  35. type: Boolean,
  36. default: false
  37. },
  38. // 宽度 rpx或 %
  39. width: {
  40. type: String,
  41. default: '100%'
  42. },
  43. //高度 rpx
  44. height: {
  45. type: String,
  46. default: '96rpx'
  47. },
  48. //字体大小 rpx
  49. size: {
  50. type: Number,
  51. default: 32
  52. },
  53. bold: {
  54. type: Boolean,
  55. default: false
  56. },
  57. margin: {
  58. type: String,
  59. default: '0'
  60. },
  61. //形状 circle(圆角), square(默认方形),rightAngle(平角)
  62. shape: {
  63. type: String,
  64. default: 'square'
  65. },
  66. plain: {
  67. type: Boolean,
  68. default: false
  69. },
  70. //link样式,去掉边框,结合plain一起使用
  71. link: {
  72. type: Boolean,
  73. default: false
  74. },
  75. disabled: {
  76. type: Boolean,
  77. default: false
  78. },
  79. //禁用后背景是否为灰色 (非空心button生效)
  80. disabledGray: {
  81. type: Boolean,
  82. default: false
  83. },
  84. loading: {
  85. type: Boolean,
  86. default: false
  87. },
  88. formType: {
  89. type: String,
  90. default: ''
  91. },
  92. openType: {
  93. type: String,
  94. default: ''
  95. },
  96. index: {
  97. type: [Number, String],
  98. default: 0
  99. },
  100. //是否需要阻止重复点击【默认200ms】
  101. preventClick: {
  102. type: Boolean,
  103. default: false
  104. }
  105. },
  106. data() {
  107. return {
  108. time: 0
  109. };
  110. },
  111. methods: {
  112. handleClick() {
  113. if (this.disabled) return;
  114. if (this.preventClick) {
  115. if (new Date().getTime() - this.time <= 200) return;
  116. this.time = new Date().getTime();
  117. setTimeout(() => {
  118. this.time = 0;
  119. }, 200);
  120. }
  121. this.$emit('click', {
  122. index: Number(this.index)
  123. });
  124. },
  125. bindgetuserinfo({
  126. detail = {}
  127. } = {}) {
  128. this.$emit('getuserinfo', detail);
  129. },
  130. bindcontact({
  131. detail = {}
  132. } = {}) {
  133. this.$emit('contact', detail);
  134. },
  135. bindgetphonenumber({
  136. detail = {}
  137. } = {}) {
  138. this.$emit('getphonenumber', detail);
  139. },
  140. binderror({
  141. detail = {}
  142. } = {}) {
  143. this.$emit('error', detail);
  144. },
  145. getShadowClass: function(type, shadow, plain) {
  146. let className = '';
  147. if (shadow && type != 'white' && !plain) {
  148. className = 'tui-shadow-' + type;
  149. }
  150. return className;
  151. },
  152. getDisabledClass: function(disabled, type, plain) {
  153. let className = '';
  154. if (disabled && type != 'white' && type.indexOf('-') == -1) {
  155. let classVal = this.disabledGray ? 'tui-gray-disabled' : 'tui-dark-disabled';
  156. className = plain ? 'tui-dark-disabled-outline' : classVal;
  157. }
  158. return className;
  159. },
  160. getShapeClass: function(shape, plain) {
  161. let className = '';
  162. if (shape == 'circle') {
  163. className = plain ? 'tui-outline-fillet' : 'tui-fillet';
  164. } else if (shape == 'rightAngle') {
  165. className = plain ? 'tui-outline-rightAngle' : 'tui-rightAngle';
  166. }
  167. return className;
  168. },
  169. getHoverClass: function(disabled, type, plain) {
  170. let className = '';
  171. if (!disabled) {
  172. className = plain ? 'tui-outline-hover' : 'tui-' + (type || 'primary') + '-hover';
  173. }
  174. return className;
  175. }
  176. }
  177. };
  178. </script>
  179. <style scoped>
  180. .tui-btn-primary {
  181. background: #5677fc !important;
  182. color: #fff;
  183. }
  184. .tui-shadow-primary {
  185. box-shadow: 0 10rpx 14rpx 0 rgba(86, 119, 252, 0.2);
  186. }
  187. .tui-btn-danger {
  188. background: #eb0909 !important;
  189. color: #fff;
  190. }
  191. .tui-shadow-danger {
  192. box-shadow: 0 10rpx 14rpx 0 rgba(235, 9, 9, 0.2);
  193. }
  194. .tui-btn-warning {
  195. background: #fc872d !important;
  196. color: #fff;
  197. }
  198. .tui-shadow-warning {
  199. box-shadow: 0 10rpx 14rpx 0 rgba(252, 135, 45, 0.2);
  200. }
  201. .tui-btn-green {
  202. background: #07c160 !important;
  203. color: #fff;
  204. }
  205. .tui-shadow-green {
  206. box-shadow: 0 10rpx 14rpx 0 rgba(7, 193, 96, 0.2);
  207. }
  208. .tui-btn-blue {
  209. background: #007aff !important;
  210. color: #fff;
  211. }
  212. .tui-shadow-blue {
  213. box-shadow: 0 10rpx 14rpx 0 rgba(0, 122, 255, 0.2);
  214. }
  215. .tui-btn-white {
  216. background: #fff !important;
  217. color: #333 !important;
  218. }
  219. .tui-btn-gray {
  220. background: #bfbfbf !important;
  221. color: #fff !important;
  222. }
  223. .tui-btn-black {
  224. background: #333 !important;
  225. color: #fff !important;
  226. }
  227. .tui-btn-brown {
  228. background: #ac9157 !important;
  229. color: #fff !important;
  230. }
  231. .tui-btn-gray-black {
  232. background: #f2f2f2 !important;
  233. color: #333;
  234. }
  235. .tui-btn-gray-primary {
  236. background: #f2f2f2 !important;
  237. color: #5677fc !important;
  238. /* #ifdef MP-QQ */
  239. border: 0 !important;
  240. /* #endif */
  241. }
  242. .tui-gray-primary-hover {
  243. background: #d9d9d9 !important;
  244. }
  245. .tui-btn-gray-green {
  246. background: #f2f2f2 !important;
  247. color: #07c160 !important;
  248. /* #ifdef MP-QQ */
  249. border: 0 !important;
  250. /* #endif */
  251. }
  252. .tui-gray-green-hover {
  253. background: #d9d9d9 !important;
  254. }
  255. .tui-btn-gray-danger {
  256. background: #f2f2f2 !important;
  257. color: #eb0909 !important;
  258. /* #ifdef MP-QQ */
  259. border: 0 !important;
  260. /* #endif */
  261. }
  262. .tui-gray-danger-hover {
  263. background: #d9d9d9 !important;
  264. }
  265. .tui-btn-gray-warning {
  266. background: #f2f2f2 !important;
  267. color: #fc872d !important;
  268. /* #ifdef MP-QQ */
  269. border: 0 !important;
  270. /* #endif */
  271. }
  272. .tui-gray-warning-hover {
  273. background: #d9d9d9 !important;
  274. }
  275. .tui-shadow-gray {
  276. box-shadow: 0 10rpx 14rpx 0 rgba(191, 191, 191, 0.2);
  277. }
  278. .tui-hover-gray {
  279. background: #f7f7f9 !important;
  280. }
  281. .tui-black-hover {
  282. background: #555 !important;
  283. color: #e5e5e5 !important;
  284. }
  285. .tui-brown-hover {
  286. background: #A37F49 !important;
  287. color: #e5e5e5 !important;
  288. }
  289. /* button start*/
  290. .tui-btn {
  291. width: 100%;
  292. position: relative;
  293. /* #ifndef MP-QQ */
  294. border: 0 !important;
  295. /* #endif */
  296. /* #ifdef MP-QQ */
  297. border: 1rpx solid;
  298. box-sizing: border-box;
  299. /* #endif */
  300. border-radius: 6rpx;
  301. padding-left: 0;
  302. padding-right: 0;
  303. overflow: visible;
  304. display: flex;
  305. align-items: center;
  306. justify-content: center;
  307. }
  308. .tui-btn__flex-1 {
  309. flex: 1;
  310. }
  311. /* #ifndef MP-QQ */
  312. .tui-btn::after {
  313. content: '';
  314. position: absolute;
  315. width: 200%;
  316. height: 200%;
  317. transform-origin: 0 0;
  318. transform: scale(0.5, 0.5) translateZ(0);
  319. box-sizing: border-box;
  320. left: 0;
  321. top: 0;
  322. border-radius: 12rpx;
  323. border: 0;
  324. }
  325. /* #endif */
  326. /* #ifdef MP-BAIDU */
  327. /* .tui-btn:active::after {
  328. background-color: rgba(0, 0, 0, 0.2) !important;
  329. } */
  330. /* #endif */
  331. .tui-text-bold {
  332. font-weight: bold;
  333. }
  334. /* #ifdef MP-QQ */
  335. .tui-btn-white {
  336. border: 1rpx solid #bfbfbf;
  337. }
  338. /* #endif */
  339. /* #ifndef MP-QQ */
  340. .tui-btn-white::after {
  341. border: 1px solid #bfbfbf;
  342. }
  343. /* #endif */
  344. .tui-white-hover {
  345. background: #e5e5e5 !important;
  346. color: #2e2e2e !important;
  347. }
  348. .tui-dark-disabled {
  349. opacity: 0.6 !important;
  350. color: #fafbfc !important;
  351. }
  352. .tui-dark-disabled-outline {
  353. /* #ifdef MP-QQ */
  354. border: 0 !important;
  355. /* #endif */
  356. opacity: 0.5 !important;
  357. }
  358. .tui-gray-disabled {
  359. background: #f3f3f3 !important;
  360. color: #919191 !important;
  361. box-shadow: none;
  362. }
  363. .tui-outline-hover {
  364. opacity: 0.5 !important;
  365. }
  366. .tui-primary-hover {
  367. background: #4a67d6 !important;
  368. color: #e5e5e5 !important;
  369. }
  370. /* #ifndef MP-QQ */
  371. .tui-primary-outline::after {
  372. border: 1px solid #5677fc !important;
  373. }
  374. /* #endif */
  375. .tui-primary-outline {
  376. color: #5677fc !important;
  377. background: transparent;
  378. /* #ifdef MP-QQ */
  379. border: 1rpx solid #5677fc !important;
  380. /* #endif */
  381. }
  382. .tui-danger-hover {
  383. background: #c80808 !important;
  384. color: #e5e5e5 !important;
  385. }
  386. .tui-danger-outline {
  387. color: #eb0909 !important;
  388. background: transparent;
  389. /* #ifdef MP-QQ */
  390. border: 1rpx solid #eb0909 !important;
  391. /* #endif */
  392. }
  393. /* #ifndef MP-QQ */
  394. .tui-danger-outline::after {
  395. border: 1px solid #eb0909 !important;
  396. }
  397. /* #endif */
  398. .tui-warning-hover {
  399. background: #d67326 !important;
  400. color: #e5e5e5 !important;
  401. }
  402. .tui-warning-outline {
  403. color: #fc872d !important;
  404. background: transparent;
  405. /* #ifdef MP-QQ */
  406. border: 1rpx solid #fc872d !important;
  407. /* #endif */
  408. }
  409. /* #ifndef MP-QQ */
  410. .tui-warning-outline::after {
  411. border: 1px solid #fc872d !important;
  412. }
  413. /* #endif */
  414. .tui-green-hover {
  415. background: #06ad56 !important;
  416. color: #e5e5e5 !important;
  417. }
  418. .tui-green-outline {
  419. color: #07c160 !important;
  420. background: transparent;
  421. /* #ifdef MP-QQ */
  422. border: 1rpx solid #07c160 !important;
  423. /* #endif */
  424. }
  425. /* #ifndef MP-QQ */
  426. .tui-green-outline::after {
  427. border: 1px solid #07c160 !important;
  428. }
  429. /* #endif */
  430. .tui-blue-hover {
  431. background: #0062cc !important;
  432. color: #e5e5e5 !important;
  433. }
  434. .tui-blue-outline {
  435. color: #007aff !important;
  436. background: transparent;
  437. /* #ifdef APP-PLUS */
  438. border: 1rpx solid #007aff !important;
  439. /* #endif */
  440. }
  441. /* #ifndef MP-QQ */
  442. .tui-blue-outline::after {
  443. border: 1px solid #007aff !important;
  444. }
  445. /* #endif */
  446. /* #ifndef APP-NVUE */
  447. .tui-btn-gradual {
  448. background: linear-gradient(90deg, rgb(255, 89, 38), rgb(240, 14, 44)) !important;
  449. color: #fff !important;
  450. }
  451. .tui-shadow-gradual {
  452. box-shadow: 0 10rpx 14rpx 0 rgba(235, 9, 9, 0.15);
  453. }
  454. /* #endif */
  455. .tui-gray-hover {
  456. background: #a3a3a3 !important;
  457. color: #898989;
  458. }
  459. /* #ifndef APP-NVUE */
  460. .tui-gradual-hover {
  461. background: linear-gradient(90deg, #d74620, #cd1225) !important;
  462. color: #fff !important;
  463. }
  464. /* #endif */
  465. .tui-gray-outline {
  466. color: #999 !important;
  467. background: transparent !important;
  468. }
  469. .tui-white-outline {
  470. color: #fff !important;
  471. background: transparent !important;
  472. /* #ifdef MP-QQ */
  473. border: 1rpx solid #fff !important;
  474. /* #endif */
  475. }
  476. .tui-black-outline {
  477. background: transparent !important;
  478. color: #333 !important;
  479. /* #ifdef MP-QQ */
  480. border: 1rpx solid #ccc !important;
  481. /* #endif */
  482. }
  483. /* #ifndef MP-QQ */
  484. .tui-gray-outline::after {
  485. border: 1px solid #ccc !important;
  486. }
  487. /* #endif */
  488. /* #ifndef MP-QQ */
  489. .tui-white-outline::after {
  490. border: 1px solid #fff !important;
  491. }
  492. .tui-black-outline::after {
  493. border: 1px solid #333 !important;
  494. }
  495. .tui-brown-outline::after {
  496. border: 1px solid #ac9157 !important;
  497. }
  498. /* #endif */
  499. .tui-brown-outline {
  500. color: #ac9157 !important;
  501. background: transparent;
  502. /* #ifdef MP-QQ */
  503. border: 1rpx solid #ac9157 !important;
  504. /* #endif */
  505. }
  506. /*圆角 */
  507. .tui-fillet {
  508. border-radius: 50rpx;
  509. }
  510. .tui-btn-white.tui-fillet::after {
  511. border-radius: 98rpx;
  512. }
  513. .tui-outline-fillet::after {
  514. border-radius: 98rpx;
  515. }
  516. /*平角*/
  517. .tui-rightAngle {
  518. border-radius: 0;
  519. }
  520. .tui-btn-white.tui-rightAngle::after {
  521. border-radius: 0;
  522. }
  523. .tui-outline-rightAngle::after {
  524. border-radius: 0;
  525. }
  526. /* #ifdef MP-QQ */
  527. .tui-btn__link {
  528. border: 0 !important;
  529. }
  530. /* #endif */
  531. .tui-btn__link::after {
  532. border: 0 !important;
  533. }
  534. </style>