From 8084b705a67fb0796790a7d10e51c7c2a0858de1 Mon Sep 17 00:00:00 2001 From: tianyongbao Date: Mon, 19 Jan 2026 00:37:32 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8E=BB=E6=8E=89=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/other/index.vue | 71 +--------------------------------- 1 file changed, 1 insertion(+), 70 deletions(-) diff --git a/src/components/other/index.vue b/src/components/other/index.vue index 9475cc7..9fab6a9 100644 --- a/src/components/other/index.vue +++ b/src/components/other/index.vue @@ -1091,38 +1091,25 @@ function changeDev(item: any) { // 设备历史数据图表 function getDeviceHistory() { loading.value = true; - console.log('📊 开始获取历史数据,参数:', paramsHistory.value); if (!paramsHistory.value.serialNum) { - console.error('❌ serialNum 为空,无法查询'); loading.value = false; return; } deviceHistory(paramsHistory.value) .then((res: any) => { - console.log('📥 历史数据接口返回:', res); - // 后端直接返回数组,而不是 {code: 200, data: []} if (Array.isArray(res)) { - console.log('✅ 数据获取成功(数组格式),数据量:', res.length); - console.log('📋 数据内容:', res); chartsDatas.value = res; - console.log('💾 chartsDatas 已赋值:', chartsDatas.value); drawCharts(1); } else if (res.code == 200) { // 兼容标准响应格式 - console.log('✅ 数据获取成功(标准格式),数据量:', res.data?.length); - console.log('📋 数据内容:', res.data); chartsDatas.value = res.data || []; - console.log('💾 chartsDatas 已赋值:', chartsDatas.value); drawCharts(1); - } else { - console.error('❌ 接口返回失败:', res); } }) .catch((err) => { - console.error('❌ 接口请求异常:', err); }) .finally(() => { loading.value = false; @@ -1130,18 +1117,12 @@ function getDeviceHistory() { } // 监测图表 - 重构版本 function drawCharts(type) { - console.log('🎨 开始绘制图表, type:', type); loading.value = true; Taro.nextTick(() => { const data = chartsDatas.value; // 后端直接返回的数据数组 const paramsType = prDev.value; // 当前选中的指标类型 - console.log('📊 chartsDatas.value:', data); - console.log('🎯 当前指标类型:', paramsType); - console.log('📅 天数:', dayDev.value); - if (!data || data.length === 0) { - console.log('⚠️ 数据为空,不绘制图表'); loading.value = false; return; } @@ -1203,11 +1184,8 @@ function drawCharts(type) { // 提取时间和数据 data.forEach((item: any, index: number) => { - console.log(`📋 处理第 ${index + 1} 条数据:`, item); - // 格式化时间:2026-01-12 09:38:32.0 -> 01-12 09:38 const timeStr = item.time || item.createTime || ''; - console.log(`⏰ 时间字符串:`, timeStr); const timeParts = timeStr.split(' '); if (timeParts.length > 1) { @@ -1221,31 +1199,21 @@ function drawCharts(type) { const formattedTime = `${monthDay} ${hourMin}`; x_time_list.push(formattedTime); - console.log(`✅ 时间格式化成功: ${formattedTime}`); } else { - console.warn(`⚠️ 时间格式错误,跳过: ${timeStr}`); x_time_list.push('--:--'); // 占位符 } // 提取对应字段的数据 const value = item[fieldName]; - console.log(`📊 ${fieldName} 字段值:`, value); if (value !== null && value !== undefined) { const numValue = Number(value.toFixed(2)); seriesData.push(numValue); - console.log(`✅ 数据添加成功: ${numValue}`); } else { seriesData.push(null); - console.warn(`⚠️ ${fieldName} 字段为空`); } }); - console.log('⏰ x轴时间列表:', x_time_list); - console.log('📊 y轴数据列表:', seriesData); - console.log('📝 数据字段名:', fieldName); - console.log('🏷️ 系列名称:', seriesName); - // 添加主数据系列 series.unshift({ name: seriesName, @@ -1255,8 +1223,6 @@ function drawCharts(type) { setTimeout(() => { loading.value = false; const ids = "GdHQcFQYzLhfeEvZbEJnhDxJzBlbCxhE" + String(doDev.value) + String(prDev.value) + String(dayDev.value); - console.log('🎯 Canvas ID:', ids); - console.log('📦 准备创建图表, series:', series); const query = Taro.createSelectorQuery(); query.select("#" + ids).boundingClientRect(); @@ -1266,13 +1232,10 @@ function drawCharts(type) { chartConf.top = res[0] ? res[0].top : 0; chartConf.left = res[0] ? res[0].left : 0; } - console.log('📏 Canvas 位置:', { top: chartConf.top, left: chartConf.left }); }); if (type == 1) { - console.log('✅ 调用 createCharts'); createCharts(x_time_list, series, ids); } else { - console.log('✅ 调用 updateCharts'); updateCharts(x_time_list, series, ids); } }, 200); @@ -1326,12 +1289,6 @@ function moveCandle(e) { } // 创建图表 - 兼容模式(支持微信小程序和H5) function createCharts(x, series, ids) { - console.log('🎨 createCharts 被调用,使用旧版 Canvas 模式'); - console.log(' - x轴数据:', x); - console.log(' - series数据:', series); - console.log(' - Canvas ID:', ids); - console.log(' - 当前环境:', Taro.getEnv()); - Taro.nextTick(() => { let cWidth = chartConf.cWidth; let cHeight = chartConf.cHeight; @@ -1339,34 +1296,23 @@ function createCharts(x, series, ids) { // 判断环境 const env = Taro.getEnv(); - console.log('📱 运行环境:', env); if (env === 'WEB' || env === 'h5') { // H5 环境需要特殊处理 - console.log('🌐 H5 环境,使用 DOM 方式获取 Canvas'); - setTimeout(() => { // H5 下需要找到真实的 canvas 元素,不是 Taro 的封装组件 const canvasElement = document.querySelector(`#${ids} canvas`); if (!canvasElement) { - console.error('❌ 未找到 Canvas 元素:', ids); - console.log('尝试直接查找 canvas 标签...'); - const allCanvas = document.querySelectorAll('canvas'); - console.log('页面中所有 canvas:', allCanvas); return; } - console.log('✅ 找到 Canvas 元素:', canvasElement); const ctx = canvasElement.getContext('2d'); if (!ctx) { - console.error('❌ 无法获取 Canvas Context'); return; } - console.log('✅ 获取 Context 成功'); - uChartsOp.value[ids] = new uCharts({ type: "line", context: ctx, @@ -1438,22 +1384,15 @@ function createCharts(x, series, ids) { }, }, }); - - console.log('✅ H5 图表创建完成'); }, 300); } else { // 小程序环境 - 使用 canvas 2d 模式 - console.log('📱 小程序环境,使用 canvas 2d 获取 context'); - // 通过 createSelectorQuery 获取 canvas 2d 节点 const query = Taro.createSelectorQuery(); query.select('#' + ids) .fields({ node: true, size: true }) .exec((res) => { - console.log('📝 canvas 节点查询结果:', res); - if (!res || !res[0] || !res[0].node) { - console.error('❌ 无法获取 canvas 节点'); return; } @@ -1461,7 +1400,6 @@ function createCharts(x, series, ids) { const ctx = canvas.getContext('2d'); if (!ctx) { - console.error('❌ 无法获取 canvas context'); return; } @@ -1469,8 +1407,6 @@ function createCharts(x, series, ids) { canvas.width = cWidth * pixelRatio; canvas.height = cHeight * pixelRatio; - console.log('✅ 获取 canvas 2d context 成功'); - uChartsOp.value[ids] = new uCharts({ type: "line", context: ctx, @@ -1543,8 +1479,6 @@ function createCharts(x, series, ids) { }, }, }); - - console.log('✅ 小程序图表创建完成'); }); } }); @@ -1588,7 +1522,7 @@ function getDaysAgo(days) { paramsHistory.value.startTime = formatDateTime(start); paramsHistory.value.endTime = formatDateTime(now); - console.log(`📅 选择 ${days} 天,时间范围: ${paramsHistory.value.startTime} ~ ${paramsHistory.value.endTime}`); + // 设置 intervalType:1天->1, 3天->2, 7天->3 if (days === 1) { @@ -1639,8 +1573,6 @@ function getNowDate() { paramsHistory.value.startTime = formatDateTime(yesterday); paramsHistory.value.endTime = formatDateTime(now); paramsHistory.value.intervalType = 1; // 默认 1 天 - - console.log(`🕒 初始化时间: ${paramsHistory.value.startTime} ~ ${paramsHistory.value.endTime}`); } function groupByDate(data) { const result = {}; @@ -1827,7 +1759,6 @@ function setParamsCtr(id) { }); } function switchRes(list, index, type) { - console.log('switchRes 调用:', { list, index, type }); if (list.length > 0) { const info = list.filter((res) => res.index == index); if (type == "img") {