index.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <scroll-view class="u-scroll-view" :class="navType" :scroll-y="true" :style="pageScrollStyle" @scrolltolower="onScrollToLower" @scroll="onScroll">
  3. <slot></slot>
  4. <view v-if="loadMore" class="load-more"><van-loading>加载中...</van-loading></view>
  5. </scroll-view>
  6. </template>
  7. <script>
  8. import VanLoading from '@/wxcomponents/vant/loading/index'
  9. export default {
  10. options: {
  11. styleIsolation: 'shared'
  12. },
  13. components: {
  14. VanLoading
  15. },
  16. props: {
  17. tabbarConflict: Boolean,
  18. showEmpty: {
  19. type: Boolean,
  20. default: false
  21. },
  22. loadMore: {
  23. type: Boolean,
  24. default: false
  25. }
  26. },
  27. computed: {
  28. pageScrollStyle() {
  29. let pageHeight = this.$config.pageHeight
  30. if (this.tabbarConflict) {
  31. pageHeight = this.$config.pageHeight - uni.upx2px(150)
  32. }
  33. console.log(pageHeight)
  34. // return 'height: ' + pageHeight + 'px'
  35. return 'height: 100%'
  36. }
  37. },
  38. watch: {
  39. },
  40. data() {
  41. return {
  42. navType: 'mobile'
  43. }
  44. },
  45. created() {
  46. },
  47. mounted() {
  48. this.getSystemInfo(this,(res)=>{
  49. this.navType = res
  50. })
  51. },
  52. methods: {
  53. getScrollViewHeight() {
  54. // 获取 scroll-view 元素的高度
  55. uni.createSelectorQuery()
  56. .in(this)
  57. .select('.u-scroll-view')
  58. .boundingClientRect(rect => {
  59. console.log(rect)
  60. console.log('scroll-view 高度:', rect.height)
  61. })
  62. .exec()
  63. },
  64. onScroll(e) {
  65. uni.createSelectorQuery()
  66. .in(this)
  67. .select('.u-scroll-view')
  68. .boundingClientRect(rect => {
  69. const scrollTop = e.detail.scrollTop
  70. if (scrollTop + rect.height + 100 > e.detail.scrollHeight) {
  71. if (this.timer) {
  72. clearTimeout(this.timer)
  73. this.timer = null
  74. }
  75. this.timer = setTimeout(() => {
  76. this.$emit('scrollNearLower', e)
  77. }, 50)
  78. }
  79. })
  80. .exec()
  81. this.$emit('scroll', e)
  82. },
  83. onScrollToLower(e) {
  84. this.$emit('scrolltolower', e)
  85. }
  86. }
  87. }
  88. </script>
  89. <style lang="scss">
  90. .load-more{
  91. display: flex;
  92. justify-content: center;
  93. .van-loading__text{
  94. font-size: $fontSize2;
  95. }
  96. }
  97. ::v-deep {
  98. .u-scroll-view {
  99. /*&.mobile {
  100. padding-top: 100rpx;
  101. }*/
  102. }
  103. }
  104. </style>