as-popup.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <template>
  2. <view v-if="showPopup" class="as-popup" :class="'as-popup-' + type">
  3. <uni-transition key="1" mode-class="fade" :show="showContent">
  4. <view class="as-mask" @tap="close" @touchmove.stop.prevent="stopPrevent"></view>
  5. </uni-transition>
  6. <uni-transition key="2" :mode-class="animate" :show="showContent" class="as-popup-content-wapper">
  7. <view class="as-popup-content" @touchmove.stop.prevent="stopPrevent">
  8. <slot></slot>
  9. </view>
  10. </uni-transition>
  11. </view>
  12. </template>
  13. <script>
  14. export default{
  15. name: 'AsPopup',
  16. model: {
  17. prop: 'status',
  18. event: 'change'
  19. },
  20. props: {
  21. status: {
  22. type: Boolean,
  23. default: false
  24. },
  25. type: {
  26. type: String,
  27. default: 'bottom'
  28. }
  29. },
  30. data(){
  31. return {
  32. showPopup: false,
  33. showContent: false,
  34. timer: null
  35. }
  36. },
  37. watch: {
  38. status(status){
  39. if(status){
  40. this.open();
  41. }else{
  42. this.close();
  43. }
  44. },
  45. // H5 下禁止底部滚动
  46. showPopup(show) {
  47. // #ifdef H5
  48. // fix by mehaotian 处理 h5 滚动穿透的问题
  49. document.getElementsByTagName('body')[0].style.overflow = show ? 'hidden' : 'visible'
  50. // #endif
  51. }
  52. },
  53. computed: {
  54. animate() {
  55. let animate;
  56. switch(this.type){
  57. case 'top':
  58. animate = ['fade', 'slide-top'];
  59. break;
  60. case 'bottom':
  61. animate = ['fade', 'slide-bottom'];
  62. break;
  63. case 'left':
  64. animate = ['fade', 'slide-left'];
  65. break;
  66. case 'right':
  67. animate = ['fade', 'slide-right'];
  68. break;
  69. case 'center':
  70. case 'dialog':
  71. animate = ['zoom-out', 'fade'];
  72. break;
  73. }
  74. return animate;
  75. }
  76. },
  77. methods: {
  78. stopPrevent() {
  79. },
  80. open() {
  81. if (this.showPopup) {
  82. clearTimeout(this.timer)
  83. this.showPopup = false
  84. }
  85. this.showPopup = true;
  86. this.showContent = true;
  87. this.$emit('change', true);
  88. },
  89. close() {
  90. this.showContent = false;
  91. this.$emit('change', false);
  92. clearTimeout(this.timer)
  93. this.timer = setTimeout(()=>{
  94. this.showPopup = false;
  95. }, 300);
  96. }
  97. }
  98. }
  99. </script>
  100. <style scoped lang="scss">
  101. .as-popup{
  102. position: fixed;
  103. /* #ifndef APP-NVUE */
  104. z-index: 999;
  105. /* #endif */
  106. .as-popup-content-wapper{
  107. position: fixed;
  108. left: 0px;
  109. right: 0px;
  110. bottom: 0px;
  111. z-index: 9;
  112. }
  113. &.as-popup-dialog, &.as-popup-center{
  114. .as-popup-content-wapper{
  115. display: flex;
  116. align-items: center;
  117. top: 0;
  118. justify-content: center;
  119. }
  120. .as-popup-content{
  121. position: fixed;
  122. left: 0px;
  123. right: 0px;
  124. bottom: 0px;
  125. z-index: 9;
  126. display: flex;
  127. align-items: center;
  128. top: 0;
  129. justify-content: center;
  130. }
  131. }
  132. }
  133. .as-mask {
  134. position: fixed;
  135. top: 0;
  136. left: 0;
  137. z-index: 9;
  138. width: 100%;
  139. height: 100%;
  140. background: rgba(0, 0, 0, 0.4);
  141. }
  142. </style>