ming-pop.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <template>
  2. <!-- 组件地址: https://ext.dcloud.net.cn/plugin?id=2716 -->
  3. <!-- v-if解决center弹窗位置问题 -->
  4. <view :class="direction==='center'?'centers':''" v-if="direction==='center'?open:true">
  5. <view class="product-window"
  6. :style="{width:width+'%',height:height=='fit-content'?height:(open?height:'fit-content')}"
  7. :class="(open ? 'on' : '')+' '+direction" @touchmove.stop.prevent="">
  8. <!-- 兼容h5顶部导航空位 -->
  9. <!-- #ifndef MP -->
  10. <!-- <view v-if="(direction!=='below'&&direction!=='center')" style="height: 100rpx;"></view> -->
  11. <!-- #endif -->
  12. <!-- <image src="../../static/ming-pop/close.png" mode=""
  13. :class="(direction!=='below'&&direction!=='center')?'iconfont-h5':''" class="iconfont" @click="close"
  14. v-if="is_close"></image> -->
  15. <slot></slot>
  16. </view>
  17. <view class="mask" v-if="is_mask" @touchmove.prevent :hidden="!open" @click="close(1)"></view>
  18. </view>
  19. </template>
  20. <script>
  21. /*
  22. 属性名 类型 默认值 必填 作用 说明
  23. direction String below 否 弹窗方向 below(下边);up(上边);left(左边) ;right(右边);center(中间)
  24. is_close Boolean true 否 是否显示关闭按钮 点击即可关闭弹窗
  25. is_mask: Boolean true 否 是否显示遮罩层 点击即可关闭弹窗(maskFun值在true情况下)
  26. maskFun Boolean true 否 是否点击遮罩关闭弹窗 遮罩为显示情况下才可生效
  27. width Number 100 否 弹窗的宽度 单位(%)。建议只在上、下方向弹窗使用100(满值)
  28. height String fit-content 否 弹窗内容的固定高度 默认是根据内容支撑高度,可进行修改成自定义高度:如height='150rpx'(支持rpx,px,%,请将单位带上)
  29. watchOpen Function - - 监听弹窗打开事件 -
  30. watchClose Function - - 监听弹窗关闭事件 -
  31. */
  32. export default {
  33. props: {
  34. direction: {
  35. type: String,
  36. default: "below"
  37. },
  38. width: {
  39. type: Number,
  40. default: 100
  41. },
  42. height: {
  43. type: String,
  44. default: "fit-content"
  45. },
  46. is_close: {
  47. type: Boolean,
  48. default: true
  49. },
  50. is_mask: {
  51. type: Boolean,
  52. default: true
  53. },
  54. maskFun: {
  55. type: Boolean,
  56. default: true
  57. }
  58. },
  59. data() {
  60. return {
  61. open: false
  62. };
  63. },
  64. methods: {
  65. show() {
  66. this.open = true;
  67. this.$emit("watchOpen")
  68. },
  69. close(e) {
  70. if (e == 1 && !this.maskFun) return;
  71. this.open = false;
  72. this.$emit("watchClose")
  73. }
  74. }
  75. }
  76. </script>
  77. <style lang="scss" scoped>
  78. view {
  79. box-sizing: border-box;
  80. }
  81. .centers {
  82. width: 100vw;
  83. display: flex;
  84. justify-content: center;
  85. align-items: center;
  86. // height: 100%;
  87. position: fixed;
  88. top: 0;
  89. left: 0;
  90. right: 0;
  91. bottom: 0;
  92. }
  93. .product-window {
  94. position: fixed;
  95. background-color: #fff;
  96. z-index: 77;
  97. border-radius: 32rpx 32rpx 0rpx 0rpx;
  98. padding: 50rpx 30rpx;
  99. overflow-y: scroll;
  100. transition: all .3s cubic-bezier(.25, .5, .5, .9);
  101. -webkit-transition: all .3s cubic-bezier(.25, .5, .5, .9);
  102. }
  103. .below {
  104. left: 0;
  105. bottom: 0;
  106. transform: translate3d(0, 100%, 0);
  107. -webkit-transform: translate3d(0, 100%, 0);
  108. }
  109. .up {
  110. top: 0;
  111. left: 0;
  112. transform: translate3d(0, -100%, 0);
  113. -webkit-transform: translate3d(0, -100%, 0);
  114. }
  115. .right {
  116. right: 0;
  117. top: 0;
  118. height: 100%;
  119. transform: translate3d(100vw, 0, 0);
  120. -webkit-transform: translate3d(100vw, 0, 0);
  121. }
  122. .left {
  123. left: 0;
  124. top: 0;
  125. height: 100%;
  126. transform: translate3d(-100vw, 0, 0);
  127. -webkit-transform: translate3d(-100vw, 0, 0);
  128. }
  129. .center {
  130. position: static;
  131. -webkit-position: static;
  132. transform: translate3d(-100vw, -100%, 0);
  133. -webkit-transform: translate3d(-100vw, -100%, 0);
  134. }
  135. .product-window.on {
  136. transform: translate3d(0, 0, 0);
  137. -webkit-transform: translate3d(0, 0, 0);
  138. }
  139. .mask {
  140. position: fixed;
  141. top: 0;
  142. left: 0;
  143. right: 0;
  144. bottom: 0;
  145. background-color: #000;
  146. opacity: .5;
  147. z-index: 5;
  148. }
  149. .product-window .iconfont {
  150. position: fixed;
  151. right: 30rpx;
  152. top: 20rpx;
  153. font-size: 35rpx;
  154. color: #8a8a8a;
  155. width: 50rpx;
  156. height: 50rpx;
  157. }
  158. //兼容h5顶部导航空位
  159. // #ifndef MP
  160. .product-window .iconfont-h5 {
  161. top: 100rpx;
  162. }
  163. // #endif
  164. </style>