wk-action-sheet.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <view class="wk-action-sheet">
  3. <view class="sheet-wrapper">
  4. <view
  5. v-for="(item, index) in list"
  6. :key="index"
  7. class="sheet-item"
  8. @click="handleSelect(index)">
  9. {{ label ? item[label] : item }}
  10. </view>
  11. </view>
  12. <view
  13. v-if="!hideCancel"
  14. class="sheet-item cancel"
  15. @click="handleCancel">
  16. {{ cancelText }}
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. /**
  22. * ActionSheet 弹出层
  23. * @property {String} cancelText 取消按钮文字
  24. * @property {Boolean} hideCancel 是否隐藏取消按钮
  25. * @property {Array<Object|String>} list 选项数组
  26. * @property {String} label 选项label字段key
  27. * @event {Function} select 选择选项触发,index item nextFn
  28. */
  29. export default {
  30. name: 'WkActionSheet',
  31. inject: ['popup'],
  32. props: {
  33. cancelText: {
  34. type: String,
  35. default: '取消'
  36. },
  37. hideCancel: {
  38. type: Boolean,
  39. default: false
  40. },
  41. list: {
  42. type: Array,
  43. default: () => []
  44. },
  45. label: {
  46. type: String,
  47. default: null
  48. }
  49. },
  50. data() {
  51. return {
  52. };
  53. },
  54. methods: {
  55. handleCancel() {
  56. this.popup.close()
  57. },
  58. handleSelect(index) {
  59. this.$emit('select', index, this.list[index], () => {
  60. this.popup.close()
  61. })
  62. }
  63. }
  64. }
  65. </script>
  66. <style scoped lang="scss">
  67. .wk-action-sheet {
  68. width: 100%;
  69. display: flex;
  70. flex-direction: column;
  71. background-color: $main-bg;
  72. border-radius: 10rpx 10rpx 0 0;
  73. overflow: hidden;
  74. .sheet-wrapper {
  75. width: 100%;
  76. background-color: $main-bg;
  77. overflow: hidden;
  78. }
  79. .sheet-item {
  80. width: 100%;
  81. color: #333;
  82. font-size: $wk-font-medium;
  83. text-align: center;
  84. border-bottom: 1rpx solid $border-color;
  85. background-color: white;
  86. padding: 22rpx 18rpx;
  87. }
  88. .cancel {
  89. color: $error;
  90. border-bottom: 0 none;
  91. margin-top: 15rpx;
  92. }
  93. }
  94. </style>