use-action-sheet.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <use-popup mode="bottom" v-model="value"
  3. length="auto"
  4. :border-radius="borderRadius"
  5. :popup="false"
  6. :maskCloseAble="maskCloseAble"
  7. :safeAreaInsetBottom="safeAreaInsetBottom"
  8. :z-index="zIndex"
  9. @close="popupClose">
  10. <view v-if="tips.text" class="fs-sm padding-tb tac border-bottom" :style="[tipsStyle]">
  11. {{tips.text}}
  12. </view>
  13. <block v-for="(item, index) in datas" :key="index">
  14. <view class="dflex-c padding-tb line-height-1" :class="[index < datas.length - 1 ? 'border-bottom' : '']" :style="[itemStyle(index)]" hover-class="use-hover-class" :hover-stay-time="150" @touchmove.stop.prevent @tap="itemClick(index)">
  15. {{item.text}}
  16. </view>
  17. </block>
  18. <view v-if="cancelBtn" class="gap"></view>
  19. <view v-if="cancelBtn" class="dflex-c padding-tb line-height-1" hover-class="use-hover-class" :hover-stay-time="150" @touchmove.stop.prevent @tap="closeClick">取消</view>
  20. </use-popup>
  21. </template>
  22. <script>
  23. import usePopup from '../use-popup/use-popup.vue'
  24. export default {
  25. components:{
  26. usePopup
  27. },
  28. props: {
  29. // 点击遮罩是否可以关闭actionsheet
  30. maskCloseAble: {
  31. type: Boolean,
  32. default: true
  33. },
  34. // 按钮的文字数组,可以自定义颜色和字体大小,字体单位为rpx
  35. list: {
  36. type: Array,
  37. default () {
  38. // 如下
  39. // return [{
  40. // text: '确定',
  41. // color: '',
  42. // fontSize: ''
  43. // }]
  44. return [];
  45. }
  46. },
  47. // 顶部的提示文字
  48. tips: {
  49. type: Object,
  50. default () {
  51. return {
  52. text: '',
  53. color: '',
  54. fontSize: '26'
  55. }
  56. }
  57. },
  58. // 底部的取消按钮
  59. cancelBtn: {
  60. type: Boolean,
  61. default: true
  62. },
  63. // 是否开启底部安全区适配,开启的话,会在iPhoneX机型底部添加一定的内边距
  64. safeAreaInsetBottom: {
  65. type: Boolean,
  66. default: true
  67. },
  68. // 通过双向绑定控制组件的弹出与收起
  69. value: {
  70. type: Boolean,
  71. default: false
  72. },
  73. // 弹出的顶部圆角值
  74. borderRadius: {
  75. type: [String, Number],
  76. default: 0
  77. },
  78. // 弹出的z-index值
  79. zIndex: {
  80. type: [String, Number],
  81. default: 10030
  82. }
  83. },
  84. watch: {
  85. list(nv, ov) {
  86. console.log('use-action-sheet', {nv:nv, ov:ov});
  87. this.datas = nv;
  88. }
  89. },
  90. data() {
  91. return {
  92. datas: []
  93. }
  94. },
  95. computed: {
  96. // 顶部提示的样式
  97. tipsStyle() {
  98. let style = {};
  99. if (this.tips.color) style.color = this.tips.color;
  100. if (this.tips.fontSize) style.fontSize = this.tips.fontSize + 'rpx';
  101. return style;
  102. },
  103. // 操作项目的样式
  104. itemStyle(index) {
  105. return (index) => {
  106. let style = {};
  107. if (this.list[index].color) style.color = this.list[index].color;
  108. if (this.list[index].fontSize) style.fontSize = this.list[index].fontSize + 'rpx';
  109. return style;
  110. }
  111. }
  112. },
  113. methods: {
  114. // 弹窗关闭回执事件
  115. popupClose() {
  116. this.$emit('input', false);
  117. this.$emit('close');
  118. },
  119. // 手动点击取消按钮
  120. closeClick() {
  121. this.$emit('input', false);
  122. },
  123. // 操作菜单 item 点击事件
  124. itemClick(index) {
  125. this.$emit('click', index);
  126. this.$emit('input', false);
  127. }
  128. }
  129. }
  130. </script>
  131. <style lang="scss"></style>