equipment.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <template>
  2. <div class="chart-list">
  3. <div class="chart-item">
  4. <chart-box name="温度">
  5. <one-line-chart
  6. class="line-chart"
  7. key="temperature"
  8. name="温度"
  9. :yData="temperatureData"
  10. :minData="[]"
  11. :chartDate="chartDate"
  12. yAxisUnit="°"
  13. ></one-line-chart>
  14. <div class="box-bg tips">
  15. <div class="text">
  16. 暂无数据
  17. </div>
  18. </div>
  19. </chart-box>
  20. </div>
  21. <div class="chart-item">
  22. <chart-box name="湿度">
  23. <one-line-chart
  24. class="line-chart"
  25. key="humidity"
  26. name="湿度"
  27. :yData="humidityData"
  28. :minData="[]"
  29. :chartDate="chartDate"
  30. yAxisUnit="%"
  31. ></one-line-chart>
  32. <div class="box-bg tips">
  33. <div class="text">
  34. 暂无数据
  35. </div>
  36. </div>
  37. </chart-box>
  38. </div>
  39. <div class="chart-item">
  40. <chart-box name="光照">
  41. <one-line-chart
  42. class="line-chart"
  43. name="光照"
  44. key="light"
  45. :yData="lightData"
  46. :minData="[]"
  47. :chartDate="chartDate"
  48. yAxisUnit="ml"
  49. ></one-line-chart>
  50. <div class="box-bg tips">
  51. <div class="text">
  52. 暂无数据
  53. </div>
  54. </div>
  55. </chart-box>
  56. </div>
  57. </div>
  58. </template>
  59. <script setup>
  60. import chartBox from "@/components/chartBox.vue";
  61. import oneLineChart from "@/components/charts/oneLineChart.vue";
  62. import { ref, watch, nextTick } from "vue";
  63. const props = defineProps({
  64. farmId: {
  65. type: [Number, String],
  66. default: null,
  67. },
  68. });
  69. watch(() => props.farmId, async (newVal, oldVal) => {
  70. if(newVal) {
  71. // 使用 nextTick 确保 DOM 更新完成后再执行
  72. await nextTick();
  73. getList();
  74. } else {
  75. // 如果 farmId 变为空,清空数据
  76. temperatureData.value = [];
  77. humidityData.value = [];
  78. lightData.value = [];
  79. chartDate.value = [];
  80. }
  81. }, {
  82. immediate: true, // 立即执行一次
  83. });
  84. const temperatureData = ref([]);
  85. const humidityData = ref([]);
  86. const lightData = ref([]);
  87. const chartDate = ref([]);
  88. function getList() {
  89. VE_API.warning.fetchFarmDeviceRecord({ farmId: props.farmId }).then((res) => {
  90. if(res.code === 0 && res.data && res.data.length > 0) {
  91. temperatureData.value = res.data.map(item => item.temperature.toFixed(2));
  92. humidityData.value = res.data.map(item => item.humidity.toFixed(2));
  93. lightData.value = res.data.map(item => item.illumination.toFixed(2));
  94. chartDate.value = res.data.map(item => formattedDates(item.recordTime));
  95. }else{
  96. temperatureData.value = [];
  97. humidityData.value = [];
  98. lightData.value = [];
  99. chartDate.value = [];
  100. }
  101. });
  102. }
  103. function formattedDates(date) {
  104. if (!date) return '';
  105. // 处理 ISO 8601 格式:2025-10-01T00:00:00
  106. // 先分割 T 获取日期部分,再分割 - 获取年月日
  107. const datePart = date.split('T')[0]; // 获取日期部分:2025-10-01
  108. const [year, month, day] = datePart.split("-");
  109. return `${month}-${day}`; // 返回 MM-DD 格式
  110. }
  111. </script>
  112. <style lang="scss" scoped>
  113. .chart-list {
  114. width: 100%;
  115. height: 100%;
  116. .chart-item {
  117. width: 100%;
  118. margin-bottom: 5px;
  119. height: 280px;
  120. .import {
  121. font-size: 12px;
  122. background: rgba(255, 255, 255, 0.2);
  123. border-radius: 4px;
  124. padding: 5px 13px;
  125. cursor: pointer;
  126. }
  127. .line-chart {
  128. width: 100%;
  129. height: calc(100% - 70px);
  130. }
  131. .base-wrap {
  132. width: 100%;
  133. height: 56px;
  134. margin-top: 4px;
  135. display: flex;
  136. justify-content: space-evenly;
  137. .base-item {
  138. width: 110px;
  139. height: 100%;
  140. font-size: 12px;
  141. text-align: center;
  142. box-sizing: border-box;
  143. color: #f3c11d;
  144. display: flex;
  145. flex-direction: column;
  146. align-items: center;
  147. margin: 0 12px;
  148. background: url("@/assets/images/home/scale-bg.png") no-repeat center center / 100% 100%;
  149. .label {
  150. width: 85px;
  151. height: 16px;
  152. line-height: 16px;
  153. color: #fff;
  154. background: url("@/assets/images/home/label-bg.png") no-repeat center center / 100% 100%;
  155. }
  156. .value {
  157. font-size: 18px;
  158. font-family: "PangMenZhengDao";
  159. span {
  160. font-size: 12px;
  161. }
  162. }
  163. }
  164. }
  165. .box-bg {
  166. margin-top: 8px;
  167. border-radius: 2px 2px 0 0;
  168. font-size: 12px;
  169. padding: 3px 6px;
  170. box-sizing: border-box;
  171. font-family: Arial, Helvetica, sans-serif;
  172. overflow-y: auto;
  173. background: linear-gradient(180deg, rgb(85, 85, 85, 0.4) 0%, rgb(35, 35, 35, 1) 100%);
  174. .text {
  175. position: relative;
  176. span {
  177. color: rgba(255, 255, 255, 0.4);
  178. line-height: 1.7;
  179. }
  180. }
  181. }
  182. }
  183. }
  184. </style>