app-button.vue 6.9 KB

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