完善设备数列展示
This commit is contained in:
parent
ed9ef19805
commit
572cad895a
@ -13,22 +13,22 @@ export const fieldNameMapping: FieldMapping = {
|
|||||||
IoTDataType: 'IoT数据类型',
|
IoTDataType: 'IoT数据类型',
|
||||||
DeviceType: '设备类型',
|
DeviceType: '设备类型',
|
||||||
DeviceAddress: '设备ID',
|
DeviceAddress: '设备ID',
|
||||||
Timestamps: '时间戳',
|
// Timestamps: '时间戳', // 已隐藏,使用TimestampStr替代
|
||||||
// 可以根据需要添加更多映射
|
// 可以根据需要添加更多映射
|
||||||
};
|
};
|
||||||
|
|
||||||
// 字段类型配置
|
// 字段类型配置
|
||||||
export const fieldTypeConfig: FieldTypeConfig = {
|
export const fieldTypeConfig: FieldTypeConfig = {
|
||||||
Timestamps: {
|
// Timestamps: { // 已隐藏,使用TimestampStr替代
|
||||||
formatter: (value: string) => {
|
// formatter: (value: string) => {
|
||||||
if (!value) return '';
|
// if (!value) return '';
|
||||||
try {
|
// try {
|
||||||
return new Date(value).toLocaleString();
|
// return new Date(value).toLocaleString();
|
||||||
} catch {
|
// } catch {
|
||||||
return value;
|
// return value;
|
||||||
}
|
// }
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
// 可以根据需要添加更多类型配置
|
// 可以根据需要添加更多类型配置
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -40,6 +40,7 @@ const FIXED_FIELDS = [
|
|||||||
'DeviceAddress',
|
'DeviceAddress',
|
||||||
'TimestampStr',
|
'TimestampStr',
|
||||||
'FormattedTimestamps',
|
'FormattedTimestamps',
|
||||||
|
'Timestamps', // 添加Timestamps到固定字段列表,确保它被隐藏
|
||||||
'DeviceAddress',
|
'DeviceAddress',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@ -8,8 +8,10 @@ import { useRoute } from 'vue-router';
|
|||||||
import { Page } from '@vben/common-ui';
|
import { Page } from '@vben/common-ui';
|
||||||
|
|
||||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
import { postDeviceInfoPage } from '#/api-client';
|
import {
|
||||||
import { postTreeModelDeviceDataInfoPage } from '#/api-client';
|
postDeviceInfoPage,
|
||||||
|
postTreeModelDeviceDataInfoPage,
|
||||||
|
} from '#/api-client';
|
||||||
import { $t } from '#/locales';
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
import { generateDynamicColumns } from './dynamicColumns';
|
import { generateDynamicColumns } from './dynamicColumns';
|
||||||
@ -44,10 +46,16 @@ const fetchDeviceOptions = async () => {
|
|||||||
|
|
||||||
// 根据设备地址获取设备信息对象
|
// 根据设备地址获取设备信息对象
|
||||||
const getDeviceInfoByAddress = (deviceAddress: string) => {
|
const getDeviceInfoByAddress = (deviceAddress: string) => {
|
||||||
if (!deviceAddress || !deviceOptions.value || deviceOptions.value.length === 0) {
|
if (
|
||||||
|
!deviceAddress ||
|
||||||
|
!deviceOptions.value ||
|
||||||
|
deviceOptions.value.length === 0
|
||||||
|
) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return deviceOptions.value.find((device) => device.deviceAddress === deviceAddress);
|
return deviceOptions.value.find(
|
||||||
|
(device) => device.deviceAddress === deviceAddress,
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
// 格式化日期为 yyyy-MM-dd HH:mm:ss 格式
|
// 格式化日期为 yyyy-MM-dd HH:mm:ss 格式
|
||||||
@ -77,7 +85,7 @@ const dynamicColumns = ref<any[]>([]);
|
|||||||
const fixedColumns = [
|
const fixedColumns = [
|
||||||
{ title: '序号', type: 'seq', width: 50, field: 'seq', slots: {} },
|
{ title: '序号', type: 'seq', width: 50, field: 'seq', slots: {} },
|
||||||
{
|
{
|
||||||
field: 'Timestamps',
|
field: 'TimestampStr',
|
||||||
title: $t('abp.IoTDBBase.Timestamps'),
|
title: $t('abp.IoTDBBase.Timestamps'),
|
||||||
minWidth: 150,
|
minWidth: 150,
|
||||||
showOverflow: true,
|
showOverflow: true,
|
||||||
@ -273,20 +281,20 @@ const gridOptions: VxeGridProps<any> = {
|
|||||||
formValues ||
|
formValues ||
|
||||||
(gridApi?.formApi ? await gridApi.formApi.getValues() : {}) ||
|
(gridApi?.formApi ? await gridApi.formApi.getValues() : {}) ||
|
||||||
{};
|
{};
|
||||||
|
|
||||||
// 如果表单中没有DeviceAddress,但有路由参数,使用路由参数
|
// 如果表单中没有DeviceAddress,但有路由参数,使用路由参数
|
||||||
if (!currentFormValues.DeviceAddress && DeviceAddress) {
|
if (!currentFormValues.DeviceAddress && DeviceAddress) {
|
||||||
currentFormValues.DeviceAddress = DeviceAddress as string;
|
currentFormValues.DeviceAddress = DeviceAddress as string;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果表单中没有IoTDataType,但有路由参数,使用路由参数
|
// 如果表单中没有IoTDataType,但有路由参数,使用路由参数
|
||||||
if (!currentFormValues.IoTDataType && IoTDataType) {
|
if (!currentFormValues.IoTDataType && IoTDataType) {
|
||||||
currentFormValues.IoTDataType = IoTDataType as string;
|
currentFormValues.IoTDataType = IoTDataType as string;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理IoTDataType,保持字符串类型
|
// 处理IoTDataType,保持字符串类型
|
||||||
const ioTDataTypeValue = currentFormValues.IoTDataType;
|
const ioTDataTypeValue = currentFormValues.IoTDataType;
|
||||||
|
|
||||||
// 调试:打印表单值和路由参数
|
// 调试:打印表单值和路由参数
|
||||||
console.log('表单值:', currentFormValues);
|
console.log('表单值:', currentFormValues);
|
||||||
console.log('路由参数:', { IoTDataType, DeviceAddress });
|
console.log('路由参数:', { IoTDataType, DeviceAddress });
|
||||||
@ -328,7 +336,7 @@ const gridOptions: VxeGridProps<any> = {
|
|||||||
EndCreationTime: endCreationTime,
|
EndCreationTime: endCreationTime,
|
||||||
});
|
});
|
||||||
console.log('调用来源:', new Error().stack);
|
console.log('调用来源:', new Error().stack);
|
||||||
|
|
||||||
const { data } = await postTreeModelDeviceDataInfoPage({
|
const { data } = await postTreeModelDeviceDataInfoPage({
|
||||||
body: {
|
body: {
|
||||||
pageIndex: page.currentPage,
|
pageIndex: page.currentPage,
|
||||||
@ -451,21 +459,21 @@ const initializeGrid = async () => {
|
|||||||
// 确保表单值正确设置
|
// 确保表单值正确设置
|
||||||
const currentValues = await gridApi.formApi.getValues();
|
const currentValues = await gridApi.formApi.getValues();
|
||||||
const updatedValues = { ...currentValues };
|
const updatedValues = { ...currentValues };
|
||||||
|
|
||||||
if (!currentValues.DeviceAddress && DeviceAddress) {
|
if (!currentValues.DeviceAddress && DeviceAddress) {
|
||||||
updatedValues.DeviceAddress = DeviceAddress as string;
|
updatedValues.DeviceAddress = DeviceAddress as string;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!currentValues.IoTDataType && IoTDataType) {
|
if (!currentValues.IoTDataType && IoTDataType) {
|
||||||
updatedValues.IoTDataType = IoTDataType as string;
|
updatedValues.IoTDataType = IoTDataType as string;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (updatedValues !== currentValues) {
|
if (updatedValues !== currentValues) {
|
||||||
await gridApi.formApi.setValues(updatedValues);
|
await gridApi.formApi.setValues(updatedValues);
|
||||||
// 等待表单值更新完成
|
// 等待表单值更新完成
|
||||||
await nextTick();
|
await nextTick();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 延迟清除初始化标志,让表单值变化监听来处理查询
|
// 延迟清除初始化标志,让表单值变化监听来处理查询
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
isInitializing.value = false;
|
isInitializing.value = false;
|
||||||
@ -486,19 +494,18 @@ const initializeGrid = async () => {
|
|||||||
|
|
||||||
// 监听路由参数变化,当有路由参数时自动触发查询
|
// 监听路由参数变化,当有路由参数时自动触发查询
|
||||||
watch(
|
watch(
|
||||||
() => [IoTDataType, DeviceAddress],
|
() => [IoTDataType, DeviceAddress],
|
||||||
async (newValues, oldValues) => {
|
async (newValues, oldValues) => {
|
||||||
// 如果正在初始化,不触发额外的查询
|
// 如果正在初始化,不触发额外的查询
|
||||||
if (isInitializing.value || !isGridInitialized.value) {
|
if (isInitializing.value || !isGridInitialized.value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 只有当路由参数真正发生变化时才触发查询
|
// 只有当路由参数真正发生变化时才触发查询
|
||||||
const hasChanged = oldValues && (
|
const hasChanged =
|
||||||
newValues[0] !== oldValues[0] ||
|
oldValues &&
|
||||||
newValues[1] !== oldValues[1]
|
(newValues[0] !== oldValues[0] || newValues[1] !== oldValues[1]);
|
||||||
);
|
|
||||||
|
|
||||||
if (hasChanged && newValues.some(Boolean) && gridApi) {
|
if (hasChanged && newValues.some(Boolean) && gridApi) {
|
||||||
// 延迟一下确保表单值已经设置
|
// 延迟一下确保表单值已经设置
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@ -509,8 +516,6 @@ watch(
|
|||||||
{ immediate: false }, // 改为false,避免立即触发
|
{ immediate: false }, // 改为false,避免立即触发
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 页面初始化时,延迟初始化表格
|
// 页面初始化时,延迟初始化表格
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
// 延迟初始化,确保VXE表格组件已完全挂载
|
// 延迟初始化,确保VXE表格组件已完全挂载
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user