Commit c3807a12 authored by Cai Wei's avatar Cai Wei

feat(*): 布袋监测连调

parent f61d456b
......@@ -132,6 +132,7 @@ export const getBagMonitoringChartOption = (xData = [], seriesData = []) => ({
top: "3%",
containLabel: true,
},
// x轴的文字去除年月日
xAxis: {
type: "category",
boundaryGap: false,
......@@ -145,6 +146,9 @@ export const getBagMonitoringChartOption = (xData = [], seriesData = []) => ({
fontSize: 12,
interval: "auto",
rotate: 0,
formatter: function (value) {
return value.split(' ')[1];
}
},
axisTick: {
show: false,
......
......@@ -4,37 +4,59 @@
<div class="select-container">
<span>检测仪器</span>
<el-select v-model="selectedDevice" placeholder="1#布袋检测仪">
<el-option v-for="item in deviceList" :key="item.deviceNo" :label="item.deviceName" :value="item.deviceNo"></el-option>
<el-option
v-for="item in deviceList"
:key="item.deviceNo"
:label="item.deviceName"
:value="item.deviceNo"
></el-option>
</el-select>
</div>
<div class="title">BME布袋监测</div>
</div>
<div class="chart-container">
<div class="chart-wrapper" ref="chartRef" v-if="chartData.xData.length > 0"></div>
<div class="chart-wrapper" v-else>
<div class="chart-wrapper" ref="chartRef"></div>
<div class="chart-wrapper no-data" v-if="chartData.xData.length === 0">
<div class="no-data-text">暂无数据</div>
</div>
</div>
<div class="data-panel" :class="{ 'collapsed': !isPanelOpen }">
<div class="panel-toggle" :class="{ 'collapsed-icon': !isPanelOpen, 'expanded-icon': isPanelOpen }" @click="togglePanel">
<div class="data-panel" :class="{ collapsed: !isPanelOpen }">
<div
class="panel-toggle"
:class="{
'collapsed-icon': !isPanelOpen,
'expanded-icon': isPanelOpen,
}"
@click="togglePanel"
>
<el-icon v-if="isPanelOpen"><ArrowRightBold /></el-icon>
<el-icon v-if="!isPanelOpen"><ArrowLeftBold /></el-icon>
</div>
<div class="data-box">
<div class="data-item">
<div>时间: {{ currentData.time || '-' }}</div>
<div>仓室: {{ currentData.compartName }}</div>
<div>时间: {{ currentData.time }}</div>
<div>仓室: {{ currentData.compartNo }}</div>
<div>反吹: {{ currentData.blowBack }}</div>
</div>
<div class="data-item">
<div>DI3: {{ currentData.di3 }}</div>
<div>排: {{ currentData.row }}</div>
<div>实时值: {{ currentData.realData }}</div>
</div>
<div class="data-item">
<div>基线值: {{ currentData.baseline }}</div>
<div>Delay: {{ currentData.delay }}</div>
<div>totaltime: {{ currentData.totalTime }}</div>
</div>
<div class="data-item">
<div>next:{{ currentData.next }}</div>
<div>valve:{{ currentData.valveNo }}</div>
<div>DI_TIME={{ currentData.diTime }}</div>
</div>
<div class="data-item">
<!-- <div>峰值R: {{ currentData.peakValueR }}</div>
<div>峰值H: {{ currentData.peakValueH }}</div> -->
<div>peak={{ currentData.peak }}</div>
</div>
</div>
......@@ -43,10 +65,8 @@
<div>时间:{{ secondaryData.time }}, 仓室: {{ secondaryData.chamber }}, 反吹: {{ secondaryData.backwash }}, 谷值: {{ secondaryData.valleyValue }}, 仓室状态阀门{{ secondaryData.status }}False{{ secondaryData.falseVal }}</div>
</div> -->
</div>
</div>
<div class="data-table">
<div class="time-controls">
<el-button @click="navigateBackward">
<el-icon><ArrowLeftBold />向前</el-icon>
......@@ -65,174 +85,204 @@
<thead>
<tr>
<th>名称</th>
<th v-for="(value, index) in tableData" :key="index">{{ value.compartName }}</th>
<th v-for="(value, index) in tableData" :key="index">
{{ value.compartName }}
</th>
</tr>
</thead>
<tbody>
<tr>
<td>峰值_R</td>
<td v-for="(value, index) in tableData" :key="'r'+index">{{ value.peakValueR || '-' }}</td>
<td v-for="(value, index) in tableData" :key="'r' + index">
{{ value.peakValueR || "-" }}
</td>
</tr>
<tr>
<td>峰值_H</td>
<td v-for="(value, index) in tableData" :key="'h'+index">{{ value.peakValueH || '-' }}</td>
<td v-for="(value, index) in tableData" :key="'h' + index">
{{ value.peakValueH || "-" }}
</td>
</tr>
<tr>
<td>状态</td>
<td v-for="(value, index) in tableData" :key="'s'+index" :class="{ 'error': value.status === 1 }">{{ value.status === 1 ? '故障' : '正常' }}</td>
<td
v-for="(value, index) in tableData"
:key="'s' + index"
:class="{ error: value.status === 1 }"
>
{{ value.status === 1 ? "故障" : "正常" }}
</td>
</tr>
<tr>
<td>反吹中</td>
<td v-for="(value, index) in tableData" :key="'b'+index">{{ value.blowBack || '-' }}</td>
<td v-for="(value, index) in tableData" :key="'b' + index">
{{ value.blowBack || "-" }}
</td>
</tr>
<tr>
<td>谷值</td>
<td v-for="(value, index) in tableData" :key="'v'+index">{{ value.valleyValue || '-' }}</td>
<td v-for="(value, index) in tableData" :key="'v' + index">
{{ value.valleyValue || "-" }}
</td>
</tr>
</tbody>
</table>
</div>
</div>
</template>
<script setup>
import { ref, reactive, onMounted, onBeforeUnmount, watch } from 'vue'
import * as echarts from 'echarts'
import moment from 'moment'
import { ArrowRightBold, ArrowLeftBold } from '@element-plus/icons-vue'
import { getBagMonitoringChartOption } from '@/utils/chart.js'
import { getMonitorToday, getMonitorList, getMonitorRealtime } from '@/request/api/bagMonitor'
import { useRoute } from 'vue-router'
import { ref, reactive, onMounted, onBeforeUnmount, watch } from "vue";
import * as echarts from "echarts";
import moment from "moment";
import { ArrowRightBold, ArrowLeftBold } from "@element-plus/icons-vue";
import { getBagMonitoringChartOption } from "@/utils/chart.js";
import {
getMonitorToday,
getMonitorList,
getMonitorRealtime,
} from "@/request/api/bagMonitor";
import { useRoute } from "vue-router";
// 获取路由参数
const route = useRoute()
const route = useRoute();
// 设备选择
const selectedDevice = ref(null)
const selectedDevice = ref(null);
const isPanelOpen = ref(true)
const isPanelOpen = ref(true);
// 图表相关
const chartRef = ref(null)
let chartInstance = null
let updateTimer = null // 定时器引用
const chartRef = ref(null);
let chartInstance = null;
let updateTimer = null; // 定时器引用
let lastTimePoint = null
let lastTimePoint = null;
// 控制是否获取实时设备状态数据
let showRealtimeDeviceStatus = true
let showRealtimeDeviceStatus = true;
// 从路由参数获取dusterNo
const dusterNo = ref(route.params.dusterNo || route.query.dusterNo || 'ZH-ZL-1GL-001') // 默认值作为fallback
const dusterNo = ref(
route.params.dusterNo || route.query.dusterNo || "ZH-ZL-1GL-001"
); // 默认值作为fallback
// 图表数据
const chartData = reactive({
xData: [],
seriesData: []
})
seriesData: [],
});
const deviceList = ref([]);
const currentTime = ref(null);
// 当前数据面板
const currentData = ref({
"date": "",
"realData": "",
"valveNo": "",
"baseline": "",
"peak": "",
"time": "",
"compartName": "",
"blowBack": "",
"row": ""
})
realtime: "",
time: "",
compartNo: "",
blowBack: "",
di3: "",
row: "",
realData: "",
baseline: "",
delay: "",
totalTime: "",
next: "",
valveNo: "",
diTime: "",
peak: "",
});
// 表格数据
const tableData = ref([{
compartName: '默认',
const tableData = ref([
{
compartName: "默认",
peakValueR: 0,
peakValueH: 0,
status: 0,
blowBack: 0,
valleyValue: 0
}]);
valleyValue: 0,
},
]);
// 时间控制
const timeInterval = ref('10')
const timeInterval = ref("10");
const togglePanel = () => {
isPanelOpen.value = !isPanelOpen.value
}
isPanelOpen.value = !isPanelOpen.value;
};
// 初始化图表
const initChart = () => {
if (chartInstance) {
chartInstance.dispose()
chartInstance.dispose();
}
// 初始化图表数据
initChartData()
}
initChartData();
};
// 初始化图表数据
const initChartData = () => {
if (!dusterNo.value || !selectedDevice.value) {
console.warn('缺少dusterNo或deviceNo,无法获取数据')
return
console.warn("缺少dusterNo或deviceNo,无法获取数据");
return;
}
// 获取昨天这个之前的数据
const startTime = moment().subtract(1, 'days').subtract(5, 'minutes').format('YYYY-MM-DD HH:mm:ss')
const endTime = moment().subtract(1, 'days').format('YYYY-MM-DD HH:mm:ss')
chartData.xData = []
chartData.seriesData = []
const startTime = moment()
.subtract(5, "minutes")
.format("YYYY-MM-DD HH:mm:ss");
const endTime = moment().format("YYYY-MM-DD HH:mm:ss");
chartData.xData = [];
chartData.seriesData = [];
getMonitorToday({
dusterNo: dusterNo.value,
deviceNo: selectedDevice.value,
startTime: startTime,
endTime: endTime
}).then(res => {
endTime: endTime,
})
.then((res) => {
// 将data中的date和realData数据添加到chartData中,要求大数据量下速度快
if (res.data && res.data.length > 0) {
res.data.forEach((item) => {
chartData.xData.push(item.date)
chartData.seriesData.push(item.realData)
})
chartData.xData.push(item.date);
chartData.seriesData.push(item.realData);
});
// 当前时间
currentTime.value = res.data[res.data.length-1].date
chartInstance = echarts.init(chartRef.value)
currentTime.value = res.data[res.data.length - 1].date;
chartInstance = echarts.init(chartRef.value);
// 启动定时更新
startRealTimeUpdates()
startRealTimeUpdates();
} else {
console.warn('未获取到初始数据')
console.warn("未获取到初始数据");
}
}).catch(err => {
console.error('获取初始数据失败:', err)
})
}
.catch((err) => {
console.error("获取初始数据失败:", err);
});
};
// 更新图表
const updateChart = () => {
if (chartInstance) {
chartInstance.setOption(getBagMonitoringChartOption(chartData.xData, chartData.seriesData))
chartInstance.setOption(
getBagMonitoringChartOption(chartData.xData, chartData.seriesData)
);
}
}
};
// 启动实时更新
const startRealTimeUpdates = () => {
if (updateTimer) {
clearInterval(updateTimer)
clearInterval(updateTimer);
}
updateTimer = setInterval(() => {
updateFunction()
}, 1000)
updateFunction();
}, 1000);
isRealTimeMode = true
showRealtimeDeviceStatus = true
}
showRealtimeDeviceStatus = true;
};
// 更新函数
const updateFunction = () => {
......@@ -242,238 +292,244 @@ const updateFunction = () => {
if (showRealtimeDeviceStatus) {
getMonitorRealtime({
dusterNo: dusterNo.value,
deviceNo: selectedDevice.value
}).then(res => {
deviceNo: selectedDevice.value,
})
.then((res) => {
if (res.data) {
// 更新数据面板
if (res.data.realtimeCompart) {
tableData.value = res.data.realtimeCompart
tableData.value = res.data.realtimeCompart;
}
if (res.data.realtimeCurve) {
currentData.value = res.data.realtimeCurve
if (res.data.realtimePanel) {
currentData.value = res.data.realtimePanel;
}
}
}).catch(err => {
console.error('获取实时数据失败:', err)
})
.catch((err) => {
console.error("获取实时数据失败:", err);
});
}
// 结束时间往后推一秒
let endTime = moment(new Date(currentTime.value)).add(1, 'seconds').format('YYYY-MM-DD HH:mm:ss')
let endTime = moment(new Date(currentTime.value))
.add(1, "seconds")
.format("YYYY-MM-DD HH:mm:ss");
getMonitorToday({
dusterNo: dusterNo.value,
deviceNo: selectedDevice.value,
startTime: currentTime.value,
endTime: endTime
}).then(res => {
endTime: endTime,
}).then((res) => {
if (res.data && res.data.length > 0) {
const item = res.data[res.data.length-1]
chartData.xData.push(item.date)
chartData.seriesData.push(item.realData || 0)
const item = res.data[res.data.length - 1];
chartData.xData.push(item.date);
chartData.seriesData.push(item.realData || 0);
// 移除最旧的数据点以保持固定长度
if (chartData.xData.length > 301) { // 保持300秒的数据
chartData.xData.shift()
chartData.seriesData.shift()
if (chartData.xData.length > 301) {
// 保持300秒的数据
chartData.xData.shift();
chartData.seriesData.shift();
}
currentTime.value = endTime;
// 更新图表
updateChart()
updateChart();
}
})
}
});
};
// 停止实时更新
const stopRealTimeUpdates = () => {
if (updateTimer) {
clearInterval(updateTimer)
updateTimer = null
clearInterval(updateTimer);
updateTimer = null;
}
isRealTimeMode = false
showRealtimeDeviceStatus = false
}
showRealtimeDeviceStatus = false;
};
// 向前导航(查看更早的数据)
const navigateBackward = () => {
// 不完全关闭轮询,只禁用实时设备状态获取
showRealtimeDeviceStatus = false
showRealtimeDeviceStatus = false;
// 获取时间间隔(分钟)
const interval = parseInt(timeInterval.value) || 10
const intervalMs = interval * 60 * 1000
const interval = parseInt(timeInterval.value) || 10;
const intervalMs = interval * 60 * 1000;
// 如果是第一次点击,以当前最后一条数据的时间为参考
if (lastTimePoint === null && chartData.xData.length > 0) {
const lastTimeString = chartData.xData[chartData.xData.length - 1]
lastTimePoint = new Date(lastTimeString)
const lastTimeString = chartData.xData[chartData.xData.length - 1];
lastTimePoint = new Date(lastTimeString);
} else if (lastTimePoint === null) {
// 如果没有数据,使用当前时间
lastTimePoint = new Date()
lastTimePoint = new Date();
}
// 计算新的时间范围
const endTime = new Date(lastTimePoint.getTime() - intervalMs)
lastTimePoint = endTime
const endTime = new Date(lastTimePoint.getTime() - intervalMs);
lastTimePoint = endTime;
// 重新生成数据
generateHistoricalData(endTime, interval)
}
generateHistoricalData(endTime, interval);
};
// 向后导航(查看更近的数据)
const navigateForward = () => {
// 不完全关闭轮询,只禁用实时设备状态获取
showRealtimeDeviceStatus = false
showRealtimeDeviceStatus = false;
// 获取时间间隔(分钟)
const interval = parseInt(timeInterval.value) || 10
const intervalMs = interval * 60 * 1000
const interval = parseInt(timeInterval.value) || 10;
const intervalMs = interval * 60 * 1000;
// 如果是第一次点击,以当前最后一条数据的时间为参考
if (lastTimePoint === null && chartData.xData.length > 0) {
const lastTimeString = chartData.xData[chartData.xData.length - 1]
lastTimePoint = new Date(lastTimeString)
const lastTimeString = chartData.xData[chartData.xData.length - 1];
lastTimePoint = new Date(lastTimeString);
} else if (lastTimePoint === null) {
// 如果没有数据,使用当前时间
lastTimePoint = new Date()
lastTimePoint = new Date();
}
// 计算新的时间范围
const endTime = new Date(lastTimePoint.getTime() + intervalMs)
const endTime = new Date(lastTimePoint.getTime() + intervalMs);
// 如果新的结束时间超过当前时间,则切换回实时模式
const now = moment()
const now = moment();
if (endTime > now) {
lastTimePoint = null
showRealtimeDeviceStatus = true
return
lastTimePoint = null;
showRealtimeDeviceStatus = true;
return;
}
lastTimePoint = endTime
lastTimePoint = endTime;
// 重新生成数据
generateHistoricalData(endTime, interval)
}
generateHistoricalData(endTime, interval);
};
const reset = () => {
// 清空现有数据
chartData.xData = []
chartData.seriesData = []
lastTimePoint = null
chartData.xData = [];
chartData.seriesData = [];
lastTimePoint = null;
// 恢复实时设备状态获取
showRealtimeDeviceStatus = true
showRealtimeDeviceStatus = true;
// 重新生成当前时间往前300秒的数据
const now = new Date()
const now = new Date();
generateHistoricalData(now, 5)
generateHistoricalData(now, 5);
// 开启实时更新
startRealTimeUpdate()
}
startRealTimeUpdate();
};
// 开启实时更新(重置用)
const startRealTimeUpdate = () => {
// 确保之前的定时器已清除
stopRealTimeUpdates()
// 初始化实时模式标志
isRealTimeMode = true
stopRealTimeUpdates();
// 启动定时更新
updateTimer = setInterval(() => {
updateFunction()
}, 1000)
}
updateFunction();
}, 1000);
};
// 生成历史数据
const generateHistoricalData = (endTime, intervalMinutes) => {
if (!dusterNo.value || !selectedDevice.value) return;
// 清空现有数据
chartData.xData = []
chartData.seriesData = []
const startTime = new Date(endTime.getTime() - intervalMinutes * 60 * 1000)
const startTimeStr = moment(startTime).format('YYYY-MM-DD HH:mm:ss')
const endTimeStr = moment(endTime).format('YYYY-MM-DD HH:mm:ss')
chartData.xData = [];
chartData.seriesData = [];
const startTime = new Date(endTime.getTime() - intervalMinutes * 60 * 1000);
const startTimeStr = moment(startTime).format("YYYY-MM-DD HH:mm:ss");
const endTimeStr = moment(endTime).format("YYYY-MM-DD HH:mm:ss");
// 从API获取历史数据
getMonitorToday({
dusterNo: dusterNo.value,
deviceNo: selectedDevice.value,
startTime: startTimeStr,
endTime: endTimeStr
}).then(res => {
if (res.data && res.data.length > 0) {
res.data.forEach(item => {
chartData.xData.push(item.date)
chartData.seriesData.push(item.realData)
endTime: endTimeStr,
})
.then((res) => {
if (res.data && res.data.length > 0) {
res.data.forEach((item) => {
chartData.xData.push(item.date);
chartData.seriesData.push(item.realData);
});
// 更新图表
updateChart()
updateChart();
}
}).catch(err => {
console.error('获取历史数据失败:', err)
})
}
.catch((err) => {
console.error("获取历史数据失败:", err);
});
};
// 监听窗口大小变化,调整图表大小
const handleResize = () => {
if (chartInstance) {
chartInstance.resize()
chartInstance.resize();
}
}
};
const getDeviceList = () => {
if (!dusterNo.value) return;
getMonitorList({
dusterNo: dusterNo.value
}).then(res => {
dusterNo: dusterNo.value,
}).then((res) => {
deviceList.value = res.data.devices || [];
if (deviceList.value.length > 0) {
selectedDevice.value = deviceList.value[0].deviceNo
tableData.value = Array.from({ length: res.data.compartCount }, (item, index) => ({
compartName: `${index+1}仓`,
selectedDevice.value = deviceList.value[0].deviceNo;
tableData.value = Array.from(
{ length: res.data.compartCount },
(item, index) => ({
compartName: `${index + 1}仓`,
peakValueR: 0,
peakValueH: 0,
status: 0,
blowBack: 0,
}))
}
initChart()
})
}
);
}
initChart();
});
};
// 监听dusterNo变化
watch(dusterNo, (newVal) => {
if (newVal) {
// 重新获取设备列表
getDeviceList()
getDeviceList();
}
})
});
onMounted(() => {
console.log("dusterNo", route);
if (dusterNo.value) {
getDeviceList()
getDeviceList();
}
window.addEventListener('resize', handleResize)
})
window.addEventListener("resize", handleResize);
});
onBeforeUnmount(() => {
window.removeEventListener('resize', handleResize)
window.removeEventListener("resize", handleResize);
// 清除定时器
if (updateTimer) {
clearInterval(updateTimer)
updateTimer = null
clearInterval(updateTimer);
updateTimer = null;
}
// 销毁图表实例
if (chartInstance) {
chartInstance.dispose()
chartInstance = null
chartInstance.dispose();
chartInstance = null;
}
})
});
</script>
<style scoped lang="scss">
......@@ -481,7 +537,8 @@ onBeforeUnmount(() => {
width: 100%;
height: calc(100% - 14px);
box-sizing: border-box;
overflow-x: hidden;
// overflow-x: hidden;
position: relative;
.header {
position: relative;
......@@ -516,7 +573,7 @@ onBeforeUnmount(() => {
.title {
font-size: 18px;
font-weight: bold;
color: #409EFF;
color: #409eff;
}
}
......@@ -527,6 +584,7 @@ onBeforeUnmount(() => {
border-radius: 4px;
display: flex;
flex-direction: column;
position: relative;
.chart-wrapper {
flex: 1;
......@@ -543,13 +601,22 @@ onBeforeUnmount(() => {
border-radius: 4px;
}
}
.no-data {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 10;
}
}
.data-panel {
position: absolute;
top: 110px;
right: 25px;
top: 0px;
right: 0px;
width: 320px;
z-index: 10;
z-index: 100;
transition: transform 0.3s ease-in-out;
&.collapsed {
......@@ -600,7 +667,6 @@ onBeforeUnmount(() => {
font-size: 12px;
}
}
}
.data-table {
background-color: #fff;
......@@ -612,24 +678,25 @@ onBeforeUnmount(() => {
width: 100%;
border-collapse: collapse;
th, td {
border: 1px solid #EBEEF5;
th,
td {
border: 1px solid #ebeef5;
text-align: center;
padding: 8px;
font-size: 14px;
}
th {
background-color: #F5F7FA;
background-color: #f5f7fa;
color: #606266;
}
.error {
color: #F56C6C;
color: #f56c6c;
}
.highlight {
background-color: #FCF8E3;
background-color: #fcf8e3;
position: relative;
&::after {
......@@ -637,7 +704,7 @@ onBeforeUnmount(() => {
position: absolute;
width: 16px;
height: 16px;
background-color: #E6A23C;
background-color: #e6a23c;
border-radius: 50%;
top: 50%;
left: 50%;
......@@ -653,7 +720,8 @@ onBeforeUnmount(() => {
align-items: center;
justify-content: flex-end;
.time-label, .time-unit {
.time-label,
.time-unit {
margin: 0 5px;
}
......@@ -664,4 +732,3 @@ onBeforeUnmount(() => {
}
}
</style>
\ No newline at end of file
......@@ -74,6 +74,7 @@
class="point warn"
v-for="item in detailObj.compartHealthList[0]"
:key="item"
@click="handleStatusDotClick()"
></div>
</div>
<div class="part">
......@@ -117,6 +118,7 @@
</template>
<script setup>
import { ref, reactive, onMounted, onUnmounted, watch, computed } from "vue";
import { useRouter } from "vue-router";
import * as echarts from "echarts";
import { getDataFun } from "@/request/method.js";
import { useUsersStore } from "@/pinia/user.js";
......@@ -148,6 +150,7 @@ const option = {
},
],
};
const router = useRouter();
const chartInstance = reactive({});
const chartData = reactive([{}, {}, {}]);
const initChart = (instance, option, domEl) => {
......@@ -546,6 +549,14 @@ const dusterName = computed(() => {
return dusterList.value.find((item) => item.dusterNo == form.dusterNo)
?.dusterName;
});
const handleStatusDotClick = () => {
router.push({
path: "/bag-monitor",
query: {
dusterNo: form.dusterNo,
}
});
};
</script>
<style lang="scss" scoped>
$borderColor: #bbbdc391;
......
......@@ -362,7 +362,6 @@ const handleValveNumClick = (row) => {
};
const handleStatusDotClick = (row, colIndex) => {
console.log("row", row);
router.push({
path: "/bag-monitor",
query: {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment