From 52a647b88aec9695f1f71d51328f7eedafc42c16 Mon Sep 17 00:00:00 2001 From: huang <1724659546@qq.com> Date: Mon, 20 Oct 2025 19:22:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/GenericMonitorList.vue | 21 +++++++++++++++++++++ src/views/monitor/SensorDataView.vue | 3 +-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/components/GenericMonitorList.vue b/src/components/GenericMonitorList.vue index c3359dc4..8f3658e2 100644 --- a/src/components/GenericMonitorList.vue +++ b/src/components/GenericMonitorList.vue @@ -70,6 +70,9 @@ border stripe style="width: 100%" + table-layout="auto" + :fit="true" + :scrollbar-always-on="true" @sort-change="handleSortChange" > { return props.columnsConfig.map(col => { const newCol = {...col}; newCol.prop = Array.isArray(col.dataIndex) ? col.dataIndex.join('.') : col.dataIndex; + + // 添加智能默认 formatter + if (!newCol.formatter) { + newCol.formatter = (row, column, cellValue) => { + if (typeof cellValue === 'object' && cellValue !== null) { + try { + return JSON.stringify(cellValue, null, 2); // 格式化为可读的JSON字符串 + } catch (e) { + console.warn('Failed to stringify object for display:', cellValue, e); + return '[Object]'; // 无法序列化时显示简短提示 + } + } else if (Array.isArray(cellValue)) { + return cellValue.join(', '); // 数组也默认用逗号连接 + } + return cellValue; + }; + } + return newCol; }); }); diff --git a/src/views/monitor/SensorDataView.vue b/src/views/monitor/SensorDataView.vue index 8941091a..08845bbe 100644 --- a/src/views/monitor/SensorDataView.vue +++ b/src/views/monitor/SensorDataView.vue @@ -45,8 +45,7 @@ const sensorDataColumns = [ title: '数据', dataIndex: 'data', key: 'data', - // 将数组格式化为逗号分隔的字符串 - formatter: (row, column, cellValue) => Array.isArray(cellValue) ? cellValue.join(', ') : cellValue, + // 移除 formatter,由 GenericMonitorList 自动处理对象和数组显示 minWidth: 150, }, {