index.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. <template>
  2. <view>
  3. <sjs src="../wxs/utils.sjs" module="utils" />
  4. <button
  5. :id="id"
  6. :class="
  7. 'custom-class ' +
  8. utils.bem('button', [type, size, { block, round, plain, square, loading, disabled, hairline, unclickable: disabled || loading }]) +
  9. ' ' +
  10. (hairline ? 'van-hairline--surround' : '')
  11. "
  12. hover-class="van-button--active hover-class"
  13. :lang="lang"
  14. :style="style + ' ' + customStyle"
  15. :open-type="openType"
  16. :business-id="businessId"
  17. :session-from="sessionFrom"
  18. :send-message-title="sendMessageTitle"
  19. :send-message-path="sendMessagePath"
  20. :send-message-img="sendMessageImg"
  21. :show-message-card="showMessageCard"
  22. :app-parameter="appParameter"
  23. :aria-label="ariaLabel"
  24. @tap="onClick"
  25. @getuserinfo="bindGetUserInfo"
  26. @contact="bindContact"
  27. @getphonenumber="bindGetPhoneNumber"
  28. @error="bindError"
  29. @launchapp="bindLaunchApp"
  30. @opensetting="bindOpenSetting"
  31. >
  32. <block :wx:if="loading">
  33. <van-loading custom-class="loading-class" :size="loadingSize" :type="loadingType" :color="type === 'default' ? '#c9c9c9' : 'white'" />
  34. <view :wx:if="loadingText" class="van-button__loading-text">
  35. {{ loadingText }}
  36. </view>
  37. </block>
  38. <block wx:else>
  39. <van-icon :wx:if="icon" size="1.2em" :name="icon" class="van-button__icon" custom-style="line-height: inherit;" />
  40. <view class="van-button__text">
  41. <slot />
  42. </view>
  43. </block>
  44. </button>
  45. </view>
  46. </template>
  47. <script>
  48. import { VantComponent } from '../common/component';
  49. import { button } from '../mixins/button';
  50. import { openType } from '../mixins/open-type';
  51. export default {
  52. data() {
  53. return {
  54. style: '',
  55. id: '',
  56. lang: '',
  57. openType: '',
  58. businessId: '',
  59. sessionFrom: '',
  60. sendMessageTitle: '',
  61. sendMessagePath: '',
  62. sendMessageImg: '',
  63. showMessageCard: '',
  64. appParameter: '',
  65. ariaLabel: ''
  66. };
  67. },
  68. mixins: [button, openType],
  69. classes: ['hover-class', 'loading-class'],
  70. props: {
  71. icon: String,
  72. plain: Boolean,
  73. block: Boolean,
  74. round: Boolean,
  75. square: Boolean,
  76. loading: Boolean,
  77. hairline: Boolean,
  78. disabled: Boolean,
  79. loadingText: String,
  80. customStyle: String,
  81. loadingType: {
  82. type: String,
  83. default: 'circular'
  84. },
  85. type: {
  86. type: String,
  87. default: 'default'
  88. },
  89. size: {
  90. type: String,
  91. default: 'normal'
  92. },
  93. loadingSize: {
  94. type: String,
  95. default: '20px'
  96. },
  97. color: {
  98. type: String
  99. }
  100. },
  101. methods: {
  102. onClick() {
  103. if (!this.disabled && !this.loading) {
  104. this.$emit('click');
  105. }
  106. },
  107. bindGetUserInfo() {
  108. console.log('占位:函数 bindGetUserInfo 未声明');
  109. },
  110. bindContact() {
  111. console.log('占位:函数 bindContact 未声明');
  112. },
  113. bindGetPhoneNumber() {
  114. console.log('占位:函数 bindGetPhoneNumber 未声明');
  115. },
  116. bindError() {
  117. console.log('占位:函数 bindError 未声明');
  118. },
  119. bindLaunchApp() {
  120. console.log('占位:函数 bindLaunchApp 未声明');
  121. },
  122. bindOpenSetting() {
  123. console.log('占位:函数 bindOpenSetting 未声明');
  124. }
  125. },
  126. watch: {
  127. color: {
  128. handler: function (color) {
  129. let style = '';
  130. if (color) {
  131. style += `color: ${this.plain ? color : 'white'};`;
  132. if (!this.plain) {
  133. // Use background instead of backgroundColor to make linear-gradient work
  134. style += `background: ${color};`;
  135. }
  136. // hide border when color is linear-gradient
  137. if (color.indexOf('gradient') !== -1) {
  138. style += 'border: 0;';
  139. } else {
  140. style += `border-color: ${color};`;
  141. }
  142. }
  143. if (style !== this.style) {
  144. this.setData({
  145. style
  146. });
  147. }
  148. },
  149. immediate: true
  150. }
  151. }
  152. };
  153. </script>
  154. <style>
  155. @import '../common/index.ttss';
  156. .van-button {
  157. position: relative;
  158. display: -webkit-inline-flex;
  159. display: inline-flex;
  160. -webkit-align-items: center;
  161. align-items: center;
  162. -webkit-justify-content: center;
  163. justify-content: center;
  164. box-sizing: border-box;
  165. padding: 0;
  166. line-height: 20px;
  167. text-align: center;
  168. vertical-align: middle;
  169. -webkit-appearance: none;
  170. -webkit-text-size-adjust: 100%;
  171. height: 44px;
  172. height: var(--button-default-height, 44px);
  173. font-size: 16px;
  174. font-size: var(--button-default-font-size, 16px);
  175. transition: opacity 0.2s;
  176. transition: opacity var(--animation-duration-fast, 0.2s);
  177. border-radius: 2px;
  178. border-radius: var(--button-border-radius, 2px);
  179. }
  180. .van-button:before {
  181. position: absolute;
  182. top: 50%;
  183. left: 50%;
  184. width: 100%;
  185. height: 100%;
  186. border: inherit;
  187. border-radius: inherit;
  188. -webkit-transform: translate(-50%, -50%);
  189. transform: translate(-50%, -50%);
  190. opacity: 0;
  191. content: ' ';
  192. background-color: #000;
  193. background-color: var(--black, #000);
  194. border-color: #000;
  195. border-color: var(--black, #000);
  196. }
  197. .van-button:after {
  198. border-width: 0;
  199. }
  200. .van-button--active:before {
  201. opacity: 0.15;
  202. }
  203. .van-button--unclickable:after {
  204. display: none;
  205. }
  206. .van-button--default {
  207. color: #323233;
  208. color: var(--button-default-color, #323233);
  209. background-color: #fff;
  210. background-color: var(--button-default-background-color, #fff);
  211. border: 1px solid #ebedf0;
  212. border: 1px solid var(--button-default-border-color, #ebedf0);
  213. }
  214. .van-button--primary {
  215. color: #fff;
  216. color: var(--button-primary-color, #fff);
  217. background-color: #07c160;
  218. background-color: var(--button-primary-background-color, #07c160);
  219. border: 1px solid #07c160;
  220. border: 1px solid var(--button-primary-border-color, #07c160);
  221. }
  222. .van-button--info {
  223. color: #fff;
  224. color: var(--button-info-color, #fff);
  225. background-color: #1989fa;
  226. background-color: var(--button-info-background-color, #1989fa);
  227. border: 1px solid #1989fa;
  228. border: 1px solid var(--button-info-border-color, #1989fa);
  229. }
  230. .van-button--danger {
  231. color: #fff;
  232. color: var(--button-danger-color, #fff);
  233. background-color: #ee0a24;
  234. background-color: var(--button-danger-background-color, #ee0a24);
  235. border: 1px solid #ee0a24;
  236. border: 1px solid var(--button-danger-border-color, #ee0a24);
  237. }
  238. .van-button--warning {
  239. color: #fff;
  240. color: var(--button-warning-color, #fff);
  241. background-color: #ff976a;
  242. background-color: var(--button-warning-background-color, #ff976a);
  243. border: 1px solid #ff976a;
  244. border: 1px solid var(--button-warning-border-color, #ff976a);
  245. }
  246. .van-button--plain {
  247. background-color: #fff;
  248. background-color: var(--button-plain-background-color, #fff);
  249. }
  250. .van-button--plain.van-button--primary {
  251. color: #07c160;
  252. color: var(--button-primary-background-color, #07c160);
  253. }
  254. .van-button--plain.van-button--info {
  255. color: #1989fa;
  256. color: var(--button-info-background-color, #1989fa);
  257. }
  258. .van-button--plain.van-button--danger {
  259. color: #ee0a24;
  260. color: var(--button-danger-background-color, #ee0a24);
  261. }
  262. .van-button--plain.van-button--warning {
  263. color: #ff976a;
  264. color: var(--button-warning-background-color, #ff976a);
  265. }
  266. .van-button--large {
  267. width: 100%;
  268. height: 50px;
  269. height: var(--button-large-height, 50px);
  270. }
  271. .van-button--normal {
  272. padding: 0 15px;
  273. font-size: 14px;
  274. font-size: var(--button-normal-font-size, 14px);
  275. }
  276. .van-button--small {
  277. min-width: 60px;
  278. min-width: var(--button-small-min-width, 60px);
  279. height: 30px;
  280. height: var(--button-small-height, 30px);
  281. padding: 0 8px;
  282. padding: 0 var(--padding-xs, 8px);
  283. font-size: 12px;
  284. font-size: var(--button-small-font-size, 12px);
  285. }
  286. .van-button--mini {
  287. display: inline-block;
  288. min-width: 50px;
  289. min-width: var(--button-mini-min-width, 50px);
  290. height: 22px;
  291. height: var(--button-mini-height, 22px);
  292. font-size: 10px;
  293. font-size: var(--button-mini-font-size, 10px);
  294. }
  295. .van-button--mini + .van-button--mini {
  296. margin-left: 5px;
  297. }
  298. .van-button--block {
  299. display: -webkit-flex;
  300. display: flex;
  301. width: 100%;
  302. }
  303. .van-button--round {
  304. border-radius: 999px;
  305. border-radius: var(--button-round-border-radius, 999px);
  306. }
  307. .van-button--square {
  308. border-radius: 0;
  309. }
  310. .van-button--disabled {
  311. opacity: 0.5;
  312. opacity: var(--button-disabled-opacity, 0.5);
  313. }
  314. .van-button__text {
  315. display: inline;
  316. }
  317. .van-button__icon + .van-button__text:not(:empty),
  318. .van-button__loading-text {
  319. margin-left: 4px;
  320. }
  321. .van-button__icon {
  322. min-width: 1em;
  323. line-height: inherit !important;
  324. vertical-align: top;
  325. }
  326. .van-button--hairline {
  327. padding-top: 1px;
  328. border-width: 0;
  329. }
  330. .van-button--hairline:after {
  331. border-color: inherit;
  332. border-width: 1px;
  333. border-radius: 4px;
  334. border-radius: calc(var(--button-border-radius, 2px) * 2);
  335. }
  336. .van-button--hairline.van-button--round:after {
  337. border-radius: 999px;
  338. border-radius: var(--button-round-border-radius, 999px);
  339. }
  340. .van-button--hairline.van-button--square:after {
  341. border-radius: 0;
  342. }
  343. </style>