tui-button.vue 9.2 KB

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