feat(无人值守): 远程监控增加监测趋势曲线、巡检路径支持调整巡检顺序
已修改3个文件
178 ■■■■■ 文件已修改
src/api/environmentAccess/deviceMonitor.js 4 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/environmentAccess/deviceMonitor/index.vue 98 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/environmentAccess/intelligentInspectionManagement/index.vue 76 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/api/environmentAccess/deviceMonitor.js
@@ -38,6 +38,10 @@
export function reportMonitorData(params) {
  return request({ url: "/environmentAccess/monitorDataReport", method: "post", params });
}
// 监测历史数据(趋势曲线)
export function listMonitorDataHistory(params) {
  return request({ url: "/environmentAccess/monitorDataHistory", method: "get", params });
}
// ==================== 报警 ====================
export function listMonitorAlarm(query) {
src/views/environmentAccess/deviceMonitor/index.vue
@@ -90,9 +90,10 @@
                  <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>
@@ -424,12 +425,40 @@
        <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,
@@ -440,6 +469,7 @@
  handleMonitorAlarm,
  listMonitorAlarm,
  listMonitorControl,
  listMonitorDataHistory,
  listMonitorDevice,
  listMonitorMetric,
  reportMonitorData,
@@ -606,6 +636,62 @@
  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);
@@ -804,5 +890,15 @@
  .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>
src/views/environmentAccess/intelligentInspectionManagement/index.vue
@@ -266,17 +266,23 @@
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="巡检点位(按选择顺序依次巡检):">
        <el-form-item label="巡检点位(按序号依次巡检,可上下调整顺序):">
          <el-select v-model="routePointIds" multiple filterable style="width: 100%"
                     placeholder="请选择巡检点位">
            <el-option v-for="item in allPointList" :key="item.id"
                       :label="`${item.pointName}(${item.areaName || '未分区'})`" :value="item.id" />
          </el-select>
          <div class="point-order">
            <span class="label">巡检顺序:</span>
            <el-tag v-for="(name, index) in selectedPointNames" :key="index" size="small" style="margin-right: 6px">
              {{ index + 1 }}. {{ name }}
            </el-tag>
          <div class="point-order-editor">
            <div v-for="(name, index) in selectedPointNames" :key="index" class="order-item">
              <span class="seq">{{ index + 1 }}</span>
              <span class="name">{{ name }}</span>
              <span class="ops">
                <el-button link type="primary" :disabled="index === 0" @click="movePoint(index, -1)">上移</el-button>
                <el-button link type="primary" :disabled="index === routePointIds.length - 1"
                           @click="movePoint(index, 1)">下移</el-button>
                <el-button link type="danger" @click="removePointAt(index)">移除</el-button>
              </span>
            </div>
            <span v-if="selectedPointNames.length === 0" class="sub-text">尚未选择点位</span>
          </div>
        </el-form-item>
@@ -602,6 +608,26 @@
  });
});
/** 调整巡检顺序:direction = -1 上移 / 1 下移 */
const movePoint = (index, direction) => {
  const list = [...routePointIds.value];
  const target = index + direction;
  if (target < 0 || target >= list.length) {
    return;
  }
  const tmp = list[index];
  list[index] = list[target];
  list[target] = tmp;
  routePointIds.value = list;
};
/** 从巡检顺序中移除某个点位 */
const removePointAt = (index) => {
  const list = [...routePointIds.value];
  list.splice(index, 1);
  routePointIds.value = list;
};
const loadRoute = () => {
  routeLoading.value = true;
  listInspectionRoute({ ...routeQuery, current: 1, size: 500 })
@@ -845,16 +871,36 @@
    color: #909399;
    font-size: 13px;
  }
  .point-order {
  .point-order-editor {
    margin-top: 8px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
    .label {
      color: #606266;
      font-size: 13px;
      margin-right: 4px;
    .order-item {
      display: flex;
      align-items: center;
      gap: 10px;
      padding: 4px 8px;
      border: 1px solid #ebeef5;
      border-radius: 4px;
      margin-bottom: 6px;
      background: #fafafa;
      .seq {
        width: 22px;
        height: 22px;
        line-height: 22px;
        text-align: center;
        border-radius: 50%;
        background: #409eff;
        color: #fff;
        font-size: 12px;
        flex: 0 0 auto;
      }
      .name {
        flex: 1;
        color: #303133;
        font-size: 13px;
      }
      .ops {
        flex: 0 0 auto;
      }
    }
  }
  .record-summary {