index.vue 7.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <uni-shadow-root class="vant-button-index"><button :id="id || buttonId" :data-detail="dataset" :class="'custom-class '+(utils.bem('button', [type, size, { block, round, plain, square, loading, disabled, hairline, unclickable: disabled || loading }]))+' '+(hairline ? 'van-hairline--surround' : '')" :hover-class="disabled || loading ? '' : 'van-button--active hover-class'" :lang="lang" :form-type="formType" :style="computed.rootStyle({ plain, color, customStyle })" :open-type="disabled || loading || (canIUseGetUserProfile && openType === 'getUserInfo') ? '' : openType" :business-id="businessId" :session-from="sessionFrom" :send-message-title="sendMessageTitle" :send-message-path="sendMessagePath" :send-message-img="sendMessageImg" :show-message-card="showMessageCard" :app-parameter="appParameter" :aria-label="ariaLabel" @click="_$self[(disabled || loading ? '' : 'onClick')||'_$noop']($event)" @getuserinfo="onGetUserInfo" @contact="onContact" @getphonenumber="onGetPhoneNumber" @getrealtimephonenumber="onGetRealTimePhoneNumber" @agreeprivacyauthorization="onAgreePrivacyAuthorization" @error="onError" @launchapp="onLaunchApp" @opensetting="onOpenSetting" @chooseavatar="onChooseAvatar">
  3. <block v-if="loading">
  4. <van-loading custom-class="loading-class" :size="loadingSize" :type="loadingType" :color="computed.loadingColor({ type, color, plain })"></van-loading>
  5. <view v-if="loadingText" class="van-button__loading-text">
  6. {{ loadingText }}
  7. </view>
  8. </block>
  9. <block v-else>
  10. <van-icon v-if="icon" size="1.2em" :name="icon" :class-prefix="classPrefix" class="van-button__icon" custom-style="line-height: inherit;"></van-icon>
  11. <view class="van-button__text">
  12. <slot></slot>
  13. </view>
  14. </block>
  15. </button></uni-shadow-root>
  16. </template>
  17. <wxs src="../wxs/utils.wxs" module="utils"></wxs><wxs src="./index.wxs" module="computed"></wxs>
  18. <script>
  19. import VanIcon from '../icon/index.vue'
  20. import VanLoading from '../loading/index.vue'
  21. global['__wxVueOptions'] = {components:{'van-icon': VanIcon,'van-loading': VanLoading}}
  22. global['__wxRoute'] = 'vant/button/index'
  23. import { VantComponent } from '../common/component';
  24. import { button } from '../mixins/button';
  25. import { canIUseFormFieldButton } from '../common/version';
  26. const mixins = [button];
  27. if (canIUseFormFieldButton()) {
  28. mixins.push('wx://form-field-button');
  29. }
  30. VantComponent({
  31. mixins,
  32. classes: ['hover-class', 'loading-class'],
  33. data: {
  34. baseStyle: '',
  35. },
  36. props: {
  37. formType: String,
  38. icon: String,
  39. classPrefix: {
  40. type: String,
  41. value: 'van-icon',
  42. },
  43. plain: Boolean,
  44. block: Boolean,
  45. round: Boolean,
  46. square: Boolean,
  47. loading: Boolean,
  48. hairline: Boolean,
  49. disabled: Boolean,
  50. loadingText: String,
  51. customStyle: String,
  52. loadingType: {
  53. type: String,
  54. value: 'circular',
  55. },
  56. type: {
  57. type: String,
  58. value: 'default',
  59. },
  60. dataset: null,
  61. size: {
  62. type: String,
  63. value: 'normal',
  64. },
  65. loadingSize: {
  66. type: String,
  67. value: '20px',
  68. },
  69. color: String,
  70. },
  71. methods: {
  72. onClick(event) {
  73. this.$emit('click', event);
  74. const { canIUseGetUserProfile, openType, getUserProfileDesc, lang, } = this.data;
  75. if (openType === 'getUserInfo' && canIUseGetUserProfile) {
  76. wx.getUserProfile({
  77. desc: getUserProfileDesc || ' ',
  78. lang: lang || 'en',
  79. complete: (userProfile) => {
  80. this.$emit('getuserinfo', userProfile);
  81. },
  82. });
  83. }
  84. },
  85. },
  86. });
  87. export default global['__wxComponents']['vant/button/index']
  88. </script>
  89. <style platform="mp-weixin">
  90. @import '../common/index.css';.van-button{-webkit-text-size-adjust:100%;align-items:center;-webkit-appearance:none;border-radius:var(--button-border-radius,2px);box-sizing:border-box;display:inline-flex;font-size:var(--button-default-font-size,16px);height:var(--button-default-height,44px);justify-content:center;line-height:var(--button-line-height,20px);padding:0;position:relative;text-align:center;transition:opacity .2s;vertical-align:middle}.van-button:before{background-color:#000;border:inherit;border-color:#000;border-radius:inherit;content:" ";height:100%;left:50%;opacity:0;position:absolute;top:50%;transform:translate(-50%,-50%);width:100%}.van-button:after{border-width:0}.van-button--active:before{opacity:.15}.van-button--unclickable:after{display:none}.van-button--default{background:var(--button-default-background-color,#fff);border:var(--button-border-width,1px) solid var(--button-default-border-color,#ebedf0);color:var(--button-default-color,#323233)}.van-button--primary{background:var(--button-primary-background-color,#07c160);border:var(--button-border-width,1px) solid var(--button-primary-border-color,#07c160);color:var(--button-primary-color,#fff)}.van-button--info{background:var(--button-info-background-color,#1989fa);border:var(--button-border-width,1px) solid var(--button-info-border-color,#1989fa);color:var(--button-info-color,#fff)}.van-button--danger{background:var(--button-danger-background-color,#ee0a24);border:var(--button-border-width,1px) solid var(--button-danger-border-color,#ee0a24);color:var(--button-danger-color,#fff)}.van-button--warning{background:var(--button-warning-background-color,#ff976a);border:var(--button-border-width,1px) solid var(--button-warning-border-color,#ff976a);color:var(--button-warning-color,#fff)}.van-button--plain{background:var(--button-plain-background-color,#fff)}.van-button--plain.van-button--primary{color:var(--button-primary-background-color,#07c160)}.van-button--plain.van-button--info{color:var(--button-info-background-color,#1989fa)}.van-button--plain.van-button--danger{color:var(--button-danger-background-color,#ee0a24)}.van-button--plain.van-button--warning{color:var(--button-warning-background-color,#ff976a)}.van-button--large{height:var(--button-large-height,50px);width:100%}.van-button--normal{font-size:var(--button-normal-font-size,14px);padding:0 15px}.van-button--small{font-size:var(--button-small-font-size,12px);height:var(--button-small-height,30px);min-width:var(--button-small-min-width,60px);padding:0 var(--padding-xs,8px)}.van-button--mini{display:inline-block;font-size:var(--button-mini-font-size,10px);height:var(--button-mini-height,22px);min-width:var(--button-mini-min-width,50px)}.van-button--mini+.van-button--mini{margin-left:5px}.van-button--block{display:flex;width:100%}.van-button--round{border-radius:var(--button-round-border-radius,999px)}.van-button--square{border-radius:0}.van-button--disabled{opacity:var(--button-disabled-opacity,.5)}.van-button__text{display:inline}.van-button__icon+.van-button__text:not(:empty),.van-button__loading-text{margin-left:4px}.van-button__icon{line-height:inherit!important;min-width:1em;vertical-align:top}.van-button--hairline{border-width:0;padding-top:1px}.van-button--hairline:after{border-color:inherit;border-radius:calc(var(--button-border-radius, 2px)*2);border-width:1px}.van-button--hairline.van-button--round:after{border-radius:var(--button-round-border-radius,999px)}.van-button--hairline.van-button--square:after{border-radius:0}
  91. </style>