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.

183 lines
4.5 KiB

9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
  1. <!-- 首页虚拟滚动 -->
  2. <template>
  3. <view :style="{ height : tableListSize < visibleSize ? tableListSize * lineHeight + getRpxToPx(65) + 'px' : '560rpx' }" class="virtualScroll content">
  4. <view class="success_info_body">
  5. <!-- 标准title可以调用组件 -->
  6. <view class="title_view">
  7. {{ $t('page.virtualScroll.title') }}
  8. </view>
  9. <!-- 参数名称列数根据实际情况调整 -->
  10. <view class="table_body">
  11. <view :style="{ height : tableListSize < visibleSize ? tableListSize * lineHeight + 'px' : '480rpx'}" class="table_main_body">
  12. <view class="table_inner_body" :class="{ animate }" :style="{ transform: 'translateY(' + tableTop + 'px)' , height : tableListSize < visibleSize ? tableListSize * lineHeight + 'px' : '480rpx'}">
  13. <view class="table_tr" v-for="(item,index) in tableList" :key="index">
  14. <view class="tr1 tr">{{item.auccont}}</view>
  15. <view class="tr2 tr">{{item.money}}</view>
  16. <view class="tr3 tr" v-if="item.createTime">{{item.createTime}}</view>
  17. <view class="tr3 tr" v-else>-</view>
  18. </view>
  19. </view>
  20. </view>
  21. </view>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. export default {
  27. data() {
  28. return {
  29. tableTimer: null,
  30. tableTop: 0,
  31. tableList: [],
  32. tableListSize: 0,
  33. componentTimer: null,
  34. //需要根据情况设置的参数
  35. visibleSize: 3, //容器内可视最大完整行数
  36. //这里分三个比分写对应样式的高、下外边距、边框计算。直接整体计算有些误差
  37. lineHeight: this.getRpxToPx(140) + this.getRpxToPx(20) + this.getRpxToPx(2), //每行的实际高度(包含margin-top/bottom,border等)
  38. componentTimerInterval: 3600000, //刷新数据的时间间隔
  39. tableTimerInterval: 1000, //向上滚动 1px 所需要的时间,越小越快,推荐值 100
  40. animate : true
  41. }
  42. },
  43. mounted() {
  44. clearInterval(this.componentTimer);
  45. this.bsGetProductProcess();
  46. },
  47. beforeDestroy() {
  48. clearInterval(this.componentTimer);
  49. clearInterval(this.tableTimer);
  50. },
  51. methods: {
  52. //调用数据接口,获取列表数据
  53. bsGetProductProcess() {
  54. clearInterval(this.tableTimer);
  55. this.tableTop = 0;
  56. this.request('getIndexScroll').then(res => {
  57. if(res.code == 200){
  58. this.tableList = res.result
  59. this.tableActionFun();
  60. }
  61. })
  62. },
  63. tableActionFun() {
  64. this.tableListSize = this.tableList.length; //数据总数
  65. this.tableList = this.tableList.concat(this.tableList); //拼接一个数组数据
  66. this.tableTimerFun();
  67. },
  68. //控制元素滚动
  69. tableTimerFun() {
  70. var count = 0;
  71. this.tableTimer = setInterval(() => {
  72. if (count < (this.tableList.length / 2) * this.lineHeight) {
  73. this.animate = true
  74. this.tableTop -= this.lineHeight
  75. count += this.lineHeight
  76. } else {
  77. this.animate = false
  78. this.tableTop = 0;
  79. count = 0;
  80. }
  81. }, this.tableTimerInterval);
  82. },
  83. //转换rpx单位
  84. getRpxToPx(rpx) {
  85. // 获取系统信息,这里使用同步方法uni.getSystemInfoSync
  86. const systemInfo = uni.getSystemInfoSync();
  87. // 假设设计稿宽度为750rpx
  88. const designWidth = 750;
  89. // 屏幕宽度,单位为px
  90. let screenWidth = systemInfo.screenWidth;
  91. //防止屏幕过大时转换的值太大。超过960就设置screenWidth为版心宽度
  92. if(screenWidth > 960){
  93. screenWidth = 375
  94. }
  95. // 计算1rpx等于多少px
  96. const rpxToPx = screenWidth / (designWidth / rpx);
  97. return parseInt(rpxToPx);
  98. }
  99. }
  100. }
  101. </script>
  102. <style lang="scss" scoped>
  103. .virtualScroll {
  104. width: 100%;
  105. }
  106. .content {
  107. width: 96%;
  108. margin: 0 auto;
  109. color: $uni-bg-color-app;
  110. }
  111. .title_view {
  112. display: flex;
  113. align-items: center;
  114. width: 100%;
  115. font-size: 32rpx;
  116. height: 50rpx;
  117. }
  118. .table_body {
  119. width: 100%;
  120. margin-top: 15rpx;
  121. }
  122. .tr {
  123. overflow: hidden;
  124. text-overflow: ellipsis;
  125. white-space: nowrap;
  126. box-sizing: border-box;
  127. padding: 0 5px;
  128. text-align: center;
  129. font-size: 30rpx;
  130. }
  131. .tr1 {
  132. width: 28%;
  133. }
  134. .tr2 {
  135. width: 22%;
  136. }
  137. .tr3 {
  138. width: 50%;
  139. font-size: 24rpx;
  140. }
  141. .table_main_body {
  142. width: 100%;
  143. overflow: hidden;
  144. }
  145. .table_inner_body {
  146. width: 98%;
  147. margin-left: 1%;
  148. }
  149. .animate{
  150. transition: all .3s;
  151. }
  152. .table_tr {
  153. display: flex;
  154. align-items: center;
  155. height: 140rpx;
  156. color: $uni-bg-color-app;
  157. font-size: 30rpx;
  158. margin-bottom: 20rpx;
  159. // box-shadow: 2rpx 2rpx 6rpx 1rpx rgba(0, 0, 0, .1),
  160. // -2rpx -2rpx 6rpx 1rpx rgba(0, 0, 0, .1);
  161. border-radius: 10rpx;
  162. background: $uni-bg-color;
  163. border: 2rpx solid #ccc;
  164. }
  165. </style>