index.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <scroll-view class="u-scroll-view" :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. return 'height: ' + pageHeight + 'px'
  34. }
  35. },
  36. watch: {
  37. },
  38. data() {
  39. return {}
  40. },
  41. created() {
  42. },
  43. mounted() {
  44. },
  45. methods: {
  46. getScrollViewHeight() {
  47. // 获取 scroll-view 元素的高度
  48. uni.createSelectorQuery()
  49. .in(this)
  50. .select('.u-scroll-view')
  51. .boundingClientRect(rect => {
  52. console.log(rect)
  53. console.log('scroll-view 高度:', rect.height)
  54. })
  55. .exec()
  56. },
  57. onScroll(e) {
  58. uni.createSelectorQuery()
  59. .in(this)
  60. .select('.u-scroll-view')
  61. .boundingClientRect(rect => {
  62. const scrollTop = e.detail.scrollTop
  63. if (scrollTop + rect.height + 100 > e.detail.scrollHeight) {
  64. if (this.timer) {
  65. clearTimeout(this.timer)
  66. this.timer = null
  67. }
  68. this.timer = setTimeout(() => {
  69. this.$emit('scrollNearLower', e)
  70. }, 50)
  71. }
  72. })
  73. .exec()
  74. this.$emit('scroll', e)
  75. },
  76. onScrollToLower(e) {
  77. this.$emit('scrolltolower', e)
  78. }
  79. }
  80. }
  81. </script>
  82. <style lang="scss">
  83. .load-more{
  84. display: flex;
  85. justify-content: center;
  86. .van-loading__text{
  87. font-size: $fontSize2;
  88. }
  89. }
  90. </style>