xm-popup.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <view class="xm-popup-wrap" :class="{
  3. 'xm-popup-wrap-show': show,
  4. 'xm-popup-wrap-show-content': showContent,
  5. }" :style="{
  6. zIndex: zIndex,
  7. background: maskBackground
  8. }" @tap.stop="toClose" @touchmove.stop.prevent="stop" :animation="animationData">
  9. <view class="xm-popup-cnt" :class="{
  10. 'xm-popup-cnt-show-content': showContent,
  11. 'xm-anim': anim,
  12. }" :style="{
  13. borderTopLeftRadius: radius + 'px',
  14. borderTopRightRadius: radius + 'px',
  15. background: background
  16. }" @tap.stop="stop">
  17. <slot></slot>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. export default {
  23. name: 'xm-popup',
  24. emits: ['close'],
  25. props: {
  26. // 是否显示弹出层
  27. show: {
  28. type: Boolean,
  29. default: false
  30. },
  31. // 弹出层内容背景颜色
  32. background: {
  33. type: String,
  34. default: '#FFFFFF'
  35. },
  36. // 弹出层内容圆角
  37. radius: {
  38. type: [Number, String],
  39. default: 0
  40. },
  41. // 弹出层的z-index
  42. zIndex: {
  43. type: [Number, String],
  44. default: 1992
  45. },
  46. // 点击遮罩, 是否可关闭
  47. maskClosable: {
  48. type: Boolean,
  49. default: true
  50. },
  51. // 遮罩的背景色
  52. maskBackground: {
  53. type: String,
  54. default: 'rgba(0,0,0,0.6)'
  55. },
  56. // 是否直接显示键盘
  57. showContent: {
  58. type: Boolean,
  59. default: false
  60. },
  61. // 是否加入动画效果
  62. anim: {
  63. type: Boolean,
  64. default: true
  65. }
  66. },
  67. data() {
  68. return {
  69. isShow: false,
  70. animation: {},
  71. animationData: {}
  72. }
  73. },
  74. methods: {
  75. toClose(e) {
  76. if (!this.maskClosable) return;
  77. this.$emit('close', {});
  78. },
  79. stop(e) {
  80. },
  81. },
  82. };
  83. </script>
  84. <style scoped lang="scss">
  85. .xm-popup {
  86. &-wrap {
  87. position: fixed;
  88. left: 0;
  89. right: 0;
  90. top: 0;
  91. bottom: 0;
  92. z-index: 1001;
  93. display: none;
  94. flex-direction: row;
  95. align-items: flex-end;
  96. justify-content: center;
  97. &-show {
  98. display: flex;
  99. }
  100. &-show-content {
  101. display: flex;
  102. position: unset;
  103. background-color: unset !important;
  104. }
  105. }
  106. &-cnt {
  107. width: 100%;
  108. min-height: 20px;
  109. overflow: hidden;
  110. padding-bottom: constant(safe-area-inset-bottom);
  111. padding-bottom: env(safe-area-inset-bottom);
  112. flex: 1;
  113. &.xm-anim{
  114. animation-duration: .2s;
  115. animation-timing-function: ease-out;
  116. animation-fill-mode: both;
  117. animation-name: xm-up;
  118. }
  119. &-show-content {
  120. padding-bottom: 0;
  121. }
  122. }
  123. @keyframes xm-up {
  124. 0% {
  125. opacity: 0;
  126. transform: translateY(100%)
  127. }
  128. 100% {
  129. opacity: 1;
  130. transform: translateY(0)
  131. }
  132. }
  133. }
  134. </style>