From d3e9fcce4cacc7deacb316571322db8851a2f11f Mon Sep 17 00:00:00 2001 From: xiaozhiyong Date: Fri, 5 Jun 2026 09:52:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 4 +- .../detail/components/info/index.vue | 2 +- .../detail/components/trend/index.vue | 53 +++++++++---------- .../equipment/list/components/list/index.vue | 29 ++++++---- 4 files changed, 46 insertions(+), 42 deletions(-) diff --git a/.env.development b/.env.development index a76eccb..42409c5 100644 --- a/.env.development +++ b/.env.development @@ -4,8 +4,8 @@ VITE_SERVER_PORT = 8888 VITE_BASE_API = /api VITE_FILE_API = /api # VITE_BASE_PATH = http://192.168.1.9:8888 -# VITE_BASE_PATH = http://192.168.110.98:8888 -VITE_BASE_PATH = https://www.xingoil.com/api +VITE_BASE_PATH = http://192.168.110.98:8888 +# VITE_BASE_PATH = https://www.xingoil.com/api VITE_POSITION = open VITE_EDITOR = code // VITE_EDITOR = webstorm 如果使用webstorm开发且要使用dom定位到代码行功能 请先自定添加 webstorm到环境变量 再将VITE_EDITOR值修改为webstorm diff --git a/src/view/equipment/list/components/detail/components/info/index.vue b/src/view/equipment/list/components/detail/components/info/index.vue index 227a8b8..595b46a 100644 --- a/src/view/equipment/list/components/detail/components/info/index.vue +++ b/src/view/equipment/list/components/detail/components/info/index.vue @@ -4,7 +4,7 @@

基本信息

设备ID: - {{ device?.cbId || '未设置' }} + {{ device?.ID || '未设置' }}
网关ID: diff --git a/src/view/equipment/list/components/detail/components/trend/index.vue b/src/view/equipment/list/components/detail/components/trend/index.vue index 5b7bdfb..ff47b08 100644 --- a/src/view/equipment/list/components/detail/components/trend/index.vue +++ b/src/view/equipment/list/components/detail/components/trend/index.vue @@ -14,8 +14,8 @@ />
- - + +
{{ item.title }} @@ -48,8 +48,19 @@ // 容器 ref const chartContainerRef = ref(null) + // 容器就绪状态:父级用 v-show 切换时,初始为 display:None,宽度为 0,需要等容器有尺寸后再渲染图表 + const isReady = ref(false) let resizeObserver = null + // 检测容器是否已具备尺寸 + const checkContainerReady = () => { + if (isReady.value || !chartContainerRef.value) return + const { clientWidth, clientHeight } = chartContainerRef.value + if (clientWidth > 0 && clientHeight > 0) { + isReady.value = true + } + } + // 触发图表 resize const triggerResize = () => { // 触发 window resize 事件让 vue-echarts autoresize 生效 @@ -97,11 +108,6 @@ // const startTime = formatDateTime(dateRange.value[0]) // const endTime = formatDateTime(dateRange.value[1]) try { - console.log('[Trend] 请求设备详情数据:', { - deviceId - // startTime, - // endTime - }) const result = await serve.getDeviceDetailsListByPage({ page: 1, pageSize: 999, @@ -109,15 +115,12 @@ startCreatedAt: dateRange.value[0], endCreatedAt: dateRange.value[1] }) - console.log('[Trend] 接口返回:', result) + if (result.code === 0) { // 提取数据 const list = result.data.list || [] // 调试:打印第一条数据的所有字段 - if (list.length > 0) { - console.log('[Trend] 第一条数据的所有字段:', list[0]) - console.log('[Trend] 字段名列表:', Object.keys(list[0])) - } + const timeData = [] const chartData = { voltage: [], // 电压(V) @@ -143,16 +146,13 @@ // 更新图表 updateChartData(timeData, chartData) } - } catch (e) { - console.error('[Trend] 请求失败', e) - } + } catch (e) {} } // 监听 device 变化,重新请求数据 watch( () => props.device, (newDevice, oldDevice) => { - console.log('[Trend] device 变化:', newDevice) if (newDevice && (!oldDevice || newDevice.ID !== oldDevice.ID)) { getTableData() } @@ -164,18 +164,15 @@ ) onMounted(() => { - // 等待 DOM 渲染完成后触发 resize - nextTick(() => { - // 延迟执行确保容器有尺寸 - setTimeout(() => { - triggerResize() - }, 100) - }) - - // 监听容器尺寸变化 + // 父级用 v-show 切换 Tab,组件挂载时可能是 display:None(尺寸为 0), + // 需要等容器有实际尺寸后再渲染 v-chart,否则 ECharts 初始化时会报 + // "Can't get DOM width or height" if (chartContainerRef.value) { + // 先检查一次(处理初始就是可见的情况) + nextTick(checkContainerReady) + // 监听容器尺寸变化:从 0 变为有尺寸时(例如切到当前 Tab)触发 isReady resizeObserver = new ResizeObserver(() => { - triggerResize() + checkContainerReady() }) resizeObserver.observe(chartContainerRef.value) } @@ -199,7 +196,7 @@ // 日期变化处理 const handleDateChange = (val) => { if (val && val.length === 2) { - console.log('[Trend] 日期范围:', val) + // console.log('[Trend] 日期范围:', val) // 触发图表 resize nextTick(() => { triggerResize() @@ -210,7 +207,7 @@ // 重置日期 const resetDateRange = () => { dateRange.value = [] - console.log('[Trend] 重置日期') + nextTick(() => { triggerResize() }) diff --git a/src/view/equipment/list/components/list/index.vue b/src/view/equipment/list/components/list/index.vue index 7928be7..fd7c5b9 100644 --- a/src/view/equipment/list/components/list/index.vue +++ b/src/view/equipment/list/components/list/index.vue @@ -2,12 +2,22 @@
{{ item.cbTypeName }}
- ID:{{ item.cbId }} - + ID:{{ item.ID }} +
{{ item.gatewayMac }} -
@@ -110,7 +113,9 @@ const emit = defineEmits(['select-device']) const searchInfo = ref({ - deviceStatus: '' + deviceStatus: '', + protocol: '', + ID: '' }) const page = ref(1) @@ -204,7 +209,9 @@ const onReset = () => { searchInfo.value = { - deviceStatus: '' + deviceStatus: '', + protocol: '', + ID: '' } getTableData() }