app-button.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <template>
  2. <view class="app-view" :style="{
  3. 'width': `${width ? width : '100%'}${width ? 'rpx': ''}`,
  4. 'height': `${setHeight}rpx`,
  5. }">
  6. <button
  7. v-if="type === 'important'"
  8. :style="[
  9. {
  10. 'line-height': `${setHeight - 2}rpx`,
  11. 'font-size': `${fontSize ? fontSize : 32}rpx`,
  12. 'width': `${width ? width : '100%'}${width ? 'rpx': ''}`,
  13. 'height': `${setHeight}rpx`,
  14. 'background-color': `${background ? background : ''}`,
  15. 'border-radius': `${roundSize ? roundSize : ''}`,
  16. color: color,
  17. padding: padding
  18. }
  19. ]"
  20. @click="handleClick"
  21. :class="[
  22. 'app-button',
  23. `app-important`,
  24. `${round ? 'is-round' : ''}`,
  25. `${disabled ? 'app-important-disabled is-disabled' : ''}`,
  26. `${theme}-background`,
  27. `${arrangement === 'column' ? 'app-button-column' : arrangement === 'row' ? 'app-button-row' : ''}`
  28. ]"
  29. >
  30. <slot></slot>
  31. </button>
  32. <button
  33. @click="handleClick"
  34. v-else-if="type === 'general'"
  35. :class="[
  36. `app-button`,
  37. `app-general`,
  38. `${disabled ? 'app-general-disabled is-disabled' : 'app-general-disabled-not'}`,
  39. `${round ? 'is-round': ''}`,
  40. `${arrangement === 'column' ? 'app-button-column' : arrangement === 'row' ? 'app-button-row' : ''}`
  41. ]"
  42. :style="{
  43. 'height': `${setHeight}rpx`,
  44. 'line-height': `${setHeight - 2}rpx`,
  45. 'font-size': `${fontSize ? fontSize : 32}rpx`,
  46. 'width': `${width ? width : '100%'}${width ? 'rpx': ''}`,
  47. 'background-color': `${background ? background : ''}`,
  48. 'border-radius': `${roundSize ? roundSize : ''}`,
  49. color: color,
  50. padding: padding
  51. }"
  52. >
  53. <slot></slot>
  54. </button>
  55. <button
  56. @click="handleClick"
  57. v-else
  58. :style="{
  59. 'height': `${setHeight}rpx`,
  60. 'line-height': `${setHeight - 2}rpx`,
  61. 'font-size': `${fontSize ? fontSize : 32}rpx`,
  62. 'width': `${width ? width : '100%'}${width ? 'rpx': ''}`,
  63. 'background-color': `${background ? background : ''}`,
  64. 'border-radius': `${roundSize ? roundSize : ''}`,
  65. color: color,
  66. padding: padding
  67. }"
  68. :class="[
  69. 'app-button',
  70. `app-secondary`,
  71. `${round ? 'is-round' : ''}`,
  72. `${disabled ? 'app-secondary-disabled is-disabled' : ''}`,
  73. `${theme}-border`,
  74. `${theme}-color`,
  75. `${theme}-secondary-background`,
  76. `${arrangement === 'column' ? 'app-button-column' : arrangement === 'row' ? 'app-button-row' : ''}`
  77. ]"
  78. >
  79. <slot></slot>
  80. </button>
  81. </view>
  82. </template>
  83. <script>
  84. export default {
  85. props: {
  86. disabled: Boolean,
  87. type: String,
  88. round: Boolean,
  89. theme: String,
  90. height: String,
  91. fontSize: String,
  92. width: String,
  93. color: String,
  94. size: String,
  95. background: String,
  96. form: Boolean,
  97. arrangement: String,
  98. roundSize: String,
  99. padding: String,
  100. },
  101. data() {
  102. return {
  103. touch: false
  104. }
  105. },
  106. methods: {
  107. handleClick(e) {
  108. this.$emit('click', e);
  109. }
  110. },
  111. computed: {
  112. setHeight: function() {
  113. if (this.height) {
  114. return this.height;
  115. } else {
  116. switch (this.size) {
  117. case 'large':
  118. return 100;
  119. case 'small':
  120. return 60;
  121. case 'medium':
  122. return 80;
  123. default:
  124. return 80;
  125. }
  126. }
  127. }
  128. }
  129. }
  130. </script>
  131. <style lang="scss" scoped>
  132. $border-radius: 40rpx;
  133. $height: 80rpx;
  134. $border-size: 1px;
  135. .app-view {
  136. position: relative;
  137. /*width:100%;*/
  138. .app-button {
  139. height: $height;
  140. text-align: center;
  141. line-height: $height;
  142. }
  143. .is-round {
  144. border-radius: $border-radius;
  145. }
  146. .is-disabled {
  147. /*background-color: #cdcdcd;*/
  148. pointer-events: none;
  149. }
  150. .app-general {
  151. background-color: #ffffff;
  152. border: $border-size solid #cdcdcd;
  153. }
  154. .app-general-disabled {
  155. color: #cdcdcd;
  156. }
  157. .app-general-disabled-not {
  158. color: #353535;
  159. }
  160. .app-mask {
  161. background-color: rgba(0, 0, 0, .2);
  162. width: 100%;
  163. height: $height;
  164. position: absolute;
  165. top:0;
  166. left: 0;
  167. }
  168. .app-important {
  169. color: #ffffff;
  170. }
  171. .app-important-disabled {
  172. background-color: #cdcdcd;
  173. }
  174. .app-secondary {
  175. border-width: $border-size;
  176. border-style: solid;
  177. }
  178. .app-secondary-disabled {
  179. background-color: #ffffff;
  180. border-color: #cdcdcd;
  181. color: #cdcdcd;
  182. }
  183. }
  184. .app-button:active {
  185. box-shadow: inset 0 0 #{1000rpx} rgba(0, 0, 0, .15);
  186. }
  187. </style>
  188. <style scoped lang="scss">
  189. /* #ifdef MP-WEIXIN */
  190. button {
  191. border: none;
  192. padding: 0 #{24rpx};
  193. }
  194. button:after {
  195. border: none;
  196. border-radius: 0;
  197. }
  198. /* #endif */
  199. /* #ifdef MP-TOUTIAO */
  200. div {
  201. display: block !important;
  202. }
  203. button {
  204. border-radius: 0;
  205. padding: 0;
  206. height: 100%;
  207. //border-color:inherit;
  208. }
  209. button:after {
  210. border: none;
  211. border-radius: 0;
  212. }
  213. /* #endif */
  214. /* #ifdef MP-ALIPAY */
  215. button {
  216. border: none;
  217. //background-color: transparent;
  218. border-radius: 0;
  219. }
  220. /* #endif */
  221. /* #ifdef MP-BAIDU*/
  222. button {
  223. padding: 0;
  224. }
  225. button:after {
  226. border-radius: 0;
  227. border: none;
  228. }
  229. /* #endif */
  230. .app-button-column {
  231. height: 100%;
  232. width: 100%;
  233. display: flex;
  234. flex-direction: column;
  235. justify-content: center;
  236. align-items: center;
  237. }
  238. .app-button-row {
  239. height: 100%;
  240. width: 100%;
  241. display: flex;
  242. flex-direction: row;
  243. justify-content: center;
  244. align-items: center;
  245. }
  246. </style>