uni-popup-sku-new.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <template>
  2. <view v-if="showPopup" class="uni-popup">
  3. <view :class="[ani, animation ? 'ani' : '', !custom ? 'uni-custom' : '']" class="uni-popup__mask" @click="close(true)" />
  4. <view
  5. :class="[type, ani, animation ? 'ani' : '', !custom ? 'uni-custom' : '']"
  6. class="uni-popup__wrapper goodslist-uni-popup safe-area"
  7. @click="close(true)"
  8. v-if="isIphoneX"
  9. >
  10. <view class="uni-popup__wrapper-box goodslist-uni-popup-box" @click.stop="clear"><slot /></view>
  11. </view>
  12. <view :class="[type, ani, animation ? 'ani' : '', !custom ? 'uni-custom' : '']" class="uni-popup__wrapper goodslist-uni-popup" @click="close(true)" v-else>
  13. <view class="uni-popup__wrapper-box goodslist-uni-popup-box" @click.stop="clear"><slot /></view>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. name: 'UniPopup',
  20. props: {
  21. // 开启动画
  22. animation: {
  23. type: Boolean,
  24. default: true
  25. },
  26. // 弹出层类型,可选值,top: 顶部弹出层;bottom:底部弹出层;center:全屏弹出层
  27. type: {
  28. type: String,
  29. default: 'center'
  30. },
  31. // 是否开启自定义
  32. custom: {
  33. type: Boolean,
  34. default: false
  35. },
  36. // maskClick
  37. maskClick: {
  38. type: Boolean,
  39. default: true
  40. },
  41. show: {
  42. type: Boolean,
  43. default: true
  44. }
  45. },
  46. data() {
  47. return {
  48. ani: '',
  49. showPopup: false,
  50. callback: null,
  51. isIphoneX: false
  52. };
  53. },
  54. watch: {
  55. show(newValue) {
  56. if (newValue) {
  57. this.open();
  58. } else {
  59. this.close();
  60. }
  61. }
  62. },
  63. created() {
  64. this.isIphoneX = this.$util.uniappIsIPhoneX();
  65. },
  66. methods: {
  67. clear() {},
  68. open(callback) {
  69. if (callback) this.callback = callback;
  70. this.$emit('change', {
  71. show: true
  72. });
  73. this.showPopup = true;
  74. this.$nextTick(() => {
  75. setTimeout(() => {
  76. this.ani = 'uni-' + this.type;
  77. }, 30);
  78. });
  79. },
  80. close(type, callback) {
  81. if (!this.maskClick && type) return;
  82. this.$emit('change', {
  83. show: false
  84. });
  85. this.ani = '';
  86. this.$nextTick(() => {
  87. setTimeout(() => {
  88. this.showPopup = false;
  89. }, 300);
  90. });
  91. if (callback) callback();
  92. if (this.callback) this.callback.call(this);
  93. }
  94. }
  95. };
  96. </script>
  97. <style>
  98. @charset "UTF-8";
  99. .uni-popup {
  100. position: fixed;
  101. top: 0;
  102. top: 0;
  103. bottom: 0;
  104. left: 0;
  105. right: 0;
  106. z-index: 999;
  107. overflow: hidden;
  108. }
  109. .uni-popup__mask {
  110. position: absolute;
  111. top: 0;
  112. bottom: 0;
  113. left: 0;
  114. right: 0;
  115. z-index: 998;
  116. background: rgba(0, 0, 0, 0.4);
  117. opacity: 0;
  118. }
  119. .uni-popup__mask.ani {
  120. transition: all 0.3s;
  121. }
  122. .uni-popup__mask.uni-bottom,
  123. .uni-popup__mask.uni-center,
  124. .uni-popup__mask.uni-right,
  125. .uni-popup__mask.uni-left,
  126. .uni-popup__mask.uni-top {
  127. opacity: 1;
  128. }
  129. .uni-popup__wrapper {
  130. position: absolute;
  131. z-index: 999;
  132. box-sizing: border-box;
  133. //background: #ffffff;
  134. }
  135. .uni-popup__wrapper.ani {
  136. transition: all 0.3s;
  137. }
  138. .uni-popup__wrapper.top {
  139. top: 0;
  140. left: 0;
  141. width: 100%;
  142. transform: translateY(-100%);
  143. }
  144. .uni-popup__wrapper.bottom {
  145. bottom: -30px;
  146. left: 0;
  147. width: 100%;
  148. transform: translateY(100%);
  149. }
  150. .uni-popup__wrapper.right {
  151. bottom: 0;
  152. left: 0;
  153. width: 100%;
  154. transform: translateX(100%);
  155. }
  156. .uni-popup__wrapper.left {
  157. bottom: 0;
  158. left: 0;
  159. width: 100%;
  160. transform: translateX(-100%);
  161. }
  162. .uni-popup__wrapper.center {
  163. width: 100%;
  164. height: 100%;
  165. display: flex;
  166. justify-content: center;
  167. align-items: center;
  168. transform: scale(1.2);
  169. opacity: 0;
  170. }
  171. .uni-popup__wrapper-box {
  172. position: relative;
  173. box-sizing: border-box;
  174. }
  175. .uni-popup__wrapper.uni-custom .uni-popup__wrapper-box {
  176. //background: #fff;
  177. }
  178. .uni-popup__wrapper.uni-custom.center .uni-popup__wrapper-box {
  179. position: relative;
  180. max-width: 80%;
  181. max-height: 80%;
  182. overflow-y: scroll;
  183. }
  184. .uni-popup__wrapper.uni-custom.bottom .uni-popup__wrapper-box,
  185. .uni-popup__wrapper.uni-custom.top .uni-popup__wrapper-box {
  186. width: 100%;
  187. max-height: 500px;
  188. overflow-y: scroll;
  189. }
  190. .uni-popup__wrapper.uni-bottom,
  191. .uni-popup__wrapper.uni-top {
  192. transform: translateY(0);
  193. }
  194. .uni-popup__wrapper.uni-left,
  195. .uni-popup__wrapper.uni-right {
  196. transform: translateX(0);
  197. }
  198. .uni-popup__wrapper.uni-center {
  199. transform: scale(1);
  200. opacity: 1;
  201. }
  202. /* isIphoneX系列手机底部安全距离 */
  203. .bottom.safe-area {
  204. padding-bottom: constant(safe-area-inset-bottom);
  205. padding-bottom: env(safe-area-inset-bottom);
  206. }
  207. </style>