fs-popup.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <view class="fs-popup">
  3. <view class="fs-popup-drawer" :class="[direction,{show:modelValue}]" :style="[style,customStyle]">
  4. <slot></slot>
  5. </view>
  6. <fs-mask v-if="showMask" :modelValue="modelValue" @close="handleClose" :maskClickable="maskClickable"></fs-mask>
  7. </view>
  8. </template>
  9. <script setup>
  10. import { computed } from 'vue'
  11. const props = defineProps({
  12. modelValue: Boolean,
  13. direction: {
  14. type: String,
  15. default: 'left',
  16. validator(value) {
  17. return ['left', 'right', 'top', 'bottom'].includes(value)
  18. }
  19. },
  20. width: {
  21. type: String,
  22. default: '80%'
  23. },
  24. height: {
  25. type: String,
  26. default: '30%'
  27. },
  28. showMask: {
  29. type: Boolean,
  30. default: true
  31. },
  32. maskClickable: {
  33. type: Boolean,
  34. default: true
  35. },
  36. customStyle: {
  37. type: Object,
  38. default() {
  39. return {}
  40. }
  41. }
  42. })
  43. const style = computed(() => {
  44. let ret = ''
  45. if (props.direction === 'left' || props.direction === 'right') {
  46. ret = `width: ${props.width}`
  47. } else {
  48. ret = `height: ${props.height}`
  49. }
  50. return ret
  51. })
  52. const emits = defineEmits(['update:modelValue'])
  53. const handleClose = () => {
  54. emits('update:modelValue', false)
  55. }
  56. </script>
  57. <style lang="scss" scoped>
  58. .fs-popup {
  59. &-drawer{
  60. position: fixed;
  61. background-color: #fff;
  62. z-index: 900;
  63. transition: all .3s;
  64. overflow: auto;
  65. }
  66. .left{
  67. top: var(--window-top);
  68. bottom: var(--window-bottom);
  69. left: 0;
  70. transform: translateX(-100%);
  71. }
  72. .right{
  73. top: var(--window-top);
  74. bottom: var(--window-bottom);
  75. right: 0;
  76. transform: translateX(100%);
  77. }
  78. .top{
  79. top: var(--window-top);
  80. right: 0;
  81. left: 0;
  82. transform: translateY(-200%);
  83. }
  84. .bottom{
  85. left: 0;
  86. bottom: var(--window-bottom);
  87. right: 0;
  88. transform: translateY(100%);
  89. }
  90. .show{
  91. transform: translateX(0);
  92. }
  93. }
  94. </style>