DeviceStatus.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <div class="screen-common-component">
  3. <ScreenComHeader :module-id="moduleId" title="设备状态" />
  4. <div class="charts-container">
  5. <div
  6. v-for="(item, index) in data"
  7. :key="index"
  8. class="device-status-desc"
  9. >
  10. <el-row>
  11. <div :style="{ backgroundColor: colors[index] }" class="icon"></div>
  12. <div :style="{ color: colors[index] }" class="type">
  13. {{ item.type }}
  14. </div>
  15. </el-row>
  16. <el-row>
  17. <div :style="{ color: colors[index] }" class="count">
  18. {{ item.count }}台
  19. </div>
  20. <!-- <div :style="{ color: colors[index] }" class="count">-->
  21. <!-- {{ item.count }}%-->
  22. <!-- </div>-->
  23. </el-row>
  24. </div>
  25. <div ref="chartRef" style="width: 100%; height: 600px"></div>
  26. </div>
  27. </div>
  28. </template>
  29. <script lang="ts" setup>
  30. import ScreenComHeader from "@/views/screens/configs/screenComHeader.vue";
  31. import * as echarts from "echarts";
  32. const bigScreenData: any = inject("bigScreenData");
  33. const chartRef = ref(null);
  34. const props = defineProps({
  35. moduleId: {
  36. type: String,
  37. required: true,
  38. },
  39. deviceData: {
  40. type: Object || null,
  41. default: null,
  42. required: true,
  43. },
  44. });
  45. const data = ref<any[]>([]);
  46. const colors = ["#4caf50", "#ffc107", "#b61945", "#607d8b"];
  47. let chart: any = null;
  48. watchEffect(() => {
  49. if (!props.deviceData) {
  50. return;
  51. }
  52. data.value = [
  53. {
  54. type: "运行",
  55. count: props.deviceData.runNum,
  56. percent: 20,
  57. },
  58. {
  59. type: "离线",
  60. count: props.deviceData.offLineNum,
  61. percent: 0,
  62. },
  63. {
  64. type: "故障",
  65. count: props.deviceData.faultNum,
  66. percent: 5,
  67. },
  68. {
  69. type: "维修",
  70. count: props.deviceData.repairNum,
  71. percent: 10,
  72. },
  73. ];
  74. const option = {
  75. color: colors,
  76. backgroundColor: "transparent",
  77. tooltip: {
  78. trigger: "item",
  79. textStyle: {
  80. fontSize: bigScreenData.value.fontSize * 2,
  81. },
  82. },
  83. legend: {
  84. bottom: "5%",
  85. left: "center",
  86. },
  87. textStyle: {
  88. fontSize: bigScreenData.value.fontSize * 2,
  89. },
  90. series: [
  91. {
  92. name: "设备状态",
  93. type: "pie",
  94. radius: ["40%", "70%"],
  95. avoidLabelOverlap: false,
  96. padAngle: 5,
  97. itemStyle: {
  98. borderRadius: 10,
  99. },
  100. labelLine: {
  101. show: false,
  102. },
  103. label: {
  104. show: false,
  105. position: "inside",
  106. },
  107. data: [
  108. { value: props.deviceData.runNum, name: "运行" },
  109. { value: props.deviceData.offLineNum, name: "离线" },
  110. { value: props.deviceData.faultNum, name: "故障" },
  111. { value: props.deviceData.repairNum, name: "维修" },
  112. ],
  113. },
  114. ],
  115. };
  116. chart.setOption(option);
  117. });
  118. onMounted(async () => {
  119. chart = echarts.init(chartRef.value, "dark");
  120. });
  121. </script>
  122. <style lang="scss" scoped>
  123. .device-status-desc {
  124. display: flex;
  125. justify-content: space-between;
  126. align-items: center;
  127. padding: 5px 20px;
  128. margin-bottom: 10px;
  129. s .icon {
  130. width: 20px;
  131. height: 20px;
  132. border-radius: 10px;
  133. margin-right: 10px;
  134. background-color: #ff7373;
  135. }
  136. .type {
  137. font-size: 2.2vh;
  138. font-weight: bold;
  139. color: #333;
  140. line-height: 1.5;
  141. }
  142. .count {
  143. font-size: 2.2vh;
  144. color: #666;
  145. line-height: 1.5;
  146. margin-left: 10px;
  147. }
  148. }
  149. </style>