From 4121523db9de68c942c8bbabb974b03940e786b6 Mon Sep 17 00:00:00 2001 From: liutao <790864623@qq.com> Date: Tue, 28 Apr 2026 17:29:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=86=E5=8F=B2=E5=88=86=E6=9E=90=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/iot/device/index.ts | 9 ++ .../iot/historyData/HistorySingleAnalyse.vue | 113 +++++++++++++++++- 2 files changed, 116 insertions(+), 6 deletions(-) diff --git a/src/api/iot/device/index.ts b/src/api/iot/device/index.ts index c786a796..1a441511 100644 --- a/src/api/iot/device/index.ts +++ b/src/api/iot/device/index.ts @@ -162,6 +162,15 @@ export const DeviceApi = { }) }, + + getHistoryAnalyse: async (params: HistoryRecordParams) => { + return await request.get({ + url: `/iot/device/historyAnalyse`, + params, + paramsSerializer: (p) => qs.stringify(p, { allowDots: true, arrayFormat: 'repeat' }) + }) + }, + devicePointList: async () => { return await request.get({ url: `/iot/device/devicePointList` }) }, diff --git a/src/views/iot/historyData/HistorySingleAnalyse.vue b/src/views/iot/historyData/HistorySingleAnalyse.vue index fa3f0bf6..db15bfa9 100644 --- a/src/views/iot/historyData/HistorySingleAnalyse.vue +++ b/src/views/iot/historyData/HistorySingleAnalyse.vue @@ -562,6 +562,7 @@ async function handleAnalyze() { const res: any = await DeviceApi.getHistoryAnalyse(params) //oneHistoryData.value = res; //historyData.value = res.data; + if (res && res.analyseData) { resultData.value = res.analyseData; // 2. 重要:转换API返回数据的格式,适配图表 if (res && res.data) { @@ -574,9 +575,16 @@ async function handleAnalyze() { calculateAnalysis() ElMessage.success('已重新分析,图表与统计结果已更新') + } else { + // 如果接口返回空数据 + ElMessage.warning('未查询到相关数据') + initializeEmptyCharts() + } } catch (error) { console.error('分析失败:', error) ElMessage.error('分析失败,请检查网络连接或参数设置') + // 出错时显示空状态 + initializeEmptyCharts() } finally { analyzing.value = false } @@ -588,6 +596,7 @@ async function handleAnalyze() { // 新增函数:转换API返回数据为图表需要的格式 function transformApiDataToChartFormat(apiData) { if (!apiData || apiData.length === 0) { + historyData.value = [] oneHistoryData.value = { time: [], series: [] @@ -868,8 +877,24 @@ const getDiviceList = async () => { const data = await DeviceApi.getDeviceAttributeGroupList({deviceId: route.query.id}) pointGroups.value = data; activePointGroup.value = data[0]?.typeNames; - selectedPointCodes.value = data[0]?.codes; + let deviceDO = data[0]?.deviceDO; + if (deviceDO && deviceDO.contactInfo) { + selectedPointCodes.value = data[0]?.codes; + const contactInfo = JSON.parse(deviceDO.contactInfo) + + // 设置查询参数 + if (contactInfo.startTime) { + queryParams.startTime = contactInfo.startTime + } + if (contactInfo.endTime) { + queryParams.endTime = contactInfo.endTime + } + if (contactInfo.codes && Array.isArray(contactInfo.codes)) { + selectedPointCodes.value = contactInfo.codes + await handleAnalyze() // 自动调用分析 + } + } } finally { loading.value = false } @@ -942,6 +967,8 @@ function handleEndTimeChange(value) { } } } +// 新增:页面加载标志 +const pageLoaded = ref(false) // 结束时间选择器选项 const endTimeOptions = computed(() => { @@ -957,13 +984,87 @@ const endTimeOptions = computed(() => { } }) +// 新增:初始化空图表 +function initializeEmptyCharts() { + const chartDom = document.getElementById('historyTrendChart') + if (chartDom && !oneChartInstance) { + oneChartInstance = echarts.init(chartDom) + } + + // 显示无数据提示 + if (oneChartInstance) { + oneChartInstance.setOption({ + title: { + text: '请选择分析条件后点击"开始分析"', + left: 'center', + top: 'center', + textStyle: { + color: '#909399', + fontSize: 16, + fontWeight: 'normal' + } + }, + xAxis: { show: false }, + yAxis: { show: false }, + series: [] + }) + } + + // 清空表格数据 + resultData.value = [] + historyData.value = [] + summaryData.value = [ + { + title: '已选点位数', + value: 0, + desc: '请先选择点位' + }, + { + title: '分析时间跨度', + value: '未设置', + desc: '请设置开始和结束时间' + }, + { + title: '最大波动点位', + value: '-', + desc: '无数据' + }, + { + title: '最小波动点位', + value: '-', + desc: '无数据' + }, + { + title: '最高值点位', + value: '-', + desc: '无数据' + } + ] +} + // 生命周期 -onMounted(() => { +onMounted(async () => { getDiviceList() - calculateAnalysis() - nextTick(() => { - updateChart() - }) + // 2. 检查是否有保存的查询参数 + const hasContactInfo = selectedPointCodes.value && selectedPointCodes.value.length > 0 + + if (hasContactInfo) { + // 3. 如果有保存的参数,自动调用接口 + console.log('检测到保存的分析条件,自动查询...') + await handleAnalyze() // 自动调用分析 + } else { + // 4. 如果没有保存的参数,只初始化图表(显示无数据状态) + console.log('无保存的分析条件,显示空状态') + initializeEmptyCharts() + calculateAnalysis() // 计算空的统计结果 + } + + // 设置页面加载完成标志 + pageLoaded.value = true + /* calculateAnalysis() + nextTick(() => { + updateChart() + })*/ }) // 监听窗口变化