index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <uni-shadow-root class="vant-action-sheet-index"><van-popup :show="show" position="bottom" :round="round" :z-index="zIndex" :overlay="overlay" custom-class="van-action-sheet custom-class" :safe-area-inset-bottom="safeAreaInsetBottom" :close-on-click-overlay="closeOnClickOverlay" :root-portal="rootPortal" @close="onClickOverlay">
  3. <view v-if="title" class="van-action-sheet__header">
  4. {{ title }}
  5. <van-icon name="cross" custom-class="van-action-sheet__close" @click="onClose"></van-icon>
  6. </view>
  7. <view v-if="description" class="van-action-sheet__description van-hairline--bottom">
  8. {{ description }}
  9. </view>
  10. <view v-if="actions && actions.length" class="list-class">
  11. <button v-for="(item,index) in (actions)" :key="item.index" :open-type="item.disabled || item.loading || (canIUseGetUserProfile && item.openType === 'getUserInfo') ? '' : item.openType" :style="item.color ? 'color: ' + item.color : ''" :class="(utils.bem('action-sheet__item', { disabled: item.disabled || item.loading }))+' '+(item.className || '')" hover-class="van-action-sheet__item--hover" :data-index="index" @click="_$self[(item.disabled || item.loading ? '' : 'onSelect')||'_$noop']($event)" @getuserinfo="onGetUserInfo" @contact="onContact" @getphonenumber="onGetPhoneNumber" @error="onError" @launchapp="onLaunchApp" @opensetting="onOpenSetting" :lang="lang" :session-from="sessionFrom" :send-message-title="sendMessageTitle" :send-message-path="sendMessagePath" :send-message-img="sendMessageImg" :show-message-card="showMessageCard" :app-parameter="appParameter">
  12. <block v-if="(!item.loading)">
  13. {{ item.name }}
  14. <view v-if="item.subname" class="van-action-sheet__subname">{{ item.subname }}</view>
  15. </block>
  16. <van-loading v-else custom-class="van-action-sheet__loading" size="22px"></van-loading>
  17. </button>
  18. </view>
  19. <slot></slot>
  20. <block v-if="cancelText">
  21. <view class="van-action-sheet__gap"></view>
  22. <view class="van-action-sheet__cancel" hover-class="van-action-sheet__cancel--hover" hover-stay-time="70" @click="onCancel">
  23. {{ cancelText }}
  24. </view>
  25. </block>
  26. </van-popup></uni-shadow-root>
  27. </template>
  28. <wxs src="../wxs/utils.wxs" module="utils"></wxs>
  29. <script>
  30. import VanIcon from '../icon/index.vue'
  31. import VanPopup from '../popup/index.vue'
  32. import VanLoading from '../loading/index.vue'
  33. global['__wxVueOptions'] = {components:{'van-icon': VanIcon,'van-popup': VanPopup,'van-loading': VanLoading}}
  34. global['__wxRoute'] = 'vant/action-sheet/index'
  35. import { VantComponent } from '../common/component';
  36. import { button } from '../mixins/button';
  37. VantComponent({
  38. classes: ['list-class'],
  39. mixins: [button],
  40. props: {
  41. show: Boolean,
  42. title: String,
  43. cancelText: String,
  44. description: String,
  45. round: {
  46. type: Boolean,
  47. value: true,
  48. },
  49. zIndex: {
  50. type: Number,
  51. value: 100,
  52. },
  53. actions: {
  54. type: Array,
  55. value: [],
  56. },
  57. overlay: {
  58. type: Boolean,
  59. value: true,
  60. },
  61. closeOnClickOverlay: {
  62. type: Boolean,
  63. value: true,
  64. },
  65. closeOnClickAction: {
  66. type: Boolean,
  67. value: true,
  68. },
  69. safeAreaInsetBottom: {
  70. type: Boolean,
  71. value: true,
  72. },
  73. rootPortal: {
  74. type: Boolean,
  75. value: false,
  76. },
  77. },
  78. methods: {
  79. onSelect(event) {
  80. const { index } = event.currentTarget.dataset;
  81. const { actions, closeOnClickAction, canIUseGetUserProfile } = this.data;
  82. const item = actions[index];
  83. if (item) {
  84. this.$emit('select', item);
  85. if (closeOnClickAction) {
  86. this.onClose();
  87. }
  88. if (item.openType === 'getUserInfo' && canIUseGetUserProfile) {
  89. wx.getUserProfile({
  90. desc: item.getUserProfileDesc || ' ',
  91. complete: (userProfile) => {
  92. this.$emit('getuserinfo', userProfile);
  93. },
  94. });
  95. }
  96. }
  97. },
  98. onCancel() {
  99. this.$emit('cancel');
  100. },
  101. onClose() {
  102. this.$emit('close');
  103. },
  104. onClickOverlay() {
  105. this.$emit('click-overlay');
  106. this.onClose();
  107. },
  108. },
  109. });
  110. export default global['__wxComponents']['vant/action-sheet/index']
  111. </script>
  112. <style platform="mp-weixin">
  113. @import '../common/index.css';.van-action-sheet{color:var(--action-sheet-item-text-color,#323233);max-height:var(--action-sheet-max-height,90%)!important}.van-action-sheet__cancel,.van-action-sheet__item{background-color:var(--action-sheet-item-background,#fff);font-size:var(--action-sheet-item-font-size,16px);line-height:var(--action-sheet-item-line-height,22px);padding:14px 16px;text-align:center}.van-action-sheet__cancel--hover,.van-action-sheet__item--hover{background-color:#f2f3f5}.van-action-sheet__cancel:after,.van-action-sheet__item:after{border-width:0}.van-action-sheet__cancel{color:var(--action-sheet-cancel-text-color,#646566)}.van-action-sheet__gap{background-color:var(--action-sheet-cancel-padding-color,#f7f8fa);display:block;height:var(--action-sheet-cancel-padding-top,8px)}.van-action-sheet__item--disabled{color:var(--action-sheet-item-disabled-text-color,#c8c9cc)}.van-action-sheet__item--disabled.van-action-sheet__item--hover{background-color:var(--action-sheet-item-background,#fff)}.van-action-sheet__subname{color:var(--action-sheet-subname-color,#969799);font-size:var(--action-sheet-subname-font-size,12px);line-height:var(--action-sheet-subname-line-height,20px);margin-top:var(--padding-xs,8px)}.van-action-sheet__header{font-size:var(--action-sheet-header-font-size,16px);font-weight:var(--font-weight-bold,500);line-height:var(--action-sheet-header-height,48px);text-align:center}.van-action-sheet__description{color:var(--action-sheet-description-color,#969799);font-size:var(--action-sheet-description-font-size,14px);line-height:var(--action-sheet-description-line-height,20px);padding:20px var(--padding-md,16px);text-align:center}.van-action-sheet__close{color:var(--action-sheet-close-icon-color,#c8c9cc);font-size:var(--action-sheet-close-icon-size,22px)!important;line-height:inherit!important;padding:var(--action-sheet-close-icon-padding,0 16px);position:absolute!important;right:0;top:0}.van-action-sheet__loading{display:flex!important}
  114. </style>