use-action-sheet.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. export default {
  24. props: {
  25. // 点击遮罩是否可以关闭actionsheet
  26. maskCloseAble: {
  27. type: Boolean,
  28. default: true
  29. },
  30. // 按钮的文字数组,可以自定义颜色和字体大小,字体单位为rpx
  31. list: {
  32. type: Array,
  33. default () {
  34. // 如下
  35. // return [{
  36. // text: '确定',
  37. // color: '',
  38. // fontSize: ''
  39. // }]
  40. return [];
  41. }
  42. },
  43. // 顶部的提示文字
  44. tips: {
  45. type: Object,
  46. default () {
  47. return {
  48. text: '',
  49. color: '',
  50. fontSize: '26'
  51. }
  52. }
  53. },
  54. // 底部的取消按钮
  55. cancelBtn: {
  56. type: Boolean,
  57. default: true
  58. },
  59. // 是否开启底部安全区适配,开启的话,会在iPhoneX机型底部添加一定的内边距
  60. safeAreaInsetBottom: {
  61. type: Boolean,
  62. default: true
  63. },
  64. // 通过双向绑定控制组件的弹出与收起
  65. value: {
  66. type: Boolean,
  67. default: false
  68. },
  69. // 弹出的顶部圆角值
  70. borderRadius: {
  71. type: [String, Number],
  72. default: 0
  73. },
  74. // 弹出的z-index值
  75. zIndex: {
  76. type: [String, Number],
  77. default: 10030
  78. }
  79. },
  80. watch: {
  81. list(nv, ov) {
  82. console.log('use-action-sheet', {nv:nv, ov:ov});
  83. this.datas = nv;
  84. }
  85. },
  86. data() {
  87. return {
  88. datas: []
  89. }
  90. },
  91. computed: {
  92. // 顶部提示的样式
  93. tipsStyle() {
  94. let style = {};
  95. if (this.tips.color) style.color = this.tips.color;
  96. if (this.tips.fontSize) style.fontSize = this.tips.fontSize + 'rpx';
  97. return style;
  98. },
  99. // 操作项目的样式
  100. itemStyle(index) {
  101. return (index) => {
  102. let style = {};
  103. if (this.list[index].color) style.color = this.list[index].color;
  104. if (this.list[index].fontSize) style.fontSize = this.list[index].fontSize + 'rpx';
  105. return style;
  106. }
  107. }
  108. },
  109. methods: {
  110. // 弹窗关闭回执事件
  111. popupClose() {
  112. this.$emit('input', false);
  113. this.$emit('close');
  114. },
  115. // 手动点击取消按钮
  116. closeClick() {
  117. this.$emit('input', false);
  118. },
  119. // 操作菜单 item 点击事件
  120. itemClick(index) {
  121. this.$emit('click', index);
  122. this.$emit('input', false);
  123. }
  124. }
  125. }
  126. </script>
  127. <style lang="scss"></style>