index.vue 5.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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" :safe-area-inset-bottom="safeAreaInsetBottom" :close-on-click-overlay="closeOnClickOverlay" @close="onClickOverlay">
  3. <view v-if="title" class="van-hairline--bottom van-action-sheet__header">
  4. {{ title }}
  5. <van-icon name="close" custom-class="van-action-sheet__close" @click="onClose"></van-icon>
  6. </view>
  7. <view v-if="description" class="van-action-sheet__description">
  8. {{ description }}
  9. </view>
  10. <view v-if="actions && actions.length">
  11. <button v-for="(item,index) in (actions)" :key="item.index" :open-type="item.openType" :style="item.color ? 'color: ' + item.color : ''" :class="(utils.bem('action-sheet__item', { disabled: item.disabled || item.loading }))+' van-hairline--top '+(item.className || '')" hover-class="van-action-sheet__item--hover" :data-index="index" @click="onSelect">
  12. <block v-if="(!item.loading)">
  13. {{ item.name }}
  14. <text v-if="item.subname" class="van-action-sheet__subname">{{ item.subname }}</text>
  15. </block>
  16. <van-loading v-else custom-class="van-action-sheet__loading" size="20px"></van-loading>
  17. </button>
  18. </view>
  19. <slot></slot>
  20. <view v-if="cancelText" class="van-action-sheet__cancel" hover-class="van-action-sheet__cancel--hover" hover-stay-time="70" @click="onCancel">
  21. {{ cancelText }}
  22. </view>
  23. </van-popup></uni-shadow-root>
  24. </template>
  25. <wxs src="../wxs/utils.wxs" module="utils"></wxs>
  26. <script>
  27. import VanIcon from '../icon/index.vue'
  28. import VanPopup from '../popup/index.vue'
  29. import VanLoading from '../loading/index.vue'
  30. global['__wxVueOptions'] = {components:{'van-icon': VanIcon,'van-popup': VanPopup,'van-loading': VanLoading}}
  31. global['__wxRoute'] = 'vant/action-sheet/index'
  32. import { VantComponent } from '../common/component';
  33. VantComponent({
  34. props: {
  35. show: Boolean,
  36. title: String,
  37. cancelText: String,
  38. description: String,
  39. round: {
  40. type: Boolean,
  41. value: true
  42. },
  43. zIndex: {
  44. type: Number,
  45. value: 100
  46. },
  47. actions: {
  48. type: Array,
  49. value: []
  50. },
  51. overlay: {
  52. type: Boolean,
  53. value: true
  54. },
  55. closeOnClickOverlay: {
  56. type: Boolean,
  57. value: true
  58. },
  59. closeOnClickAction: {
  60. type: Boolean,
  61. value: true
  62. },
  63. safeAreaInsetBottom: {
  64. type: Boolean,
  65. value: true
  66. }
  67. },
  68. methods: {
  69. onSelect(event) {
  70. const { index } = event.currentTarget.dataset;
  71. const item = this.data.actions[index];
  72. if (item && !item.disabled && !item.loading) {
  73. this.$emit('select', item);
  74. if (this.data.closeOnClickAction) {
  75. this.onClose();
  76. }
  77. }
  78. },
  79. onCancel() {
  80. this.$emit('cancel');
  81. },
  82. onClose() {
  83. this.$emit('close');
  84. },
  85. onClickOverlay() {
  86. this.$emit('click-overlay');
  87. this.onClose();
  88. }
  89. }
  90. });
  91. export default global['__wxComponents']['vant/action-sheet/index']
  92. </script>
  93. <style platform="mp-weixin">
  94. @import '../common/index.css';.van-action-sheet{max-height:90%!important;max-height:var(--action-sheet-max-height,90%)!important;color:#323233;color:var(--action-sheet-item-text-color,#323233)}.van-action-sheet__cancel,.van-action-sheet__item{text-align:center;font-size:16px;font-size:var(--action-sheet-item-font-size,16px);line-height:50px;line-height:var(--action-sheet-item-height,50px);background-color:#fff;background-color:var(--action-sheet-item-background,#fff)}.van-action-sheet__cancel--hover,.van-action-sheet__item--hover{background-color:#f2f3f5;background-color:var(--active-color,#f2f3f5)}.van-action-sheet__cancel:before{display:block;content:" ";height:8px;height:var(--action-sheet-cancel-padding-top,8px);background-color:#f7f8fa;background-color:var(--action-sheet-cancel-padding-color,#f7f8fa)}.van-action-sheet__item--disabled{color:#c8c9cc;color:var(--action-sheet-item-disabled-text-color,#c8c9cc)}.van-action-sheet__item--disabled.van-action-sheet__item--hover{background-color:#fff;background-color:var(--action-sheet-item-background,#fff)}.van-action-sheet__subname{margin-left:4px;margin-left:var(--padding-base,4px);font-size:12px;font-size:var(--action-sheet-subname-font-size,12px);color:#646566;color:var(--action-sheet-subname-color,#646566)}.van-action-sheet__header{text-align:center;font-weight:500;font-weight:var(--font-weight-bold,500);font-size:16px;font-size:var(--action-sheet-header-font-size,16px);line-height:44px;line-height:var(--action-sheet-header-height,44px)}.van-action-sheet__description{text-align:center;padding:16px;padding:var(--padding-md,16px);color:#646566;color:var(--action-sheet-description-color,#646566);font-size:14px;font-size:var(--action-sheet-description-font-size,14px);line-height:20px;line-height:var(--action-sheet-description-line-height,20px)}.van-action-sheet__close{position:absolute!important;top:0;right:0;line-height:inherit!important;padding:0 12px;padding:var(--action-sheet-close-icon-padding,0 12px);font-size:18px!important;font-size:var(--action-sheet-close-icon-size,18px)!important;color:#969799;color:var(--action-sheet-close-icon-color,#969799)}.van-action-sheet__loading{display:-webkit-flex!important;display:flex!important;height:50px;height:var(--action-sheet-item-height,50px)}
  95. </style>