Touchbox.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <template>
  2. <view class="site-box" ref="fixbox" :style="{ 'z-index':zIndex , 'height':popupHeight + 'px'}">
  3. <view class="tap-touch-line" @touchmove="getstart" @touchend="getend" />
  4. <slot />
  5. <!-- <scroll-view :style="{'height':scrollHeight - 20 + 'px' }" scroll-y="true" :show-scrollbar="false">
  6. <template v-for="item in siteListArr">
  7. <siteListModel :info="item" @checkSiteDetails="checkSiteDetails" />
  8. </template>
  9. </scroll-view> -->
  10. <!-- @touchmove="getstart" @tap="tap" @touchend="getend" -->
  11. <!-- :style="{'height':windowHeight + 'px','width':windowWidth + 'px','top':fixboxtop +'px','border-top-left-radius':radius,'border-top-right-radius':radius,'z-index':zIndex}" -->
  12. <!-- <view class="content" :style="{'height':windowHeight + 'px'}">
  13. <view class="tapBoxTouchLine" v-if="showLine">
  14. <view class="line" :style="{'transform': `scaleY(${lineScale})`,'width':`${lineWidth}rpx`}"></view>
  15. </view>
  16. <slot />
  17. </view> -->
  18. </view>
  19. </template>
  20. <script>
  21. export default {
  22. name: 'Touchbox',
  23. data() {
  24. return {
  25. windowHeight: 0,
  26. touchHeight: uni.upx2px(80),
  27. popupHeight: 0,
  28. oldHeight: 0,
  29. scrollHeight: 0,
  30. minTop: 0,
  31. maxTop: 0,
  32. };
  33. },
  34. props: {
  35. zIndex: {
  36. type: Number,
  37. default: 99,
  38. },
  39. smallHeight: {
  40. type: Number,
  41. default: 0.35,
  42. },
  43. maxHeight: {
  44. type: Number,
  45. default: 0.65,
  46. },
  47. // minHeight: {
  48. // type: Number,
  49. // default: 0.2,
  50. // },
  51. },
  52. created() {
  53. const { windowHeight } = uni.getSystemInfoSync();
  54. this.windowHeight = windowHeight;
  55. // this.windowWidth = uni.getSystemInfoSync().windowWidth;
  56. this.popupHeight = this.oldHeight = windowHeight * this.smallHeight;
  57. this.maxTop = windowHeight * (1 - this.smallHeight);
  58. this.minTop = windowHeight * (1 - this.maxHeight);
  59. // minTop:0,
  60. // maxTop:0,
  61. },
  62. mounted() {
  63. this.$nextTick(function() {
  64. // this.windowWidth = uni.getSystemInfoSync().windowWidth;
  65. // this.windowHeight = uni.getSystemInfoSync().windowHeight;
  66. // var defaultHeight = this.windowHeight * (1 - this.minHeight);
  67. // this.firsttop = defaultHeight;
  68. // this.phonetop =
  69. // (this.windowHeight * this.maxHeight - this.windowHeight * this.minHeight) / 2;
  70. // this.phoneMinTop =
  71. // (this.windowHeight * this.minHeight - this.windowHeight * this.smallHeight) / 2;
  72. // this.fixboxtop = defaultHeight;
  73. // this.$emit('currentHeight', this.windowHeight - this.fixboxtop);
  74. // this.$emit('maxtHeight', this.windowHeight * this.maxHeight);
  75. });
  76. },
  77. onReady() {},
  78. computed: {},
  79. watch: {
  80. popupHeight(newH, oldH) {
  81. this.scrollHeight = newH - this.touchHeight;
  82. },
  83. scrollHeight: {
  84. handler(newH) {
  85. this.$emit('currentHeight', newH);
  86. },
  87. immediate: true
  88. }
  89. },
  90. methods: {
  91. // 隐藏
  92. concealList() {
  93. this.popupHeight = this.touchHeight
  94. },
  95. getstart(e) {
  96. e.preventDefault();
  97. const { clientY, screenY } = e.touches[0];
  98. const Y = clientY || screenY;
  99. console.log(Y, this.maxTop)
  100. // // 这里特殊处理 解决:在滑动框内如果存在滚动元素,则会出现滑动时滑动框和内部滚动同时滑的问题
  101. if (Y < this.minTop || Y > (this.windowHeight - this.touchHeight)) {
  102. return
  103. }
  104. this.popupHeight = this.windowHeight - Y;
  105. },
  106. getend() {
  107. if (this.popupHeight >= this.oldHeight && (this.popupHeight - this.oldHeight) > 50) {
  108. // 上拉
  109. this.popupHeight = this.windowHeight * this.maxHeight
  110. } else if ((this.oldHeight - this.popupHeight) > 50) {
  111. console.log("this.oldHeight = ", this.oldHeight, "this.popupHeight = ", this.popupHeight)
  112. const s_h = this.windowHeight * this.smallHeight;
  113. // 下拉
  114. if (this.popupHeight >= s_h) {
  115. // 在中等偏上区域,还原成中等高度
  116. this.popupHeight = s_h
  117. } else {
  118. // 在中等偏下区域,还原成最小高度
  119. this.popupHeight = this.touchHeight
  120. }
  121. } else {
  122. // 拉取幅度不够,还原,防止误触发
  123. this.popupHeight = this.oldHeight
  124. };
  125. // 记录当前高度
  126. this.oldHeight = this.popupHeight;
  127. },
  128. },
  129. };
  130. </script>
  131. <style lang="scss" scoped>
  132. .site-box {
  133. position: fixed;
  134. left: 0;
  135. right: 0;
  136. bottom: 0;
  137. background-color: #ffffff;
  138. // padding: 0 12px;
  139. transition-property: top;
  140. transition-duration: 0.7s;
  141. border-radius: 40rpx 40rpx 0 0;
  142. .tap-touch-line {
  143. width: 100%;
  144. height: 80rpx;
  145. position: relative;
  146. &:before {
  147. content: '';
  148. position: absolute;
  149. left: 50%;
  150. top: 50%;
  151. transform: translate(-50%, -50%);
  152. width: 30%;
  153. height: 8rpx;
  154. border-radius: 4rpx;
  155. background-color: rgb(214, 215, 217);
  156. }
  157. }
  158. }
  159. // .tapBoxTouchLine {
  160. // display: flex;
  161. // align-items: center;
  162. // justify-content: center;
  163. // padding: 20rpx 0 30rpx;
  164. // }
  165. // .line {
  166. // margin: 0px;
  167. // vertical-align: middle;
  168. // // border-bottom: 8rpx solid rgb(214, 215, 217);
  169. // height: 8rpx;
  170. // background-color: rgb(214, 215, 217);
  171. // border-radius: 4rpx;
  172. // // border: 4rpx;
  173. // // border-top-color: rgb(214, 215, 217);
  174. // // border-right-color: rgb(214, 215, 217);
  175. // // border-left-color: rgb(214, 215, 217);
  176. // }
  177. // .fixedbox {
  178. // position: fixed;
  179. // left: 0;
  180. // background-color: #ffffff;
  181. // padding: 0 12px;
  182. // }
  183. // .fixedbox2 {
  184. // position: fixed;
  185. // left: 0;
  186. // background-color: #ffffff;
  187. // padding: 0 12px;
  188. // transition-property: top;
  189. // transition-duration: 0.4s;
  190. // }
  191. </style>