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.

273 lines
6.4 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
  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": "block",
  38. "startDate": "2022-06-07"
  39. },
  40. {
  41. "process": 0.0000,
  42. "planNo": "WP2022061301",
  43. "endDate": "2022-06-13",
  44. "type": "wallboard",
  45. "startDate": "2022-06-13"
  46. },
  47. {
  48. "process": 0.0000,
  49. "planNo": "WP2022061301",
  50. "endDate": "2022-06-13",
  51. "type": "wallboard",
  52. "startDate": "2022-06-13"
  53. },
  54. {
  55. "process": 0.0000,
  56. "planNo": "WP2022061301",
  57. "endDate": "2022-06-13",
  58. "type": "wallboard",
  59. "startDate": "2022-06-13"
  60. },
  61. {
  62. "process": 0.0000,
  63. "planNo": "WP2022061301",
  64. "endDate": "2022-06-13",
  65. "type": "wallboard",
  66. "startDate": "2022-06-13"
  67. },
  68. {
  69. "process": 0.0000,
  70. "planNo": "WP2022061301",
  71. "endDate": "2022-06-13",
  72. "type": "wallboard",
  73. "startDate": "2022-06-13"
  74. },
  75. {
  76. "process": 0.0000,
  77. "planNo": "WP2022061301",
  78. "endDate": "2022-06-13",
  79. "type": "wallboard",
  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. let screenWidth = systemInfo.screenWidth;
  176. //防止屏幕过大时转换的值太大。超过960就设置screenWidth为版心宽度
  177. if(screenWidth > 960){
  178. screenWidth = 375
  179. }
  180. // 计算1rpx等于多少px
  181. const rpxToPx = screenWidth / (designWidth / rpx);
  182. console.log(rpxToPx);
  183. return rpxToPx;
  184. }
  185. }
  186. }
  187. </script>
  188. <style lang="scss" scoped>
  189. .virtualScroll {
  190. width: 100%;
  191. height: 560rpx;
  192. }
  193. .content {
  194. width: 96%;
  195. margin: 0 auto;
  196. color: $uni-bg-color-app;
  197. }
  198. .title_view {
  199. width: 100%;
  200. font-size: 32rpx;
  201. }
  202. .table_body {
  203. width: 100%;
  204. margin-top: 15rpx;
  205. }
  206. .tr {
  207. overflow: hidden;
  208. text-overflow: ellipsis;
  209. white-space: nowrap;
  210. box-sizing: border-box;
  211. padding: 0 5px;
  212. text-align: center;
  213. font-size: 30rpx;
  214. }
  215. .tr1 {
  216. width: 28%;
  217. }
  218. .tr2 {
  219. width: 15%;
  220. }
  221. .tr3 {
  222. width: 35%;
  223. font-size: 24rpx;
  224. }
  225. .tr4 {
  226. flex: 1;
  227. }
  228. .table_main_body {
  229. width: 100%;
  230. height: 480rpx;
  231. overflow: hidden;
  232. position: relative;
  233. }
  234. .table_inner_body {
  235. width: 98%;
  236. position: absolute;
  237. left: 1%;
  238. }
  239. .animate{
  240. transition: all .3s;
  241. }
  242. .table_tr {
  243. display: flex;
  244. align-items: center;
  245. height: 140rpx;
  246. color: $uni-bg-color-app;
  247. font-size: 30rpx;
  248. margin-bottom: 20rpx;
  249. // box-shadow: 2rpx 2rpx 6rpx 1rpx rgba(0, 0, 0, .1),
  250. // -2rpx -2rpx 6rpx 1rpx rgba(0, 0, 0, .1);
  251. border-radius: 10rpx;
  252. background: $uni-bg-color;
  253. border: 2rpx solid #ccc;
  254. }
  255. </style>