| | |
| | | <el-table-column label="最后采集时间" width="180" align="center"> |
| | | <template #default="{ row: metric }">{{ formatDateTime(metric.lastCollectTime) }}</template> |
| | | </el-table-column> |
| | | <el-table-column label="操作" width="140" align="center"> |
| | | <el-table-column label="操作" width="200" align="center"> |
| | | <template #default="{ row: metric }"> |
| | | <el-button link type="primary" @click="openReportDialog(row, metric)">上报数据</el-button> |
| | | <el-button link type="primary" @click="openTrendDialog(row, metric)">趋势</el-button> |
| | | </template> |
| | | </el-table-column> |
| | | </el-table> |
| | |
| | | <el-button type="primary" :loading="reportLoading" @click="submitReportData">上报</el-button> |
| | | </template> |
| | | </el-dialog> |
| | | |
| | | <!-- ==================== 监测趋势 ==================== --> |
| | | <el-dialog v-model="trendDialog" title="监测趋势" width="880px"> |
| | | <div class="trend-header"> |
| | | <span class="trend-device">{{ trendForm.deviceName }} · {{ trendForm.metricName }}</span> |
| | | <el-radio-group v-model="trendRange" size="small" @change="loadTrend"> |
| | | <el-radio-button value="1">近1天</el-radio-button> |
| | | <el-radio-button value="7">近7天</el-radio-button> |
| | | <el-radio-button value="30">近30天</el-radio-button> |
| | | </el-radio-group> |
| | | </div> |
| | | <div v-if="trendData.length" style="width: 100%"> |
| | | <Echarts |
| | | :chartStyle="trendChartStyle" |
| | | :grid="trendGrid" |
| | | :xAxis="trendXAxis" |
| | | :yAxis="trendYAxis" |
| | | :series="trendSeries" |
| | | :tooltip="trendTooltip" |
| | | style="height: 340px" |
| | | /> |
| | | </div> |
| | | <el-empty v-else description="该时间段暂无采集数据,可在上方指标里先上报一条再看趋势" /> |
| | | <template #footer> |
| | | <el-button @click="trendDialog = false">关闭</el-button> |
| | | </template> |
| | | </el-dialog> |
| | | </div> |
| | | </template> |
| | | |
| | | <script setup> |
| | | import { onMounted, onUnmounted, reactive, ref } from "vue"; |
| | | import { ElMessageBox, ElNotification } from "element-plus"; |
| | | import Echarts from "@/components/Echarts/echarts.vue"; |
| | | import { |
| | | addMonitorDevice, |
| | | addMonitorMetric, |
| | |
| | | handleMonitorAlarm, |
| | | listMonitorAlarm, |
| | | listMonitorControl, |
| | | listMonitorDataHistory, |
| | | listMonitorDevice, |
| | | listMonitorMetric, |
| | | reportMonitorData, |
| | |
| | | return metric.thresholdMax !== null && metric.thresholdMax !== undefined && value > Number(metric.thresholdMax); |
| | | }; |
| | | const metricAlarmClass = (metric) => (isMetricAlarm(metric) ? "danger-text" : ""); |
| | | |
| | | // ==================== 监测趋势 ==================== |
| | | const trendDialog = ref(false); |
| | | const trendRange = ref("1"); |
| | | const trendData = ref([]); |
| | | const trendForm = reactive({ deviceId: null, deviceName: "", metricCode: "", metricName: "", unit: "" }); |
| | | const trendChartStyle = { width: "100%", height: "100%" }; |
| | | const trendGrid = { left: "3%", right: "4%", bottom: "10%", top: "12%", containLabel: true }; |
| | | const trendTooltip = { trigger: "axis" }; |
| | | const trendXAxis = ref([{ type: "category", data: [], axisLabel: { rotate: 20 } }]); |
| | | const trendYAxis = ref([{ type: "value", scale: true }]); |
| | | const trendSeries = ref([]); |
| | | |
| | | const toDateTimeStr = (d) => { |
| | | const pad = (n) => String(n).padStart(2, "0"); |
| | | return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`; |
| | | }; |
| | | |
| | | const openTrendDialog = (device, metric) => { |
| | | trendForm.deviceId = device.id; |
| | | trendForm.deviceName = device.deviceName; |
| | | trendForm.metricCode = metric.metricCode; |
| | | trendForm.metricName = metric.metricName; |
| | | trendForm.unit = metric.unit || ""; |
| | | trendRange.value = "1"; |
| | | trendDialog.value = true; |
| | | loadTrend(); |
| | | }; |
| | | |
| | | const loadTrend = () => { |
| | | const days = Number(trendRange.value || 1); |
| | | const end = new Date(); |
| | | const start = new Date(end.getTime() - days * 24 * 3600 * 1000); |
| | | listMonitorDataHistory({ |
| | | deviceId: trendForm.deviceId, |
| | | metricCode: trendForm.metricCode, |
| | | startTime: toDateTimeStr(start), |
| | | endTime: toDateTimeStr(end), |
| | | }).then((res) => { |
| | | const list = res.data || []; |
| | | trendData.value = list; |
| | | trendXAxis.value[0].data = list.map((item) => formatDateTime(item.collectTime).substring(5, 16)); |
| | | trendSeries.value = [ |
| | | { |
| | | name: trendForm.metricName + (trendForm.unit ? `(${trendForm.unit})` : ""), |
| | | type: "line", |
| | | smooth: true, |
| | | symbol: "circle", |
| | | symbolSize: 6, |
| | | data: list.map((item) => Number(item.metricValue)), |
| | | itemStyle: { color: "#409EFF" }, |
| | | areaStyle: { opacity: 0.12 }, |
| | | }, |
| | | ]; |
| | | }); |
| | | }; |
| | | |
| | | // ==================== 数据上报 ==================== |
| | | const reportDialog = ref(false); |
| | |
| | | .metric-actions { |
| | | margin-bottom: 10px; |
| | | } |
| | | .trend-header { |
| | | display: flex; |
| | | align-items: center; |
| | | justify-content: space-between; |
| | | margin-bottom: 12px; |
| | | .trend-device { |
| | | font-weight: 600; |
| | | color: #303133; |
| | | } |
| | | } |
| | | } |
| | | </style> |