index.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <scroll-view class="u-scroll-view" :scroll-y="true" style="height: 100%" @scrolltolower="onScrollToLower" @scroll="onScroll" :scroll-into-view="scrollIntoViewId">
  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. scrollIntoViewId: {
  18. type: String,
  19. default: ''
  20. },
  21. tabbarConflict: Boolean,
  22. showEmpty: {
  23. type: Boolean,
  24. default: false
  25. },
  26. loadMore: {
  27. type: Boolean,
  28. default: false
  29. }
  30. },
  31. computed: {
  32. pageScrollStyle() {
  33. let pageHeight = this.$config.pageHeight
  34. if (this.tabbarConflict) {
  35. pageHeight = this.$config.pageHeight - uni.upx2px(150)
  36. }
  37. // return 'height: ' + pageHeight + 'px'
  38. return 'height: 100%'
  39. }
  40. },
  41. watch: {
  42. },
  43. data() {
  44. return {
  45. }
  46. },
  47. created() {
  48. },
  49. mounted() {
  50. },
  51. methods: {
  52. getScrollViewHeight() {
  53. // 获取 scroll-view 元素的高度
  54. uni.createSelectorQuery()
  55. .in(this)
  56. .select('.u-scroll-view')
  57. .boundingClientRect(rect => {
  58. })
  59. .exec()
  60. },
  61. onScroll(e) {
  62. uni.createSelectorQuery()
  63. .in(this)
  64. .select('.u-scroll-view')
  65. .boundingClientRect(rect => {
  66. const scrollTop = e.detail.scrollTop
  67. if (scrollTop + rect.height + 100 > e.detail.scrollHeight) {
  68. if (this.timer) {
  69. clearTimeout(this.timer)
  70. this.timer = null
  71. }
  72. this.timer = setTimeout(() => {
  73. this.$emit('scrollNearLower', e)
  74. }, 50)
  75. }
  76. })
  77. .exec()
  78. this.$emit('scroll', e)
  79. },
  80. onScrollToLower(e) {
  81. this.$emit('scrolltolower', e)
  82. }
  83. }
  84. }
  85. </script>
  86. <style lang="scss">
  87. .load-more{
  88. display: flex;
  89. justify-content: center;
  90. .van-loading__text{
  91. font-size: $fontSize2;
  92. }
  93. }
  94. ::v-deep {
  95. .u-scroll-view {
  96. /*&.mobile {
  97. padding-top: 100rpx;
  98. }*/
  99. }
  100. }
  101. </style>