popup.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <view>
  3. <view :class="'popup ' + (propClassname || '') + ' ' + ((propShow || false) ? 'popup-show' : '') + ' ' + ((propAnimation || true) ? 'animation': '' )" :disable-scroll="propDisablescroll">
  4. <view class="popup-mask" v-if="propMask || true" @tap="on_mask_tap"></view>
  5. <view :class="'popup-content bottom-line-exclude popup-' + (propPosition || 'bottom')+ ' '+(propIsBar ? 'popup-bar' : '')" :style="'left:'+popup_content_left_value+'px'">
  6. <slot></slot>
  7. </view>
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. export default {
  13. data() {
  14. return {
  15. popup_content_left_value: 'auto'
  16. };
  17. },
  18. components: {},
  19. props: {
  20. propClassname: {
  21. type: String,
  22. default: ''
  23. },
  24. propShow: {
  25. type: Boolean,
  26. default: false
  27. },
  28. propPosition: {
  29. type: String,
  30. default: 'bottom'
  31. },
  32. propMask: {
  33. type: Boolean,
  34. default: true
  35. },
  36. propAnimation: {
  37. type: Boolean,
  38. default: true
  39. },
  40. propDisablescroll: {
  41. type: Boolean,
  42. default: false
  43. },
  44. propIsBar: {
  45. type: Boolean,
  46. default: false
  47. }
  48. },
  49. // 属性值改变监听
  50. watch: {
  51. // 监听状态
  52. propShow(value, old_value) {
  53. this.left_handle();
  54. }
  55. },
  56. // 组建创建
  57. created: function() {
  58. this.left_handle();
  59. },
  60. methods: {
  61. // 事件处理
  62. on_mask_tap: function on_mask_tap() {
  63. this.$emit('onclose', {
  64. detail: {}
  65. }, {});
  66. },
  67. // 左边距位置处理
  68. left_handle() {
  69. // 处理内容左边距、避免父级设置内边距影响
  70. var width = uni.getSystemInfoSync().windowWidth;
  71. var left = 0;
  72. if(width > 800) {
  73. left = (width-800)/2;
  74. }
  75. this.popup_content_left_value = left;
  76. }
  77. }
  78. };
  79. </script>
  80. <style>
  81. .popup-content {
  82. position: fixed;
  83. background: #fff;
  84. z-index: 101;
  85. overflow: hidden;
  86. }
  87. .popup-mask {
  88. position: fixed;
  89. top: 0;
  90. bottom: 0;
  91. left: 0;
  92. right: 0;
  93. background-color: rgba(0, 0, 0, 0.6);
  94. opacity: 0;
  95. pointer-events: none;
  96. z-index: 100;
  97. }
  98. .popup-left {
  99. transform: translateX(-100%);
  100. left: 0;
  101. top: 0;
  102. bottom: 0;
  103. }
  104. .popup-right {
  105. transform: translateX(100%);
  106. right: 0;
  107. top: 0;
  108. bottom: 0;
  109. }
  110. .popup-top {
  111. top: 0;
  112. width: 100vw;
  113. transform: translateY(-100%);
  114. }
  115. .popup-bottom {
  116. bottom: var(--window-bottom);
  117. width: 100vw;
  118. transform: translateY(100%);
  119. }
  120. .popup-show .popup-content {
  121. transform: none;
  122. }
  123. .popup-show .popup-mask {
  124. opacity: 1;
  125. pointer-events: auto;
  126. }
  127. .popup.animation .popup-mask,
  128. .popup.animation .popup-content {
  129. transition: all 0.25s linear;
  130. }
  131. .popup-top {
  132. border-bottom-right-radius: 20rpx;
  133. border-bottom-left-radius: 20rpx;
  134. }
  135. .popup-bottom {
  136. border-top-right-radius: 20rpx;
  137. border-top-left-radius: 20rpx;
  138. }
  139. .popup-left {
  140. border-top-right-radius: 20rpx;
  141. border-bottom-right-radius: 20rpx;
  142. }
  143. .popup-right {
  144. border-top-left-radius: 20rpx;
  145. border-bottom-left-radius: 20rpx;
  146. }
  147. .popup-bar {
  148. /* #ifdef H5 || APP */
  149. bottom: var(--window-bottom) !important;
  150. /* #endif */
  151. }
  152. </style>