app-button.vue 7.0 KB

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