tui-button.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  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' : 'tui-text-nobold',
  8. noborder?'tui-btn-noborder':''
  9. ]"
  10. :hover-class="getHoverClass(disabled, type, plain)" :style="{ width: width, height: height, lineHeight: `calc(${height})`, fontSize: size + 'rpx', margin: margin, 'background-color': backColor&&(!disabled||!disabledGray)?backColor+' !important':'', 'color': fontColor&&(!disabled||!disabledGray)?fontColor+' !important':'', 'border-color': borderColor?borderColor+' !important':'' }"
  11. :loading="loading" :form-type="formType" :open-type="openType" @getuserinfo="bindgetuserinfo" @getphonenumber="bindgetphonenumber"
  12. @contact="bindcontact" @error="binderror" :disabled="disabled" @tap="handleClick">
  13. <slot></slot>
  14. <view class="after" :style="{'border-color': borderColor?borderColor+' !important':'', 'border-width':borderSize?borderSize+' !important':''}"></view>
  15. </button>
  16. </template>
  17. <script>
  18. export default {
  19. name: 'tuiButton',
  20. behaviors: ['wx://form-field-button'],
  21. props: {
  22. //样式类型 primary, white, danger, warning, green,blue, gray,black,gray-primary,gray-danger,gray-warning,gray-green
  23. type: {
  24. type: String,
  25. default: 'primary'
  26. },
  27. //是否加阴影
  28. shadow: {
  29. type: Boolean,
  30. default: false
  31. },
  32. // 宽度 rpx或 %
  33. width: {
  34. type: String,
  35. default: '100%'
  36. },
  37. //高度 rpx
  38. height: {
  39. type: String,
  40. default: '96rpx'
  41. },
  42. //字体大小 rpx
  43. size: {
  44. type: Number,
  45. default: 32
  46. },
  47. bold: {
  48. type: Boolean,
  49. default: false
  50. },
  51. margin: {
  52. type: String,
  53. default: '0'
  54. },
  55. //形状 circle(圆角), square(默认方形),rightAngle(平角)
  56. shape: {
  57. type: String,
  58. default: 'square'
  59. },
  60. plain: {
  61. type: Boolean,
  62. default: false
  63. },
  64. disabled: {
  65. type: Boolean,
  66. default: false
  67. },
  68. borderSize:{
  69. type: String,
  70. default: ''
  71. },
  72. borderColor: {
  73. type: String,
  74. default: ''
  75. },
  76. backColor: {
  77. type: String,
  78. default: ''
  79. },
  80. fontColor: {
  81. type: String,
  82. default: ''
  83. },
  84. //禁用后背景是否为灰色 (非空心button生效)
  85. disabledGray: {
  86. type: Boolean,
  87. default: false
  88. },
  89. loading: {
  90. type: Boolean,
  91. default: false
  92. },
  93. formType: {
  94. type: String,
  95. default: ''
  96. },
  97. openType: {
  98. type: String,
  99. default: ''
  100. },
  101. index: {
  102. type: [Number, String],
  103. default: 0
  104. },
  105. noborder: {
  106. type: Boolean,
  107. default: false
  108. }
  109. },
  110. methods: {
  111. handleClick() {
  112. if (this.disabled) return false;
  113. this.$emit('click', {
  114. index: Number(this.index)
  115. });
  116. },
  117. formSubmit(e) {
  118. if (this.disabled) return false;
  119. this.$emit('formSubmit', e);
  120. },
  121. formReset(e) {
  122. if (this.disabled) return false;
  123. this.$emit('formReset', e);
  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: #007aff !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: #3f9f81 !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-gray-black {
  228. background: #f2f2f2 !important;
  229. color: #333;
  230. }
  231. .tui-btn-gray-primary {
  232. background: #f2f2f2 !important;
  233. color: #007aff !important;
  234. }
  235. .tui-gray-primary-hover {
  236. background: #d9d9d9 !important;
  237. }
  238. .tui-btn-gray-green {
  239. background: #f2f2f2 !important;
  240. color: #3f9f81 !important;
  241. }
  242. .tui-gray-green-hover {
  243. background: #d9d9d9 !important;
  244. }
  245. .tui-btn-gray-danger {
  246. background: #f2f2f2 !important;
  247. color: #eb0909 !important;
  248. }
  249. .tui-gray-danger-hover {
  250. background: #d9d9d9 !important;
  251. }
  252. .tui-btn-gray-warning {
  253. background: #f2f2f2 !important;
  254. color: #fc872d !important;
  255. }
  256. .tui-gray-warning-hover {
  257. background: #d9d9d9 !important;
  258. }
  259. .tui-shadow-gray {
  260. box-shadow: 0 10rpx 14rpx 0 rgba(191, 191, 191, 0.2);
  261. }
  262. .tui-hover-gray {
  263. background: #f7f7f9 !important;
  264. }
  265. .tui-black-hover {
  266. background: #555 !important;
  267. color: #e5e5e5 !important;
  268. }
  269. /* button start*/
  270. .tui-btn {
  271. width: 100%;
  272. position: relative;
  273. border: 0 !important;
  274. border-radius: 6rpx;
  275. padding-left: 0;
  276. padding-right: 0;
  277. overflow: visible;
  278. }
  279. .tui-btn .after {
  280. content: '';
  281. position: absolute;
  282. width: 200%;
  283. height: 200%;
  284. transform-origin: 0 0;
  285. transform: scale(0.5, 0.5) translateZ(0);
  286. box-sizing: border-box;
  287. left: 0;
  288. top: 0;
  289. border-radius: 12rpx;
  290. border: 0;
  291. }
  292. .tui-text-bold {
  293. font-weight: bold;
  294. }
  295. .tui-text-nobold {
  296. font-weight: normal;
  297. }
  298. .tui-btn-white .after {
  299. border: 1px solid #bfbfbf;
  300. }
  301. .tui-white-hover {
  302. background: #e5e5e5 !important;
  303. color: #2e2e2e !important;
  304. }
  305. .tui-dark-disabled {
  306. opacity: 0.6 !important;
  307. color: #fafbfc !important;
  308. }
  309. .tui-dark-disabled-outline {
  310. opacity: 0.5 !important;
  311. }
  312. .tui-gray-disabled {
  313. background: #f3f3f3 !important;
  314. color: #919191 !important;
  315. box-shadow: none;
  316. }
  317. .tui-outline-hover {
  318. opacity: 0.5;
  319. }
  320. .tui-primary-hover {
  321. background: #19649d !important;
  322. color: #e5e5e5 !important;
  323. }
  324. .tui-primary-outline .after {
  325. border: 1px solid #007aff !important;
  326. }
  327. .tui-primary-outline {
  328. color: #007aff !important;
  329. background: transparent;
  330. }
  331. .tui-danger-hover {
  332. background: #c80808 !important;
  333. color: #e5e5e5 !important;
  334. }
  335. .tui-danger-outline {
  336. color: #eb0909 !important;
  337. background: transparent;
  338. }
  339. .tui-danger-outline .after {
  340. border: 1px solid #eb0909 !important;
  341. }
  342. .tui-warning-hover {
  343. background: #d67326 !important;
  344. color: #e5e5e5 !important;
  345. }
  346. .tui-warning-outline {
  347. color: #fc872d !important;
  348. background: transparent;
  349. }
  350. .tui-warning-outline .after {
  351. border: 1px solid #fc872d !important;
  352. }
  353. .tui-green-hover {
  354. background: #45a788 !important;
  355. color: #e5e5e5 !important;
  356. }
  357. .tui-green-outline {
  358. color: #3f9f81 !important;
  359. background: transparent;
  360. }
  361. .tui-green-outline .after {
  362. border: 1px solid #3f9f81 !important;
  363. }
  364. .tui-blue-hover {
  365. background: #0062cc !important;
  366. color: #e5e5e5 !important;
  367. }
  368. .tui-blue-outline {
  369. color: #007aff !important;
  370. background: transparent;
  371. }
  372. .tui-blue-outline .after {
  373. border: 1px solid #007aff !important;
  374. }
  375. /* #ifndef APP-NVUE */
  376. .tui-btn-gradual {
  377. background: linear-gradient(90deg, rgb(255, 89, 38), rgb(240, 14, 44)) !important;
  378. color: #fff !important;
  379. }
  380. .tui-shadow-gradual {
  381. box-shadow: 0 10rpx 14rpx 0 rgba(235, 9, 9, 0.15);
  382. }
  383. /* #endif */
  384. .tui-gray-hover {
  385. background: #a3a3a3 !important;
  386. color: #898989;
  387. }
  388. /* #ifndef APP-NVUE */
  389. .tui-gradual-hover {
  390. background: linear-gradient(90deg, #d74620, #cd1225) !important;
  391. color: #fff !important;
  392. }
  393. /* #endif */
  394. .tui-gray-outline {
  395. color: #999 !important;
  396. background: transparent !important;
  397. }
  398. .tui-white-outline {
  399. color: #fff !important;
  400. background: transparent !important;
  401. }
  402. .tui-black-outline {
  403. background: transparent !important;
  404. color: #333 !important;
  405. }
  406. .tui-gray-outline .after {
  407. border: 1px solid #ccc !important;
  408. }
  409. .tui-white-outline .after {
  410. border: 1px solid #fff !important;
  411. }
  412. .tui-black-outline .after {
  413. border: 1px solid #333 !important;
  414. }
  415. /*圆角 */
  416. .tui-fillet {
  417. border-radius: 50rpx;
  418. }
  419. .tui-btn-white.tui-fillet .after {
  420. border-radius: 98rpx;
  421. }
  422. .tui-outline-fillet .after {
  423. border-radius: 98rpx;
  424. }
  425. /*平角*/
  426. .tui-rightAngle {
  427. border-radius: 0;
  428. }
  429. .tui-btn-white.tui-rightAngle .after {
  430. border-radius: 0;
  431. }
  432. .tui-outline-rightAngle .after {
  433. border-radius: 0;
  434. }
  435. .tui-btn-noborder .after {
  436. border: none !important;
  437. }
  438. </style>