tui-button.vue 10 KB

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