优化展示
This commit is contained in:
@@ -70,6 +70,9 @@
|
|||||||
border
|
border
|
||||||
stripe
|
stripe
|
||||||
style="width: 100%"
|
style="width: 100%"
|
||||||
|
table-layout="auto"
|
||||||
|
:fit="true"
|
||||||
|
:scrollbar-always-on="true"
|
||||||
@sort-change="handleSortChange"
|
@sort-change="handleSortChange"
|
||||||
>
|
>
|
||||||
<el-table-column
|
<el-table-column
|
||||||
@@ -138,6 +141,24 @@ const tableColumns = computed(() => {
|
|||||||
return props.columnsConfig.map(col => {
|
return props.columnsConfig.map(col => {
|
||||||
const newCol = {...col};
|
const newCol = {...col};
|
||||||
newCol.prop = Array.isArray(col.dataIndex) ? col.dataIndex.join('.') : col.dataIndex;
|
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;
|
return newCol;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -45,8 +45,7 @@ const sensorDataColumns = [
|
|||||||
title: '数据',
|
title: '数据',
|
||||||
dataIndex: 'data',
|
dataIndex: 'data',
|
||||||
key: 'data',
|
key: 'data',
|
||||||
// 将数组格式化为逗号分隔的字符串
|
// 移除 formatter,由 GenericMonitorList 自动处理对象和数组显示
|
||||||
formatter: (row, column, cellValue) => Array.isArray(cellValue) ? cellValue.join(', ') : cellValue,
|
|
||||||
minWidth: 150,
|
minWidth: 150,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user