fs-mask.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <view
  3. class="fs-mask"
  4. :class="{ 'fs-mask-blur': blurable }"
  5. :style="{ zIndex: zIndex }"
  6. v-if="modelValue"
  7. @click="handleMask"
  8. ></view>
  9. </template>
  10. <script>
  11. /**
  12. * 遮罩组件
  13. * @description 遮罩组件
  14. * @property {Boolean} blurable 毛玻璃效果
  15. * @property {Number} zIndex 层级
  16. * @property {Boolean} maskClickable 点击遮罩是否可关闭
  17. * @property {Boolean} bgColor 背景色
  18. * @event {Function} close 关闭事件
  19. */
  20. export default {
  21. name: 'fs-mask'
  22. }
  23. </script>
  24. <script setup>
  25. const props = defineProps({
  26. modelValue: Boolean,
  27. blurable: Boolean,
  28. zIndex: {
  29. type: Number,
  30. default: 899
  31. },
  32. maskClickable: {
  33. type: Boolean,
  34. default: true
  35. },
  36. bgColor: {
  37. type: String,
  38. default: 'rgba(0, 0, 0, 0.5)'
  39. }
  40. })
  41. const emits = defineEmits(['update:modelValue', 'close'])
  42. const handleMask = () => {
  43. if (props.maskClickable) {
  44. emits('update:modelValue', false)
  45. emits('close')
  46. }
  47. }
  48. </script>
  49. <style lang="scss">
  50. .fs-mask {
  51. position: fixed;
  52. top: var(--window-top);
  53. right: 0;
  54. bottom: var(--window-bottom);
  55. left: 0;
  56. background-color: v-bind(bgColor);
  57. &-blur {
  58. backdrop-filter: blur(12rpx);
  59. }
  60. }
  61. </style>