mix-popup.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <!-- :style="{zIndex:zIndex}" -->
  3. <view
  4. class="uni-popup"
  5. :class="[
  6. {'uni-popup--show': state > 0},
  7. {'uni-popup__center': type === 'center'}
  8. ]"
  9. @touchmove.stop.prevent="stopPrevent"
  10. >
  11. <view class="mask" :class="{'mask--show': state === 1}" @click="hide('mask')" v-show="isShowMask"/>
  12. <view v-if="type==='right'" class="wrapper wrapper__right" :class="{'wrapper--show': state === 1}">
  13. <view class="wrapper__box" @click.stop="stopPrevent">
  14. <slot />
  15. </view>
  16. </view>
  17. <!-- 底部弹窗 -->
  18. <view v-if="type==='bottom'" class="wrapper wrapper__bottom" :class="{'wrapper--show': state === 1}">
  19. <view class="wrapper__box" @click.stop="stopPrevent">
  20. <slot />
  21. </view>
  22. </view>
  23. <!-- 中间弹窗 -->
  24. <view v-if="type==='center'" class="wrapper wrapper__center" :class="{'wrapper__center--show': state === 1}">
  25. <view class="wrapper__center__box" @click.stop="stopPrevent">
  26. <slot />
  27. </view>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. export default {
  33. name: 'MixPopup',
  34. props: {
  35. // 弹出层类型,可选值,top: 顶部弹出层;bottom:底部弹出层;center:全屏弹出层
  36. type: {
  37. type: String,
  38. default: 'center'
  39. },
  40. isShowMask:{
  41. type:Boolean,
  42. default:true
  43. },
  44. //是否阻止点击mask隐藏
  45. isStopMaskHide:{
  46. type:Boolean,
  47. value:false,
  48. },
  49. zIndex:{
  50. type:Number,
  51. value:1001,
  52. },
  53. },
  54. data() {
  55. return {
  56. state: 0,
  57. }
  58. },
  59. created() {
  60. // this.show()
  61. },
  62. methods: {
  63. show() {
  64. this.state = 2;
  65. this.$nextTick(() => {
  66. this.state = 1;
  67. })
  68. },
  69. hide(type) {
  70. if(type == 'mask' && this.isStopMaskHide==true ){
  71. return;
  72. }
  73. uni.hideKeyboard();
  74. this.state = 2;
  75. setTimeout(() => {
  76. this.state = 0;
  77. }, 350)
  78. this.$emit('onHide');
  79. },
  80. toggle(){
  81. if(this.state === 0){
  82. this.show()
  83. }else{
  84. this.hide();
  85. }
  86. },
  87. stopPrevent() {},
  88. }
  89. }
  90. </script>
  91. <style lang="scss" scoped>
  92. // #ifndef APP-PLUS-NVUE */
  93. // view{
  94. // display: flex;
  95. // flex-direction: column;
  96. // }
  97. // /* #endif
  98. .uni-popup {
  99. position: fixed;
  100. /* #ifdef H5 */
  101. top: var(--window-top);
  102. /* #endif */
  103. /* #ifndef H5 */
  104. top: 0;
  105. /* #endif */
  106. bottom: 0;
  107. left: 0;
  108. right: 0;
  109. // z-index: 101;
  110. z-index: 1000;
  111. overflow: hidden;
  112. transform: translateX(750rpx);
  113. display: flex;
  114. flex-direction: column;
  115. &--show{
  116. transform: translateX(0);
  117. }
  118. &__center{
  119. justify-content: center;
  120. align-items: center;
  121. }
  122. }
  123. .mask {
  124. position: fixed;
  125. top: 0;
  126. bottom: 0;
  127. left: 0;
  128. right: 0;
  129. z-index: 101;
  130. opacity: 0;
  131. transition: opacity .38s;
  132. background-color: rgba(0,0,0,.3);
  133. &--show{
  134. opacity: 1;
  135. }
  136. }
  137. .wrapper {
  138. position: fixed;
  139. z-index: 1002;
  140. transition: transform .3s, opacity .3s;
  141. &__right{
  142. flex-direction: column;
  143. top: 0;
  144. bottom: 0;
  145. right: 0;
  146. transform: translateX(610rpx);
  147. }
  148. &__bottom{
  149. flex-direction: column;
  150. left: 0;
  151. bottom: 0;
  152. right: 0;
  153. transform: translateY(100%);
  154. }
  155. &__center{
  156. transform: scale(1.16);
  157. opacity: 0;
  158. }
  159. &--show{
  160. transform: translate(0rpx, 0rpx);
  161. }
  162. &__center--show{
  163. transform: scale(1);
  164. opacity: 1;
  165. }
  166. &__box{
  167. flex: 1;
  168. position: relative;
  169. }
  170. }
  171. /* .center {
  172. #ifndef APP-NVUE
  173. display: flex;
  174. flex-direction: column;
  175. #endif
  176. bottom: 0;
  177. left: 0;
  178. right: 0;
  179. top: 0;
  180. justify-content: center;
  181. align-items: center;
  182. transform: scale(1.1);
  183. opacity: 0;
  184. }
  185. */
  186. </style>