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.

131 lines
3.1 KiB

8 months ago
  1. <!-- 虚拟滚动组件 -->
  2. <template>
  3. <view class="virtualScroll">
  4. <view class="virtualScroll-title">{{ $t('page.virtualScroll.title') }}</view>
  5. <!-- 滚动列表 -->
  6. <view
  7. :style="{ height : scrollListLength >= maxShowNumber ? `${ maxShowNumber * 160 }rpx` : `${scrollListLength * 164}rpx` }"
  8. class="scroll-list">
  9. <view :class="{ animate }" :style="{ transform : `translate(0rpx,${ -scrollPostion }rpx)`}">
  10. <!-- 主要数据 -->
  11. <view class="scroll-list-main-data">
  12. <view ref="scrollItem" v-for="item in scrollList" :key="item.id" class="scroll-item">
  13. <view class="user-name">{{ item.auccont }}</view>
  14. <view class="money">{{ item.money }}</view>
  15. <view class="time">{{ item.createTime }}</view>
  16. </view>
  17. </view>
  18. <!-- 副本数据 -->
  19. <view class="scroll-list-copy-data">
  20. <view v-for="item in scrollList" :key="item.id" class="scroll-item">
  21. <view class="user-name">{{ item.auccont }}</view>
  22. <view class="money">{{ item.money }}</view>
  23. <view class="time">{{ item.createTime }}</view>
  24. </view>
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. export default {
  32. data() {
  33. return {
  34. scrollList: [], //滚动的数据列表
  35. scrollListLength: 0, //滚动数据列表数据总数
  36. maxShowNumber: 3, //显示个数
  37. scrollInterval: null, //控制元素滚动的定时器
  38. topInterval: null, //返回顶部定时器
  39. scrollPostion: 0, //滚动位置
  40. animate: true, //是否显示延迟动画效果
  41. lineHeight: 0, //每个滚动元素的高度
  42. }
  43. },
  44. mounted() {
  45. this.getScrollList()
  46. },
  47. methods: {
  48. //获取滚动列表
  49. async getScrollList() {
  50. this.request('getIndexScroll').then(res => {
  51. if (res.code == 200) {
  52. this.scrollList = res.result
  53. this.scrollListLength = res.result.length
  54. this.scroll()
  55. }
  56. })
  57. },
  58. //控制元素滚动
  59. scroll() {
  60. this.scrollInterval = setInterval(() => {
  61. this.animate = true
  62. this.scrollPostion += 160
  63. }, 1000)
  64. this.topInterval = setInterval(() => {
  65. if (this.scrollPostion > this.scrollListLength * 160) {
  66. this.animate = false
  67. clearInterval(this.scrollInterval)
  68. clearInterval(this.topInterval)
  69. this.scrollPostion = 0
  70. this.scroll()
  71. }
  72. }, 100)
  73. },
  74. }
  75. }
  76. </script>
  77. <style lang="scss" scoped>
  78. .virtualScroll {
  79. margin: 0rpx auto;
  80. width: 96%;
  81. .virtualScroll-title {
  82. display: flex;
  83. align-items: center;
  84. font-size: 36rpx;
  85. height: 80rpx;
  86. color: $uni-bg-color-app;
  87. }
  88. .scroll-list {
  89. overflow: hidden;
  90. // 主要数据 、副本数据
  91. .scroll-list-main-data,
  92. .scroll-list-copy-data {
  93. padding-top: 20rpx;
  94. .scroll-item {
  95. display: flex;
  96. align-items: center;
  97. height: 140rpx;
  98. width: 98%;
  99. margin-left: 1%;
  100. margin-bottom: 20rpx;
  101. border-radius: 10rpx;
  102. box-shadow: 4rpx 4rpx 10rpx rgba(0, 0, 0, .1),
  103. -4rpx -4rpx 10rpx rgba(0, 0, 0, .1);
  104. view {
  105. flex: 1;
  106. text-align: center;
  107. &:nth-child(3) {
  108. flex: 2;
  109. }
  110. }
  111. }
  112. }
  113. .animate {
  114. transition: all .4s linear;
  115. }
  116. }
  117. }
  118. </style>