rtone.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <div id="rtone">
  3. <ul>
  4. <li>
  5. 累计完成进尺 :<span>{{one}}</span>m
  6. </li>
  7. <li>
  8. 月 完 成 进尺 :<span>{{two}}</span> m
  9. </li>
  10. <li>
  11. 日 平 均 进尺 :<span>{{three}}</span> m
  12. </li>
  13. <li>
  14. 班 最 高 进尺 :<span>{{four}}</span> m
  15. </li>
  16. <li>
  17. 日 最 高 进尺 :<span>{{five}}</span> m
  18. </li>
  19. <li>
  20. 当 前___人 员 :<span id="six">{{six}}</span>
  21. </li>
  22. </ul>
  23. </div>
  24. </template>
  25. <script>
  26. export default {
  27. data(){
  28. return {
  29. // showValue:'',
  30. one:'',
  31. two:'',
  32. three:'',
  33. four:'',
  34. five:'',
  35. six:'',
  36. allData:null, // 服务器返回的数据
  37. currentPage: 1, //当前显示的页数, 当修改页数时, 数据动态刷新
  38. totalPage: 0, //一共多少也
  39. timerId:null, //定时器
  40. }
  41. },
  42. mounted() {
  43. this.getData()
  44. // 对窗口大小变化的事件进行监听
  45. // window.addEventListener('resize', this.screenAdapter)
  46. },
  47. destroyed(){
  48. clearInterval(this.timerId)
  49. // 在组件销毁的时候, 需要将监听器取消掉
  50. // window.removeEventListener('resize', this.screenAdapter)
  51. },
  52. methods: {
  53. async getData(){
  54. // 请求数据 allData
  55. const { data: ret } = await this.$http.get('hbase/getJSON')
  56. this.allData = ret
  57. // 对数据排序
  58. this.allData.sort((a,b) => {{
  59. return a.value-b.value //从小到大排序
  60. }})
  61. // 每1个元素显示一页
  62. this.totalPage = this.allData.length % 1 ===0 ? this.allData.length /1 : this.allData.length / 1 +1
  63. // 获取完数据, 更新图标
  64. this.updateData()
  65. // 启动定时器, 每隔三秒改变currentPage, 进而更新图表
  66. this.startInterval()
  67. },
  68. updateData() {
  69. const start = (this.currentPage - 1) * 1
  70. const end = this.currentPage * 1
  71. const showData = this.allData.slice(start, end)
  72. this.one = showData[0].leijiwanchengjinchi
  73. this.two = showData[0].benyuewanchengjinchi
  74. this.three = showData[0].ripingjunjinchi
  75. this.four = showData[0].banzuigaojinchi
  76. this.five = showData[0].rizuigaojinchi
  77. this.six = showData[0].dangqianrenyuan
  78. },
  79. startInterval () {
  80. // 每个3秒执行一次
  81. setInterval(() => {
  82. // 保险操作
  83. if(this.timeId){
  84. clearInterval(this.timerId)
  85. }
  86. this.currentPage++
  87. // 当页数超过总页数是, 从头开始
  88. if(this.currentPage > this.totalPage){
  89. this.currentPage = 1
  90. }
  91. this.updateData()
  92. },3000)
  93. }
  94. }
  95. }
  96. </script>
  97. <style scoped>
  98. li{
  99. width: 100%;
  100. height: 100%;
  101. color: royalblue;
  102. display: flex;
  103. /* flex-direction: column; */
  104. font-size: 1.25rem;
  105. position: relative;
  106. }
  107. span{
  108. width: 7.5rem;
  109. height: 1.625rem;
  110. background-color: rgb(133, 158, 231);
  111. margin: 0 .325rem .25rem;
  112. text-align: center;
  113. }
  114. </style>