uni-popup.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <template>
  2. <view>
  3. <view v-show="show" :style="{ top: offsetTop + 'px' }" class="uni-mask" @click="hide" @touchmove.stop.prevent="moveHandle" />
  4. <view v-show="show" :class="'uni-popup-' + position + ' ' + 'uni-popup-' + mode" class="uni-popup">
  5. {{ msg }}
  6. <slot />
  7. <!-- <view v-if="position === 'middle' && mode === 'insert'" :class="{
  8. 'uni-close-bottom': buttonMode === 'bottom',
  9. 'uni-close-right': buttonMode === 'right'
  10. }" class=" uni-icon uni-icon-close" @click="closeMask" /> -->
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. export default {
  16. name: 'UniPopup',
  17. props: {
  18. /**
  19. * 页面显示
  20. */
  21. show: {
  22. type: Boolean,
  23. default: false
  24. },
  25. /**
  26. * 对齐方式
  27. */
  28. position: {
  29. type: String,
  30. // top - 顶部, middle - 居中, bottom - 底部
  31. default: 'middle'
  32. },
  33. /**
  34. * 显示模式
  35. */
  36. mode: {
  37. type: String,
  38. default: 'insert'
  39. },
  40. /**
  41. * 额外信息
  42. */
  43. msg: {
  44. type: String,
  45. default: ''
  46. },
  47. /**
  48. * h5遮罩是否到顶
  49. */
  50. h5Top: {
  51. type: Boolean,
  52. default: false
  53. },
  54. buttonMode: {
  55. type: String,
  56. default: 'bottom'
  57. }
  58. },
  59. data() {
  60. return {
  61. offsetTop: 0
  62. }
  63. },
  64. watch: {
  65. h5Top(newVal) {
  66. if (newVal) {
  67. this.offsetTop = 44
  68. } else {
  69. this.offsetTop = 0
  70. }
  71. }
  72. },
  73. created() {
  74. let offsetTop = 0
  75. // #ifdef H5
  76. if (!this.h5Top) {
  77. offsetTop = 44
  78. } else {
  79. offsetTop = 0
  80. }
  81. // #endif
  82. this.offsetTop = offsetTop
  83. },
  84. methods: {
  85. hide() {
  86. if (this.mode === 'insert' && this.position === 'middle') return
  87. this.$emit('hidePopup')
  88. },
  89. closeMask() {
  90. if (this.mode === 'insert') {
  91. this.$emit('hidePopup')
  92. }
  93. },
  94. moveHandle() {}
  95. }
  96. }
  97. </script>
  98. <style>
  99. .uni-mask {
  100. position: fixed;
  101. z-index: 998;
  102. top: 0;
  103. right: 0;
  104. bottom: 0;
  105. left: 0;
  106. background-color: black;
  107. }
  108. .uni-popup {
  109. position: fixed;
  110. z-index: 999;
  111. background-color: #ffffff;
  112. }
  113. .uni-popup-middle {
  114. display: flex;
  115. flex-direction: column;
  116. align-items: center;
  117. justify-content: center;
  118. top: 50%;
  119. left: 50%;
  120. transform: translate(-50%, -50%);
  121. }
  122. .uni-popup-middle.uni-popup-insert {
  123. min-width: 380upx;
  124. min-height: 380upx;
  125. max-width: 100%;
  126. max-height: 80%;
  127. transform: translate(-50%, -50%);
  128. background: none;
  129. box-shadow: none;
  130. }
  131. .uni-popup-middle.uni-popup-fixed {
  132. border-radius: 10upx;
  133. padding: 30upx;
  134. }
  135. .uni-close-bottom,
  136. .uni-close-right {
  137. position: absolute;
  138. bottom: -465upx;
  139. text-align: center;
  140. border-radius: 50%;
  141. color: #D9332E;
  142. font-size: 80upx;
  143. font-weight: bold;
  144. opacity: 0.8;
  145. z-index: -1;
  146. }
  147. .uni-close-bottom {
  148. margin: auto;
  149. left: 0;
  150. right: 0;
  151. }
  152. .uni-close-right {
  153. right: -60upx;
  154. top: -80upx;
  155. }
  156. .uni-close-bottom:after {
  157. content: '';
  158. position: absolute;
  159. width: 0px;
  160. top: -200upx;
  161. bottom: 56upx;
  162. left: 50%;
  163. transform: translate(-50%, -50%);
  164. opacity: 0.8;
  165. }
  166. .uni-popup-top,
  167. .uni-popup-bottom {
  168. display: flex;
  169. align-items: center;
  170. justify-content: center;
  171. }
  172. .uni-popup-top {
  173. top: 0;
  174. left: 0;
  175. width: 100%;
  176. height: 100upx;
  177. line-height: 100upx;
  178. text-align: center;
  179. }
  180. .uni-popup-bottom {
  181. left: 0;
  182. bottom: 0;
  183. width: 100%;
  184. min-height: 100upx;
  185. line-height: 100upx;
  186. text-align: center;
  187. }
  188. </style>