You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <!-- 底部弹窗 -->
  2. <template>
  3. <view :class="['popup',{'popup-show':show}]" @mousewheel.prevent.stop @touchmove.stop.prevent
  4. :style="{'z-index':zindex}">
  5. <view class="mask" :style="{'z-index':maskZindex,bottom:bottom+'rpx'}" v-show="show" @click.stop="onClose"
  6. @touchmove.prevent.stop></view>
  7. <view :class="['content',{show}]" @click.stop @touchmove.prevent.stop :style="{height:`${height}px`,maxHeight:show ? cotMaxHeight:0,'border-top-right-radius':cotRadius,
  8. 'border-top-left-radius':cotRadius,transition: `all ${animaTime}s ease-in`,bottom:bottom+'rpx','z-index':zindex}">
  9. <view id="title-bar" class="title-bar" v-show="title">
  10. <view class="title" :style="{fontWeight:fontweight}">{{title}}</view>
  11. <view class="close-wrap" @click.stop="onClose">
  12. <image class="close-icon" :src="closeIcon" mode="widthFix"></image>
  13. </view>
  14. </view>
  15. <view class="scroll-wrap">
  16. <scroll-view :class="{'scroll-view':isAnimaStart}" scroll-y="true" style="height:100%;"
  17. @scrolltolower="onScrollToLower">
  18. <view id="popup_content" class="popup_content">
  19. <slot></slot>
  20. </view>
  21. </scroll-view>
  22. </view>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. export default {
  28. props: {
  29. title: { //标题
  30. type: String,
  31. default: ''
  32. },
  33. fontweight: {
  34. type: [String, Number],
  35. default: 'normal'
  36. },
  37. visible: { //隐藏显示标识
  38. type: Boolean,
  39. default: false
  40. },
  41. maxHeight: { //内容区域最大高度
  42. type: [String, Number],
  43. default: '75%'
  44. },
  45. radius: { //顶部圆角
  46. type: [String, Number],
  47. default: '0'
  48. },
  49. animaTime: { //弹窗动画时间
  50. type: Number,
  51. default: 0.2
  52. },
  53. bottom: { //离底部距离
  54. type: [String, Number],
  55. default: 0
  56. },
  57. zindex: {
  58. type: [String, Number],
  59. default: 1000
  60. },
  61. maskZindex: {
  62. type: [String, Number],
  63. default: 999
  64. },
  65. always: { //是否每次打开都重新计算内容高度
  66. type: Boolean,
  67. default: false
  68. },
  69. },
  70. data() {
  71. return {
  72. show: false,
  73. height: 0,
  74. PopHeight: 0,
  75. cotMaxHeight: '',
  76. isAnimaStart: false,
  77. rpxRate: "",
  78. cotRadius: 0,
  79. closeIcon: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAADfklEQVR4Xu2aPWgUQRSA37uzEbQSLWwEG0FLbRIwVcBOsBPETqIgNtGb2VwhSXNmZs/YGNRYWYqlnQqCooKdYB8iRlAQu2uyzJPFLFzW2/95c3Pkrt15s/N9897Mzu4h7PMf7nN+mAqYZsA+NzAtgaIE0Fo/BoBLALAshHhU1N6X60qpKwAQIuJLIcT1rHHlZoDWegEAniTBRHRHSnnfF8iscSilriLiM4B/i7wxZiEIgqej2ucKWF1dXWy1WnuAfZegtb4GABsJ/C50RwjRryxgbW3t4M7OzldEPDkcTERdKeU93zJBKXUDEdNl+iuKotPdbvd3ZQFxgFLqOCJ+BIATKQlelcPuzO9JcyL62Wq1ZjqdzmatNSAJ8l1CXfiYr/Q26KuEJvCVBPhYDk3hKwvwSYIN+FoCfJBgC762gAIJK1LKZa4t0iZ8IwF5EgCgL4To2JZgG76xgEQCALxPPyzZlsABb0VA3EkYhseMMZ+4JHDBWxPAKYET3qoADgnc8NYF2JTgAp5FgA0JruDZBDSRoLW+CQAPUyfPwlNd3S239GGozg2q7g6u4VkzIBFWVsI44J0IKFMO44J3JqBAwhsAmE+V2DYins97k1OnJEfFsK4B6RvmlMNw021jzGwQBN9sQeb141RAQSbEl53COy2B4VnQWgcA8N9bZSLakFJmfsTgyAjnGTBqwUuBsRyls+Q5FZCx2keIeGBcEpwJyJj5bQC4SEQvuI7SRWXjREAWfLLaZ+0ORPRQSnmrCKLJdXYBRfBFT4zcElgFlIVPSXiHiKdShyG2TGATUBU+Ae71ekfa7fYHVxJYBCilbiNi+nN06YcclxKsC2gK7zoTrAqwBe9SgjUBtuFdSbAigAvehYTGArjhuSU0EuAKnlNCbQEZ8FvGmDnOlxm2t8haArLgiWhWSvmjybN5mVibEioLGDe87XKoJMAXeJsSSgvwDd6WhFICfIW3IaFQgO/wTSXkCgjDcJ6IXqdW5i1Xq32ZHWG4TdbuAACXhRDPR/VX9Hf5FQC4OxToLXxBJjwQQixWFhCG4QwRxX+Ujn+bRDQnpfxedWZct+/1ekfb7fZbRDyze+8LQohXlQXEAf1+/ywRHY6i6MvS0tIf1zB177e+vn5oMBicM8YMpJSfs/opXATrDmBS4qYCJmWmuMY5zQAus5PS7zQDJmWmuMb5F+6nKm6KNS8jAAAAAElFTkSuQmCC'
  80. }
  81. },
  82. watch: {
  83. visible(newval) {
  84. this.isAnimaStart = true;
  85. setTimeout(() => {
  86. this.isAnimaStart = false;
  87. }, this.animaTime * 1000)
  88. if (newval && this.height === 0) {
  89. if (this.PopHeight === 0 || this.always) {
  90. this.setContViewHeight();
  91. } else {
  92. this.height = this.PopHeight
  93. }
  94. // #ifdef H5
  95. this.setBodyOverFlow('hidden') //阻止滚动穿透
  96. //#endif
  97. this.$emit('open')
  98. } else {
  99. this.height = 0;
  100. // #ifdef H5
  101. this.setBodyOverFlow('visible')
  102. //#endif
  103. }
  104. this.show = newval
  105. },
  106. maxHeight: {
  107. handler(newval) {
  108. this.cotMaxHeight = this.unitCheck(newval);
  109. },
  110. immediate: true
  111. },
  112. radius: {
  113. handler(newval) {
  114. this.cotRadius = this.unitCheck(newval);
  115. },
  116. immediate: true
  117. }
  118. },
  119. created() {
  120. this.rpxRate = this.getRpxRate()
  121. },
  122. mounted() {
  123. this.$nextTick(() => {
  124. // #ifdef H5
  125. this.preventTouch(document.querySelector(
  126. '.scroll-wrap .uni-scroll-view .uni-scroll-view')); //防止浏览器报错
  127. //#endif
  128. })
  129. },
  130. methods: {
  131. onClose() {
  132. this.$emit("update:visible", false);
  133. this.$emit('close')
  134. },
  135. //触底
  136. onScrollToLower(e) {
  137. this.$emit("reachBottom");
  138. },
  139. getRpxRate() {
  140. let res = uni.getSystemInfoSync();
  141. let width = res.windowWidth;
  142. let rate = 750.00 / width;
  143. return rate
  144. },
  145. unitCheck(value) {
  146. const val = String(value);
  147. if (!val.includes('px') && !val.includes('%')) {
  148. return `${val}rpx`;
  149. }
  150. return val;
  151. },
  152. preventTouch(el) {
  153. el.addEventListener('touchmove', function(e) {
  154. e.stopPropagation();
  155. }, {
  156. passive: false
  157. });
  158. },
  159. setBodyOverFlow(val) {
  160. document.body.style.overflow = val
  161. },
  162. //设置内容区域高度
  163. async setContViewHeight() {
  164. let data = await this.computeHeight();
  165. this.height = data.height + (this.title ? 100 / parseFloat(this.rpxRate) : 0);
  166. this.PopHeight = this.height;
  167. },
  168. //计算内容区域高度
  169. computeHeight() {
  170. return new Promise(resolve => {
  171. this.$nextTick(() => {
  172. const query = uni.createSelectorQuery().in(this);
  173. query.select('#popup_content').boundingClientRect(data => {
  174. resolve(data)
  175. }).exec();
  176. })
  177. })
  178. }
  179. }
  180. }
  181. </script>
  182. <style lang="scss" scoped>
  183. .popup {
  184. &.popup-show {
  185. position: fixed;
  186. top: 0;
  187. right: 0;
  188. left: 0;
  189. bottom: 0;
  190. overflow: hidden;
  191. z-index: 999;
  192. }
  193. .mask {
  194. position: fixed;
  195. top: 0;
  196. right: 0;
  197. bottom: 0;
  198. left: 0;
  199. background-color: rgba($color: #000000, $alpha: 0.5);
  200. z-index: 999;
  201. }
  202. .content {
  203. position: fixed;
  204. bottom: 0;
  205. left: 0;
  206. right: 0;
  207. height: 0;
  208. height: auto;
  209. background-color: #F3F3F3;
  210. transition: all 0.2s ease-in;
  211. z-index: 1000;
  212. display: flex;
  213. flex-direction: column;
  214. align-items: center;
  215. overflow: hidden;
  216. .title-bar {
  217. width: 100%;
  218. flex-shrink: 0;
  219. text-align: center;
  220. position: relative;
  221. padding: 25rpx 70rpx 20rpx;
  222. box-sizing: border-box;
  223. height: 90rpx;
  224. .title {
  225. font-size: 34rpx;
  226. color: #000;
  227. width: 100%;
  228. overflow: hidden;
  229. text-overflow: ellipsis;
  230. white-space: nowrap;
  231. }
  232. .close-wrap {
  233. position: absolute;
  234. top: 20rpx;
  235. right: 10rpx;
  236. padding: 10rpx 20rpx;
  237. box-sizing: border-box;
  238. }
  239. .close-icon {
  240. width: 36rpx;
  241. height: auto;
  242. }
  243. }
  244. .scroll-wrap {
  245. flex: 1;
  246. height: 0;
  247. width: 100%;
  248. }
  249. &.visible {
  250. max-height: 75%;
  251. overflow-y: hidden;
  252. height: auto;
  253. }
  254. }
  255. }
  256. .scroll-view ::-webkit-scrollbar {
  257. display: none !important;
  258. width: 0 !important;
  259. height: 0 !important;
  260. -webkit-appearance: none;
  261. background: transparent;
  262. }
  263. .popup_content {
  264. width: 100%;
  265. padding: 30rpx;
  266. box-sizing: border-box;
  267. &::after {
  268. display: block;
  269. width: 100%;
  270. content: "\00A0";
  271. overflow: hidden;
  272. opacity: 0;
  273. height: 1rpx;
  274. }
  275. }
  276. </style>