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.

269 lines
6.2 KiB

1 year ago
  1. <!-- 首页虚拟滚动 -->
  2. <template>
  3. <view 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 class="table_main_body">
  12. <view class="table_inner_body" :class="{ animate }" :style="{top: tableTop + 'px'}">
  13. <view class="table_tr" v-for="(item,index) in tableList" :key="index">
  14. <view class="tr1 tr">{{item.planNo}}</view>
  15. <view class="tr2 tr">{{item.type}}</view>
  16. <view class="tr3 tr" v-if="item.startDate!='-'">{{item.startDate}} ~ {{item.endDate}}</view>
  17. <view class="tr3 tr" v-else>-</view>
  18. <view class="tr4 tr" v-if="item.process!='-'">{{Number(item.process).toFixed(2)}} %</view>
  19. <view class="tr4 tr" v-else>-</view>
  20. </view>
  21. </view>
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. export default {
  29. data() {
  30. return {
  31. tableTimer: null,
  32. tableTop: 0,
  33. tableList: [{
  34. "process": 0.0000,
  35. "planNo": "BP2022060701",
  36. "endDate": "2022-06-07",
  37. "type": "砌块",
  38. "startDate": "2022-06-07"
  39. },
  40. {
  41. "process": 0.0000,
  42. "planNo": "WP2022061301",
  43. "endDate": "2022-06-13",
  44. "type": "墙板",
  45. "startDate": "2022-06-13"
  46. },
  47. {
  48. "process": 0.0000,
  49. "planNo": "WP2022061301",
  50. "endDate": "2022-06-13",
  51. "type": "墙板",
  52. "startDate": "2022-06-13"
  53. },
  54. {
  55. "process": 0.0000,
  56. "planNo": "WP2022061301",
  57. "endDate": "2022-06-13",
  58. "type": "墙板",
  59. "startDate": "2022-06-13"
  60. },
  61. {
  62. "process": 0.0000,
  63. "planNo": "WP2022061301",
  64. "endDate": "2022-06-13",
  65. "type": "墙板",
  66. "startDate": "2022-06-13"
  67. },
  68. {
  69. "process": 0.0000,
  70. "planNo": "WP2022061301",
  71. "endDate": "2022-06-13",
  72. "type": "墙板",
  73. "startDate": "2022-06-13"
  74. },
  75. {
  76. "process": 0.0000,
  77. "planNo": "WP2022061301",
  78. "endDate": "2022-06-13",
  79. "type": "墙板",
  80. "startDate": "2022-06-13"
  81. }
  82. ],
  83. tableListSize: 0,
  84. componentTimer: null,
  85. //需要根据情况设置的参数
  86. visibleSize: 3, //容器内可视最大完整行数
  87. lineHeight: this.getRpxToPx(162), //每行的实际高度(包含margin-top/bottom,border等)
  88. componentTimerInterval: 3600000, //刷新数据的时间间隔
  89. tableTimerInterval: 1000, //向上滚动 1px 所需要的时间,越小越快,推荐值 100
  90. animate : true
  91. }
  92. },
  93. //如果没有父元素传值,将watch内的内容搬至mounted中即可
  94. props: ["activeFactoryId"],
  95. watch: {
  96. activeFactoryId(val, oldVal) {
  97. clearInterval(this.componentTimer);
  98. this.bsGetProductProcess();
  99. this.componentTimerFun();
  100. }
  101. },
  102. mounted() {
  103. clearInterval(this.componentTimer);
  104. this.bsGetProductProcess();
  105. this.componentTimerFun();
  106. },
  107. beforeDestroy() {
  108. clearInterval(this.componentTimer);
  109. clearInterval(this.tableTimer);
  110. },
  111. methods: {
  112. //调用数据接口,获取列表数据
  113. bsGetProductProcess() {
  114. clearInterval(this.tableTimer);
  115. this.tableTop = 0;
  116. if (this.activeFactoryId != "") {
  117. // this.request('forgetPass').then(res => {
  118. // if(res.code == 200){
  119. // this.serverList = res.result
  120. // }
  121. // })
  122. this.tableActionFun();
  123. }
  124. },
  125. tableActionFun() {
  126. this.tableListSize = this.tableList.length; //数据总数
  127. if (this.tableListSize > this.visibleSize) { //总数大于容器内可视最大完整行数
  128. this.tableList = this.tableList.concat(this.tableList); //拼接一个数组数据
  129. this.tableTimerFun();
  130. } else {
  131. this.fillTableList();
  132. }
  133. },
  134. //当数据过少时,不触发自动轮播事件,并填充没有数据的行,参数根据实际情况修改即可
  135. fillTableList() {
  136. var addLength = this.visibleSize - this.tableListSize;
  137. for (var i = 0; i < addLength; i++) {
  138. this.tableList.push({
  139. planNo: "-",
  140. type: "-",
  141. startDate: "-",
  142. endDate: "-",
  143. process: "-"
  144. });
  145. }
  146. },
  147. //控制元素滚动
  148. tableTimerFun() {
  149. var count = 0;
  150. this.tableTimer = setInterval(() => {
  151. if (count < (this.tableList.length / 2) * this.lineHeight) {
  152. this.animate = true
  153. this.tableTop -= this.lineHeight;
  154. count += this.lineHeight;
  155. } else {
  156. this.animate = false
  157. this.tableTop = 0;
  158. count = 0;
  159. }
  160. }, this.tableTimerInterval);
  161. },
  162. //更新数据
  163. componentTimerFun() {
  164. this.componentTimer = setInterval(() => {
  165. this.bsGetProductProcess();
  166. }, this.componentTimerInterval);
  167. },
  168. //转换rpx单位
  169. getRpxToPx(rpx) {
  170. // 获取系统信息,这里使用同步方法uni.getSystemInfoSync
  171. const systemInfo = uni.getSystemInfoSync();
  172. // 假设设计稿宽度为750rpx
  173. const designWidth = 750;
  174. // 屏幕宽度,单位为px
  175. const screenWidth = systemInfo.screenWidth;
  176. // 计算1rpx等于多少px
  177. const rpxToPx = screenWidth / (designWidth / rpx);
  178. console.log(rpxToPx);
  179. return rpxToPx;
  180. }
  181. }
  182. }
  183. </script>
  184. <style lang="scss" scoped>
  185. .virtualScroll {
  186. width: 100%;
  187. height: 560rpx;
  188. }
  189. .content {
  190. width: 96%;
  191. margin: 0 auto;
  192. color: $uni-bg-color-app;
  193. }
  194. .title_view {
  195. width: 100%;
  196. font-size: 32rpx;
  197. }
  198. .table_body {
  199. width: 100%;
  200. margin-top: 15rpx;
  201. }
  202. .tr {
  203. overflow: hidden;
  204. text-overflow: ellipsis;
  205. white-space: nowrap;
  206. box-sizing: border-box;
  207. padding: 0 5px;
  208. text-align: center;
  209. font-size: 30rpx;
  210. }
  211. .tr1 {
  212. width: 28%;
  213. }
  214. .tr2 {
  215. width: 15%;
  216. }
  217. .tr3 {
  218. width: 35%;
  219. font-size: 24rpx;
  220. }
  221. .tr4 {
  222. flex: 1;
  223. }
  224. .table_main_body {
  225. width: 100%;
  226. height: 480rpx;
  227. overflow: hidden;
  228. position: relative;
  229. }
  230. .table_inner_body {
  231. width: 98%;
  232. position: absolute;
  233. left: 1%;
  234. }
  235. .animate{
  236. transition: all .3s;
  237. }
  238. .table_tr {
  239. display: flex;
  240. align-items: center;
  241. height: 140rpx;
  242. color: $uni-bg-color-app;
  243. font-size: 30rpx;
  244. margin-bottom: 20rpx;
  245. // box-shadow: 2rpx 2rpx 6rpx 1rpx rgba(0, 0, 0, .1),
  246. // -2rpx -2rpx 6rpx 1rpx rgba(0, 0, 0, .1);
  247. border-radius: 10rpx;
  248. background: $uni-bg-color;
  249. border: 2rpx solid #ccc;
  250. }
  251. </style>