完善设备数据展示,移除重复的字段

This commit is contained in:
ChenYi 2025-07-17 15:26:23 +08:00
parent d699782bc9
commit 180718974d
5 changed files with 142 additions and 66 deletions

View File

@ -4,7 +4,7 @@ import { computed } from 'vue';
import dayjs from 'dayjs';
import { getSelectResultList, postMetersPage } from '#/api-client';
import { getSelectResultList } from '#/api-client';
import { $t } from '#/locales';
export const querySchema = computed(() => [
@ -150,7 +150,20 @@ export const tableSchema: any = computed((): VxeGridProps['columns'] => [
minWidth: 150,
slots: {},
},
{ field: 'systemName', title: $t('abp.IoTDBBase.SystemName'), minWidth: 150, slots: {} },
{
field: 'formattedTimestamps',
title: $t('abp.IoTDBBase.FormattedTimestamps'),
minWidth: '150',
formatter: ({ cellValue }) => {
return cellValue ? dayjs(cellValue).format('YYYY-MM-DD HH:mm:ss') : '';
},
},
{
field: 'systemName',
title: $t('abp.IoTDBBase.SystemName'),
minWidth: 150,
slots: {},
},
{
field: 'deviceType',
title: $t('abp.IoTDBBase.DeviceType'),

View File

@ -1,4 +1,9 @@
import type { FieldMapping, FieldTypeConfig, ColumnConfig, DynamicDeviceData } from './types';
import type {
ColumnConfig,
DynamicDeviceData,
FieldMapping,
FieldTypeConfig,
} from './types';
// 字段名映射配置
export const fieldNameMapping: FieldMapping = {
@ -34,11 +39,14 @@ const FIXED_FIELDS = [
'DeviceType',
'IoTDataType',
'DeviceId',
'Timestamps'
'Timestamps',
'FormattedTimestamps',
];
// 动态生成表格列
export const generateDynamicColumns = (data: DynamicDeviceData[]): ColumnConfig[] => {
export const generateDynamicColumns = (
data: DynamicDeviceData[],
): ColumnConfig[] => {
if (!data || data.length === 0) return [];
// 获取第一条数据的所有字段
@ -47,11 +55,11 @@ export const generateDynamicColumns = (data: DynamicDeviceData[]): ColumnConfig[
const fields = Object.keys(firstRow);
// 过滤掉不需要显示的字段和固定字段
const excludeFields = ['id', 'key', '__typename', ...FIXED_FIELDS];
const excludeFields = new Set(['__typename', 'id', 'key', ...FIXED_FIELDS]);
return fields
.filter(field => !excludeFields.includes(field))
.map(field => {
.filter((field) => !excludeFields.has(field))
.map((field) => {
// 确保字段名是有效的字符串
const safeField = String(field || '').trim();
if (!safeField) return null;
@ -67,7 +75,10 @@ export const generateDynamicColumns = (data: DynamicDeviceData[]): ColumnConfig[
// 应用字段类型配置,确保配置是安全的
if (fieldTypeConfig[safeField]) {
const typeConfig = fieldTypeConfig[safeField];
if (typeConfig.formatter && typeof typeConfig.formatter === 'function') {
if (
typeConfig.formatter &&
typeof typeConfig.formatter === 'function'
) {
columnConfig.formatter = typeConfig.formatter;
}
if (typeConfig.width !== undefined) {
@ -94,7 +105,7 @@ export const getAllPossibleFields = () => {
// 预定义列配置(可选)
export const getPredefinedColumns = () => {
return getAllPossibleFields().map(field => ({
return getAllPossibleFields().map((field) => ({
field,
title: fieldNameMapping[field] || field,
minWidth: 150,

View File

@ -2,7 +2,7 @@
import type { VbenFormProps } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';
import { computed, nextTick, ref, watch, onMounted } from 'vue';
import { computed, nextTick, onMounted, ref, watch } from 'vue';
import { useRoute } from 'vue-router';
import { Page } from '@vben/common-ui';
@ -57,7 +57,7 @@ const formatDate = (date: Date | string) => {
if (isNaN(d.getTime())) return undefined;
const year = d.getFullYear();
const month = String(d.getMonth() +1).padStart(2, '0');
const month = String(d.getMonth() + 1).padStart(2, '0');
const day = String(d.getDate()).padStart(2, '0');
const hours = String(d.getHours()).padStart(2, '0');
const minutes = String(d.getMinutes()).padStart(2, '0');
@ -66,7 +66,6 @@ const formatDate = (date: Date | string) => {
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
};
const route = useRoute();
const { DeviceType, DeviceId, FocusAddress, SystemName } = route.query;
@ -76,11 +75,41 @@ const dynamicColumns = ref<any[]>([]);
// - IoTDBTreeModelDeviceDataDto
const fixedColumns = [
{ title: '序号', type: 'seq', width: 50, field: 'seq', slots: {} },
{ field: 'Timestamps', title: $t('abp.IoTDBBase.Timestamps'), minWidth: 150, showOverflow: true, slots: {} },
{ field: 'FormattedTimestamps', title: $t('abp.IoTDBBase.FormattedTimestamps'), minWidth: 150, showOverflow: true, slots: {} },
{ field: 'SystemName', title: $t('abp.IoTDBBase.SystemName'), minWidth: 150, showOverflow: true, slots: {} },
{ field: 'ProjectId', title: $t('abp.IoTDBBase.ProjectId'), minWidth: 150, showOverflow: true, slots: {} },
{ field: 'DeviceType', title: $t('abp.IoTDBBase.DeviceType'), minWidth: 150, showOverflow: true, slots: {} },
{
field: 'Timestamps',
title: $t('abp.IoTDBBase.Timestamps'),
minWidth: 150,
showOverflow: true,
slots: {},
},
{
field: 'FormattedTimestamps',
title: $t('abp.IoTDBBase.FormattedTimestamps'),
minWidth: 150,
showOverflow: true,
slots: {},
},
{
field: 'SystemName',
title: $t('abp.IoTDBBase.SystemName'),
minWidth: 150,
showOverflow: true,
slots: {},
},
{
field: 'ProjectId',
title: $t('abp.IoTDBBase.ProjectId'),
minWidth: 150,
showOverflow: true,
slots: {},
},
{
field: 'DeviceType',
title: $t('abp.IoTDBBase.DeviceType'),
minWidth: 150,
showOverflow: true,
slots: {},
},
{
field: 'IoTDataType',
title: $t('abp.IoTDBBase.IoTDataType'),
@ -88,7 +117,13 @@ const fixedColumns = [
showOverflow: true,
slots: {},
},
{ field: 'DeviceId', title: $t('abp.IoTDBBase.DeviceId'), minWidth: 150, showOverflow: true, slots: {} },
{
field: 'DeviceId',
title: $t('abp.IoTDBBase.DeviceId'),
minWidth: 150,
showOverflow: true,
slots: {},
},
];
// - 使
@ -102,11 +137,11 @@ const allColumns = computed(() => {
//
if (dynamicColumns.value && Array.isArray(dynamicColumns.value)) {
const validDynamicColumns = dynamicColumns.value.filter(col =>
col && typeof col === 'object' && col.field && col.title
).map(col => ({
const validDynamicColumns = dynamicColumns.value
.filter((col) => col && typeof col === 'object' && col.field && col.title)
.map((col) => ({
...col,
slots: col.slots || {} // slots
slots: col.slots || {}, // slots
}));
columns.push(...validDynamicColumns);
}
@ -144,11 +179,11 @@ const formOptions: VbenFormProps = {
const relevantFields = new Set([
'DeviceId',
'DeviceType',
'EndCreationTime',
'FocusAddress',
'IoTDataType',
'SystemName',
'StartCreationTime',
'EndCreationTime',
'SystemName',
]);
const hasRelevantChange = changedFields.some((field) =>
relevantFields.has(field),
@ -160,17 +195,21 @@ const formOptions: VbenFormProps = {
if (deviceId) {
// deviceOptions
let device = deviceOptions.value.length > 0 ? deviceOptions.value.find(d => d.id === deviceId) : null;
let device =
deviceOptions.value.length > 0
? deviceOptions.value.find((d) => d.id === deviceId)
: null;
// DeviceSelect
if (!device && gridApi?.formApi) {
try {
// DeviceSelect
const deviceSelectRef = gridApi.formApi.getFieldComponentRef('DeviceId');
const deviceSelectRef =
gridApi.formApi.getFieldComponentRef('DeviceId');
if (deviceSelectRef && deviceSelectRef.getSelectedDevice) {
device = deviceSelectRef.getSelectedDevice();
}
} catch (error) {
} catch {
//
}
}
@ -181,14 +220,15 @@ const formOptions: VbenFormProps = {
//
setTimeout(() => {
try {
const deviceSelectRef = gridApi.formApi.getFieldComponentRef('DeviceId');
const deviceSelectRef =
gridApi.formApi.getFieldComponentRef('DeviceId');
if (deviceSelectRef && deviceSelectRef.getSelectedDevice) {
const delayedDevice = deviceSelectRef.getSelectedDevice();
if (delayedDevice) {
selectedDeviceInfo.value = delayedDevice;
}
}
} catch (error) {
} catch {
//
}
}, 100);
@ -239,7 +279,10 @@ const gridOptions: VxeGridProps<any> = {
return { items: [], totalCount: 0 };
}
// formValuesAPI
const currentFormValues = formValues || (gridApi?.formApi ? await gridApi.formApi.getValues() : {}) || {};
const currentFormValues =
formValues ||
(gridApi?.formApi ? await gridApi.formApi.getValues() : {}) ||
{};
// DeviceTypeIoTDataType
const deviceTypeValue = currentFormValues.DeviceType || DeviceType;
const deviceTypeNumber = deviceTypeValue
@ -249,15 +292,23 @@ const gridOptions: VxeGridProps<any> = {
const ioTDataTypeValue = currentFormValues.IoTDataType;
//
const startCreationTime = currentFormValues.StartCreationTime ? formatDate(currentFormValues.StartCreationTime) : undefined;
const endCreationTime = currentFormValues.EndCreationTime ? formatDate(currentFormValues.EndCreationTime) : undefined;
const startCreationTime = currentFormValues.StartCreationTime
? formatDate(currentFormValues.StartCreationTime)
: undefined;
const endCreationTime = currentFormValues.EndCreationTime
? formatDate(currentFormValues.EndCreationTime)
: undefined;
// DeviceId(10)使focusId
let finalDeviceId = currentFormValues.DeviceId || DeviceId || '';
let finalFocusAddress = currentFormValues.FocusAddress || '';
// 使
const deviceInfo = selectedDeviceInfo.value || (currentFormValues.DeviceId && deviceOptions.value.length > 0 ? getDeviceInfoById(currentFormValues.DeviceId) : null);
const deviceInfo =
selectedDeviceInfo.value ||
(currentFormValues.DeviceId && deviceOptions.value.length > 0
? getDeviceInfoById(currentFormValues.DeviceId)
: null);
if (deviceInfo) {
finalFocusAddress = deviceInfo.focusAddress || '';
@ -292,8 +343,6 @@ const gridOptions: VxeGridProps<any> = {
},
});
// 使
if (data?.items && data.items.length > 0) {
try {
@ -411,14 +460,14 @@ watch(
() => [DeviceType, DeviceId, FocusAddress, SystemName],
async (newValues, oldValues) => {
//
if (newValues.some(val => val) && gridApi && isGridInitialized.value) {
if (newValues.some(Boolean) && gridApi && isGridInitialized.value) {
//
setTimeout(() => {
gridApi.reload();
}, 100);
}
},
{ immediate: false } // false
{ immediate: false }, // false
);
//

View File

@ -146,11 +146,6 @@ export const tableSchema: any = computed((): VxeGridProps['columns'] => [
title: $t('abp.IoTDBBase.Timestamps'),
minWidth: '150',
},
{
field: 'FormattedTimestamps',
title: $t('abp.IoTDBBase.FormattedTimestamps'),
minWidth: '150',
},
{
field: 'SystemName',
title: $t('abp.IoTDBBase.SystemName'),

View File

@ -150,6 +150,14 @@ export const tableSchema: any = computed((): VxeGridProps['columns'] => [
minWidth: '150',
slots: {},
},
{
field: 'formattedTimestamps',
title: $t('abp.IoTDBBase.FormattedTimestamps'),
minWidth: '150',
formatter: ({ cellValue }) => {
return cellValue ? dayjs(cellValue).format('YYYY-MM-DD HH:mm:ss') : '';
},
},
{
field: 'systemName',
title: $t('abp.IoTDBBase.SystemName'),