fs-action.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <fs-popup direction="bottom" height="auto" v-model="visible" :showMask="showMask" :maskClickable="maskClickable">
  3. <view class="fs-action">
  4. <view class="fs-action-item" v-for="(item, index) in list" :key="index" @click="handleAction(item)">
  5. {{ item.name }}
  6. </view>
  7. <view class="fs-action-extra"><slot></slot></view>
  8. <view class="fs-action-cancel" v-if="showCancel" @click="cancel">{{ cancelText }}</view>
  9. </view>
  10. </fs-popup>
  11. </template>
  12. <script>
  13. /**
  14. * 动作组件
  15. * @description 动作组件
  16. * @property {Array} list action列表
  17. * @property {Boolean} showMask 是否展示遮罩
  18. * @property {Boolean} maskClickable 遮罩是否可点击
  19. * @property {Boolean} showCancel 是否展示取消action
  20. * @property {String} cancelText “取消”文字
  21. * @event {Function} change change事件
  22. * @example <fs-action :list="list" v-model="show" @change="change"></fs-action>
  23. */
  24. export default {
  25. name: 'fs-action'
  26. }
  27. </script>
  28. <script setup>
  29. import { computed } from 'vue'
  30. const props = defineProps({
  31. list: Array,
  32. modelValue: Boolean,
  33. showMask: {
  34. type: Boolean,
  35. default: true
  36. },
  37. maskClickable: {
  38. type: Boolean,
  39. default: true
  40. },
  41. cancelText: {
  42. type: String,
  43. default: '取消'
  44. },
  45. showCancel: {
  46. type: Boolean,
  47. default: true
  48. }
  49. })
  50. const emits = defineEmits(['update:modelValue', 'change'])
  51. const visible = computed({
  52. get: () => props.modelValue,
  53. set: value => emits('update:modelValue', value)
  54. })
  55. const cancel = () => {
  56. emits('update:modelValue', false)
  57. }
  58. const handleAction = item => {
  59. emits('change', item)
  60. cancel()
  61. }
  62. </script>
  63. <style lang="scss" scoped>
  64. .fs-action {
  65. background-color: #f8f8f8;
  66. &-item {
  67. padding: 20rpx;
  68. text-align: center;
  69. background-color: #fff;
  70. & + & {
  71. border-top: 1px solid var(--border-color);
  72. }
  73. }
  74. &-cancel {
  75. padding: 20rpx;
  76. text-align: center;
  77. background-color: #fff;
  78. margin-top: 10rpx;
  79. }
  80. }
  81. </style>