uni-popup.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <template>
  2. <view>
  3. <view class="uni-mask" v-show="show" :style="{top:offsetTop + 'px'}" @click="hide"></view>
  4. <view :class="['uni-popup','uni-popup-'+type]" v-show="show" :style="'width:'+width+'rpx; heigth:'+heigth+'rpx;padding:'+padding+'rpx;background-color:'+backgroundColor+';box-shadow:'+boxShadow+';'">
  5. <view class="popup-head" v-if="msg!=''">
  6. {{msg}}
  7. </view>
  8. <slot></slot>
  9. </view>
  10. </view>
  11. </template>
  12. <script>
  13. export default {
  14. props: {
  15. show: {
  16. type: Boolean,
  17. default: false
  18. },
  19. type: {
  20. type: String,
  21. //top - 顶部, middle - 居中, bottom - 底部
  22. default: 'middle'
  23. },
  24. width: {
  25. type: Number,
  26. default: 600
  27. },
  28. heigth: {
  29. type: Number,
  30. default: 800
  31. },
  32. padding:{
  33. type: Number,
  34. default: 30
  35. },
  36. backgroundColor:{
  37. type: String,
  38. default: '#ffffff'
  39. },
  40. boxShadow:{
  41. type: String,
  42. default: '0 0 30upx rgba(0, 0, 0, .1)'
  43. },
  44. msg: {
  45. type: String,
  46. default: ""
  47. }
  48. },
  49. data() {
  50. let offsetTop = 0;
  51. //#ifdef H5
  52. offsetTop = 0;
  53. //#endif
  54. return {
  55. offsetTop: offsetTop
  56. }
  57. },
  58. methods: {
  59. hide: function() {
  60. this.$emit('hidePopup');
  61. }
  62. }
  63. }
  64. </script>
  65. <style>
  66. .uni-mask {
  67. position: fixed;
  68. z-index: 998;
  69. top: 0;
  70. right: 0;
  71. bottom: 0;
  72. left: 0;
  73. background-color: rgba(0, 0, 0, .3);
  74. }
  75. .uni-popup {
  76. position: fixed;
  77. z-index: 999;
  78. }
  79. .uni-popup-middle {
  80. display: flex;
  81. flex-direction: column;
  82. align-items: flex-start;
  83. width: 600upx;
  84. /* height:800upx; */
  85. border-radius: 10upx;
  86. top: 50%;
  87. left: 50%;
  88. transform: translate(-50%, -50%);
  89. justify-content: flex-start;
  90. padding: 30upx;
  91. overflow: auto;
  92. }
  93. .popup-head{ width: 100%; padding-bottom: 40rpx; box-sizing: border-box; font-size: 30rpx; font-weight: bold;}
  94. .uni-popup-top {
  95. top: 0;
  96. left: 0;
  97. width: 100%;
  98. height: 100upx;
  99. line-height: 100upx;
  100. text-align: center;
  101. }
  102. .uni-popup-bottom {
  103. left: 0;
  104. bottom: 0;
  105. width: 100%;
  106. text-align: center;
  107. }
  108. </style>