index.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <div class="centerRight2">
  3. <div class="bg-color-black">
  4. <div class="d-flex pt-2 pl-2">
  5. <span>
  6. <i class="iconfont icon-vector" />
  7. </span>
  8. <div class="d-flex">
  9. <span class="fs-xl text mx-2">任务完成排行榜</span>
  10. </div>
  11. </div>
  12. <div class="d-flex mt-1 jc-center body-box">
  13. <dv-scroll-board
  14. ref="scrollBoard"
  15. class="dv-scr-board"
  16. :config="config"
  17. />
  18. </div>
  19. </div>
  20. </div>
  21. </template>
  22. <script>
  23. export default {
  24. data() {
  25. return {
  26. config: {
  27. header: ["托盘号","批次号", "起始位置", "终止位置", "任务状态"],
  28. data: [
  29. ["数据加载中..."," ", " ", " ", " "],
  30. [" ", " ", " ", " "," "],
  31. [" ", " ", " ", " "," "],
  32. [" ", " ", " ", " "," "],
  33. [" ", " ", " ", " "," "],
  34. [" ", " ", " ", " "," "],
  35. [" ", " ", " ", " "," "],
  36. ],
  37. rowNum: 7,
  38. headerHeight: 35,
  39. headerBGC: "#0f1325",
  40. oddRowBGC: "#0f1325",
  41. evenRowBGC: "#171c33",
  42. index: true,
  43. columnWidth: [5,75,150],
  44. align: ["center", "center", "center", "center", "center"],
  45. },
  46. intervalId: null,
  47. token: "PDA1",
  48. };
  49. },
  50. mounted() {
  51. this.fetchData();
  52. // 每分钟刷新一次数据
  53. this.intervalId = setInterval(this.fetchData, 60000);
  54. },
  55. beforeUnmount() {
  56. // 清除定时器
  57. clearInterval(this.intervalId);
  58. },
  59. methods: {
  60. async fetchData() {
  61. try {
  62. const headers = new Headers({
  63. Accept: "application/json, text/plain, */*",
  64. token: this.token,
  65. });
  66. const url = "http://192.168.18.200:8008/container/wcs_task/";
  67. // const url = "http://192.168.18.200:8008/container/wcs_task/";
  68. const response = await fetch(url, {
  69. method: "GET",
  70. headers: headers,
  71. });
  72. if (!response.ok) {
  73. throw new Error(
  74. `网络错误: ${response.status} ${response.statusText}`
  75. );
  76. }
  77. const jsonData = await response.json();
  78. console.log("数据获取成功:", jsonData);
  79. const tableData = jsonData.results.map((item) => [
  80. item.container,
  81. item.batch_code,
  82. item.current_location,
  83. item.target_location,
  84. item.message,
  85. ]);
  86. // 应用平台主题色
  87. const statusColors = {
  88. 进行中: "#ffb638", // 橘黄色
  89. 任务已完成: "#2ed47a", // 绿色
  90. 等待出库: "#3c9aff", // 蓝色
  91. };
  92. while (tableData.length < 7) {
  93. tableData.push(["-", "-", "-", "-", "-"]);
  94. }
  95. const formattedData = tableData.map((row) => {
  96. const status = row[4];
  97. return [
  98. `<span style="color: #fff">${row[0]}</span>`,
  99. `<span style="color: #c0e4ff">${row[1]}</span>`,
  100. `<span style="color: #c0e4ff">${row[2]}</span>`,
  101. `<span style="color: #c0e4ff">${row[3]}</span>`,
  102. `<span style="color: ${
  103. statusColors[status] || "#fff"
  104. }; font-weight: 500">${status}</span>`,
  105. ];
  106. });
  107. this.config.data =
  108. tableData.length > 0 ? formattedData : [["暂无数据", "", "", ""]];
  109. console.log("数据处理成功:", this.config.data);
  110. this.$refs["scrollBoard"].updateRows(this.config.data);
  111. } catch (error) {
  112. console.error("数据获取失败:", error);
  113. const errorMessage = `加载失败: ${error.message}`;
  114. this.config.data = [
  115. [errorMessage, "", "", ""],
  116. ["请检查网络连接", "", "", ""],
  117. ["或服务地址是否正确", "", "", ""],
  118. ["Token: " + this.token, "", "", ""],
  119. ];
  120. }
  121. },
  122. },
  123. };
  124. </script>
  125. <style lang="scss" scoped>
  126. $box-height: 410px;
  127. $box-width: 100%;
  128. .centerRight2 {
  129. padding: 16px;
  130. padding-top: 20px;
  131. height: $box-height;
  132. width: $box-width;
  133. border-radius: 5px;
  134. .bg-color-black {
  135. height: $box-height - 30px;
  136. border-radius: 10px;
  137. }
  138. .text {
  139. color: #c3cbde;
  140. }
  141. .body-box {
  142. border-radius: 10px;
  143. overflow: hidden;
  144. .dv-scr-board {
  145. width: 98%;
  146. height: 340px;
  147. }
  148. }
  149. }
  150. </style>