2025-06-25 17:29:57 +08:00
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
|
import type { VbenFormProps } from '#/adapter/form';
|
|
|
|
|
|
import type { VxeGridProps } from '#/adapter/vxe-table';
|
|
|
|
|
|
|
2025-07-11 13:51:31 +08:00
|
|
|
|
import { computed, nextTick, ref, watch } from 'vue';
|
2025-06-25 17:29:57 +08:00
|
|
|
|
import { useRoute } from 'vue-router';
|
|
|
|
|
|
|
|
|
|
|
|
import { Page } from '@vben/common-ui';
|
|
|
|
|
|
|
|
|
|
|
|
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
2025-07-14 08:57:04 +08:00
|
|
|
|
import { postMetersPage, postTreeModelDeviceDataInfoPage } from '#/api-client';
|
|
|
|
|
|
import { $t } from '#/locales';
|
2025-06-25 17:29:57 +08:00
|
|
|
|
|
2025-07-10 10:28:06 +08:00
|
|
|
|
import { generateDynamicColumns } from './dynamicColumns';
|
2025-07-11 13:51:31 +08:00
|
|
|
|
import { querySchema } from './schema';
|
2025-06-25 17:29:57 +08:00
|
|
|
|
|
2025-07-14 08:57:04 +08:00
|
|
|
|
defineOptions({
|
|
|
|
|
|
name: 'DeviceData',
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-07-11 17:41:23 +08:00
|
|
|
|
// 存储设备信息选项的完整数据
|
|
|
|
|
|
const deviceOptions = ref<any[]>([]);
|
|
|
|
|
|
|
|
|
|
|
|
// 获取设备信息的完整数据
|
|
|
|
|
|
const fetchDeviceOptions = async () => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const { data } = await postMetersPage({
|
|
|
|
|
|
body: {
|
|
|
|
|
|
pageIndex: 1,
|
|
|
|
|
|
pageSize: 1000,
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
2025-07-14 08:57:04 +08:00
|
|
|
|
|
2025-07-11 17:41:23 +08:00
|
|
|
|
if (data?.items) {
|
|
|
|
|
|
deviceOptions.value = data.items;
|
|
|
|
|
|
console.log('设备信息选项:', deviceOptions.value);
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('获取设备信息失败:', error);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 根据设备ID获取设备信息对象
|
|
|
|
|
|
const getDeviceInfoById = (deviceId: string) => {
|
2025-07-14 08:57:04 +08:00
|
|
|
|
return deviceOptions.value.find((device) => device.id === deviceId);
|
2025-07-11 17:41:23 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2025-06-25 17:29:57 +08:00
|
|
|
|
const route = useRoute();
|
|
|
|
|
|
const { DeviceType, DeviceId, FocusAddress } = route.query;
|
2025-07-10 10:28:06 +08:00
|
|
|
|
|
|
|
|
|
|
// 动态列定义
|
|
|
|
|
|
const dynamicColumns = ref<any[]>([]);
|
|
|
|
|
|
|
2025-07-10 13:50:05 +08:00
|
|
|
|
// 固定列定义(始终显示)- 基于 IoTDBTreeModelDeviceDataDto 类型
|
2025-07-10 10:52:19 +08:00
|
|
|
|
const fixedColumns = [
|
2025-07-10 10:28:06 +08:00
|
|
|
|
{ title: '序号', type: 'seq', width: 50 },
|
2025-07-14 08:57:04 +08:00
|
|
|
|
{ field: 'Timestamps', title: $t('abp.IoTDBBase.Timestamps'), minWidth: 150 },
|
|
|
|
|
|
{ field: 'SystemName', title: $t('abp.IoTDBBase.SystemName'), minWidth: 150 },
|
|
|
|
|
|
{ field: 'ProjectId', title: $t('abp.IoTDBBase.ProjectId'), minWidth: 150 },
|
|
|
|
|
|
{ field: 'DeviceType', title: $t('abp.IoTDBBase.DeviceType'), minWidth: 150 },
|
|
|
|
|
|
{
|
|
|
|
|
|
field: 'IoTDataType',
|
|
|
|
|
|
title: $t('abp.IoTDBBase.IoTDataType'),
|
|
|
|
|
|
minWidth: 150,
|
|
|
|
|
|
},
|
|
|
|
|
|
{ field: 'DeviceId', title: $t('abp.IoTDBBase.DeviceId'), minWidth: 150 },
|
2025-07-10 10:52:19 +08:00
|
|
|
|
];
|
2025-07-10 10:28:06 +08:00
|
|
|
|
|
2025-07-10 11:47:50 +08:00
|
|
|
|
// 合并固定列和动态列 - 使用计算属性确保响应式
|
2025-07-11 13:51:31 +08:00
|
|
|
|
const allColumns = computed(() => [...fixedColumns, ...dynamicColumns.value]);
|
2025-07-10 10:36:02 +08:00
|
|
|
|
|
|
|
|
|
|
// 初始化默认列(防止表格空白)
|
|
|
|
|
|
const initDefaultColumns = () => {
|
|
|
|
|
|
if (dynamicColumns.value.length === 0) {
|
2025-07-10 13:50:05 +08:00
|
|
|
|
// 不再需要在这里设置默认列,因为固定列已经包含了基本字段
|
|
|
|
|
|
dynamicColumns.value = [];
|
2025-07-10 10:36:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化默认列
|
|
|
|
|
|
initDefaultColumns();
|
2025-07-10 10:28:06 +08:00
|
|
|
|
|
2025-07-11 17:41:23 +08:00
|
|
|
|
// 获取设备信息数据
|
|
|
|
|
|
fetchDeviceOptions();
|
|
|
|
|
|
|
2025-06-25 17:29:57 +08:00
|
|
|
|
const formOptions: VbenFormProps = {
|
|
|
|
|
|
schema: querySchema.value,
|
2025-07-09 17:31:29 +08:00
|
|
|
|
initialValues: {
|
|
|
|
|
|
FocusAddress: FocusAddress as string,
|
2025-07-11 17:41:23 +08:00
|
|
|
|
DeviceType: DeviceType ? Number(DeviceType) : undefined,
|
|
|
|
|
|
DeviceId: DeviceId as string,
|
2025-07-09 17:31:29 +08:00
|
|
|
|
},
|
2025-07-10 10:28:06 +08:00
|
|
|
|
// 禁用表单值变化时自动提交,使用自定义处理函数
|
|
|
|
|
|
submitOnChange: false,
|
|
|
|
|
|
// 添加表单值变化的处理函数
|
|
|
|
|
|
handleValuesChange: async (values, changedFields) => {
|
2025-07-11 17:41:23 +08:00
|
|
|
|
// 当任何相关字段发生变化时,刷新表格数据
|
2025-07-14 08:57:04 +08:00
|
|
|
|
const relevantFields = new Set([
|
|
|
|
|
|
'DeviceId',
|
|
|
|
|
|
'DeviceType',
|
|
|
|
|
|
'FocusAddress',
|
|
|
|
|
|
'IoTDataType',
|
|
|
|
|
|
'SystemName',
|
|
|
|
|
|
]);
|
|
|
|
|
|
const hasRelevantChange = changedFields.some((field) =>
|
|
|
|
|
|
relevantFields.has(field),
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2025-07-11 17:41:23 +08:00
|
|
|
|
if (hasRelevantChange) {
|
|
|
|
|
|
console.log('表单字段变化:', { values, changedFields });
|
2025-07-14 08:57:04 +08:00
|
|
|
|
console.log(
|
|
|
|
|
|
'相关字段变化:',
|
|
|
|
|
|
changedFields.filter((field) => relevantFields.has(field)),
|
|
|
|
|
|
);
|
2025-07-11 13:51:31 +08:00
|
|
|
|
|
2025-07-10 10:28:06 +08:00
|
|
|
|
// 使用 setTimeout 确保表单值已经完全更新
|
|
|
|
|
|
setTimeout(async () => {
|
|
|
|
|
|
const latestValues = await gridApi.formApi.getValues();
|
2025-07-11 17:41:23 +08:00
|
|
|
|
console.log('最新表单值:', latestValues);
|
2025-07-10 10:28:06 +08:00
|
|
|
|
gridApi.reload(latestValues);
|
|
|
|
|
|
}, 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2025-06-25 17:29:57 +08:00
|
|
|
|
};
|
2025-07-10 11:47:50 +08:00
|
|
|
|
|
2025-06-25 17:29:57 +08:00
|
|
|
|
const gridOptions: VxeGridProps<any> = {
|
|
|
|
|
|
checkboxConfig: {
|
|
|
|
|
|
highlight: true,
|
|
|
|
|
|
labelField: 'name',
|
|
|
|
|
|
},
|
2025-07-10 11:47:50 +08:00
|
|
|
|
columns: allColumns, // 使用计算属性
|
2025-06-25 17:29:57 +08:00
|
|
|
|
height: 'auto',
|
|
|
|
|
|
keepSource: true,
|
2025-07-10 10:36:02 +08:00
|
|
|
|
pagerConfig: {
|
|
|
|
|
|
currentPage: 1,
|
|
|
|
|
|
pageSize: 20,
|
2025-07-10 15:33:21 +08:00
|
|
|
|
// 添加分页事件处理
|
|
|
|
|
|
onChange: (currentPage: number, pageSize: number) => {
|
|
|
|
|
|
console.log('分页变化:', { currentPage, pageSize });
|
|
|
|
|
|
// 当pageSize变化时,重置到第一页
|
|
|
|
|
|
if (pageSize !== gridOptions.pagerConfig.pageSize) {
|
|
|
|
|
|
console.log('页面大小变化,重置到第一页');
|
|
|
|
|
|
// 更新配置中的pageSize
|
|
|
|
|
|
gridOptions.pagerConfig.pageSize = pageSize;
|
|
|
|
|
|
gridOptions.pagerConfig.currentPage = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2025-07-10 10:36:02 +08:00
|
|
|
|
},
|
2025-06-25 17:29:57 +08:00
|
|
|
|
toolbarConfig: {
|
|
|
|
|
|
custom: true,
|
|
|
|
|
|
},
|
|
|
|
|
|
customConfig: {
|
|
|
|
|
|
storage: true,
|
|
|
|
|
|
},
|
2025-07-10 10:52:19 +08:00
|
|
|
|
// 添加调试配置
|
|
|
|
|
|
showOverflow: true,
|
|
|
|
|
|
showHeaderOverflow: true,
|
2025-06-25 17:29:57 +08:00
|
|
|
|
proxyConfig: {
|
|
|
|
|
|
ajax: {
|
|
|
|
|
|
query: async ({ page }, formValues) => {
|
2025-07-10 10:52:19 +08:00
|
|
|
|
console.log('=== API调用开始 ===');
|
2025-07-11 17:41:23 +08:00
|
|
|
|
// 处理DeviceType和IoTDataType,确保传递数字类型
|
|
|
|
|
|
const deviceTypeValue = formValues.DeviceType || DeviceType;
|
2025-07-14 08:57:04 +08:00
|
|
|
|
const deviceTypeNumber = deviceTypeValue
|
|
|
|
|
|
? Number(deviceTypeValue)
|
|
|
|
|
|
: undefined;
|
|
|
|
|
|
|
2025-07-14 10:32:02 +08:00
|
|
|
|
const ioTDataTypeValue = formValues.IoTDataType;
|
2025-07-14 08:57:04 +08:00
|
|
|
|
|
2025-07-14 10:32:02 +08:00
|
|
|
|
console.log('=== API调用开始 ===2', ioTDataTypeValue);
|
2025-07-11 13:51:31 +08:00
|
|
|
|
|
2025-07-14 09:09:44 +08:00
|
|
|
|
// 处理DeviceId,当设备类型为集中器(10)时,使用focusId
|
|
|
|
|
|
let finalDeviceId = 0;
|
|
|
|
|
|
const deviceInfo = getDeviceInfoById(formValues.DeviceId);
|
|
|
|
|
|
finalDeviceId =
|
|
|
|
|
|
deviceTypeNumber === 10 && deviceInfo
|
|
|
|
|
|
? deviceInfo.focusId
|
|
|
|
|
|
: deviceInfo.meterId;
|
2025-07-10 10:52:19 +08:00
|
|
|
|
try {
|
|
|
|
|
|
const { data } = await postTreeModelDeviceDataInfoPage({
|
|
|
|
|
|
body: {
|
|
|
|
|
|
...formValues,
|
|
|
|
|
|
pageIndex: page.currentPage,
|
|
|
|
|
|
pageSize: page.pageSize,
|
2025-07-11 17:41:23 +08:00
|
|
|
|
// 优先使用表单中的值,如果没有则使用路由参数
|
|
|
|
|
|
DeviceType: deviceTypeNumber,
|
2025-07-14 10:32:02 +08:00
|
|
|
|
DeviceId: finalDeviceId.toString(),
|
|
|
|
|
|
FocusAddress: deviceInfo.focusAddress,
|
2025-07-11 17:41:23 +08:00
|
|
|
|
// 添加其他表单参数
|
|
|
|
|
|
SystemName: formValues.SystemName,
|
2025-07-14 09:09:44 +08:00
|
|
|
|
IoTDataType: ioTDataTypeValue,
|
2025-07-10 10:52:19 +08:00
|
|
|
|
},
|
|
|
|
|
|
});
|
2025-07-11 13:51:31 +08:00
|
|
|
|
|
2025-07-10 10:52:19 +08:00
|
|
|
|
console.log('API返回的原始数据:', data);
|
|
|
|
|
|
console.log('数据类型:', typeof data);
|
2025-07-11 13:51:31 +08:00
|
|
|
|
console.log(
|
|
|
|
|
|
'data是否为null/undefined:',
|
|
|
|
|
|
data === null || data === undefined,
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2025-07-10 10:52:19 +08:00
|
|
|
|
if (data) {
|
|
|
|
|
|
console.log('data.items存在:', !!data.items);
|
2025-07-11 13:51:31 +08:00
|
|
|
|
console.log(
|
|
|
|
|
|
'data.items类型:',
|
|
|
|
|
|
Array.isArray(data.items) ? 'Array' : typeof data.items,
|
|
|
|
|
|
);
|
2025-07-10 10:52:19 +08:00
|
|
|
|
if (data.items) {
|
|
|
|
|
|
console.log('data.items长度:', data.items.length);
|
|
|
|
|
|
if (data.items.length > 0) {
|
|
|
|
|
|
console.log('第一条数据:', data.items[0]);
|
2025-07-11 13:51:31 +08:00
|
|
|
|
console.log(
|
|
|
|
|
|
'第一条数据的所有字段:',
|
|
|
|
|
|
Object.keys(data.items[0]),
|
|
|
|
|
|
);
|
2025-07-10 10:52:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-07-11 13:51:31 +08:00
|
|
|
|
|
2025-07-11 14:01:20 +08:00
|
|
|
|
// 简化处理逻辑,直接使用接口返回的数据
|
2025-07-10 10:52:19 +08:00
|
|
|
|
if (data?.items && data.items.length > 0) {
|
|
|
|
|
|
console.log('原始items数据:', data.items);
|
2025-07-11 13:51:31 +08:00
|
|
|
|
|
2025-07-10 10:52:19 +08:00
|
|
|
|
// 动态生成列定义
|
2025-07-11 14:01:20 +08:00
|
|
|
|
const generatedColumns = generateDynamicColumns(data.items);
|
2025-07-10 10:52:19 +08:00
|
|
|
|
console.log('生成的列定义:', generatedColumns);
|
2025-07-11 13:51:31 +08:00
|
|
|
|
|
2025-07-10 11:47:50 +08:00
|
|
|
|
// 更新动态列
|
|
|
|
|
|
dynamicColumns.value = generatedColumns;
|
2025-07-11 13:51:31 +08:00
|
|
|
|
|
2025-07-10 11:47:50 +08:00
|
|
|
|
// 使用setState更新整个gridOptions,确保列定义能够正确更新
|
|
|
|
|
|
await nextTick();
|
|
|
|
|
|
gridApi.setState({
|
|
|
|
|
|
gridOptions: {
|
|
|
|
|
|
...gridOptions,
|
|
|
|
|
|
columns: allColumns.value,
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
2025-07-11 13:51:31 +08:00
|
|
|
|
|
2025-07-11 14:01:20 +08:00
|
|
|
|
// 直接使用接口返回的totalCount
|
2025-07-11 13:51:31 +08:00
|
|
|
|
const result = {
|
|
|
|
|
|
items: data.items || [],
|
2025-07-11 14:01:20 +08:00
|
|
|
|
totalCount: data.totalCount || 0,
|
2025-07-11 13:51:31 +08:00
|
|
|
|
};
|
2025-07-14 08:57:04 +08:00
|
|
|
|
|
2025-07-11 13:51:31 +08:00
|
|
|
|
console.log('返回给表格的数据:', result);
|
2025-07-14 08:57:04 +08:00
|
|
|
|
console.log(
|
|
|
|
|
|
'总数:',
|
|
|
|
|
|
result.totalCount,
|
|
|
|
|
|
'当前页数据量:',
|
|
|
|
|
|
result.items.length,
|
|
|
|
|
|
);
|
2025-07-11 13:51:31 +08:00
|
|
|
|
console.log('分页信息:', {
|
|
|
|
|
|
currentPage: page.currentPage,
|
2025-07-11 14:01:20 +08:00
|
|
|
|
pageSize: page.pageSize,
|
2025-07-11 13:51:31 +08:00
|
|
|
|
});
|
2025-07-14 08:57:04 +08:00
|
|
|
|
|
2025-07-11 13:51:31 +08:00
|
|
|
|
return result;
|
2025-07-10 15:33:21 +08:00
|
|
|
|
}
|
2025-07-11 13:51:31 +08:00
|
|
|
|
|
2025-07-10 10:52:19 +08:00
|
|
|
|
console.log('没有数据或数据为空');
|
2025-07-10 11:47:50 +08:00
|
|
|
|
return {
|
|
|
|
|
|
items: [],
|
|
|
|
|
|
totalCount: 0,
|
|
|
|
|
|
};
|
2025-07-10 10:52:19 +08:00
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('API调用出错:', error);
|
|
|
|
|
|
throw error;
|
2025-07-10 10:28:06 +08:00
|
|
|
|
}
|
2025-06-25 17:29:57 +08:00
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-07-10 10:28:06 +08:00
|
|
|
|
const [Grid, gridApi] = useVbenVxeGrid({ formOptions, gridOptions });
|
2025-07-10 15:33:21 +08:00
|
|
|
|
|
|
|
|
|
|
// 监听分页器状态变化
|
2025-07-11 13:51:31 +08:00
|
|
|
|
watch(
|
|
|
|
|
|
() => gridApi?.pagerApi?.currentPage,
|
|
|
|
|
|
(newPage, oldPage) => {
|
|
|
|
|
|
console.log('当前页变化:', { newPage, oldPage });
|
|
|
|
|
|
},
|
|
|
|
|
|
);
|
2025-07-10 15:33:21 +08:00
|
|
|
|
|
2025-07-11 13:51:31 +08:00
|
|
|
|
watch(
|
|
|
|
|
|
() => gridApi?.pagerApi?.pageSize,
|
|
|
|
|
|
(newSize, oldSize) => {
|
|
|
|
|
|
console.log('页面大小变化:', { newSize, oldSize });
|
|
|
|
|
|
if (newSize !== oldSize && oldSize) {
|
|
|
|
|
|
console.log('页面大小从', oldSize, '变为', newSize, ',重置到第一页');
|
|
|
|
|
|
// 重置到第一页
|
|
|
|
|
|
gridApi.pagerApi.currentPage = 1;
|
2025-07-10 15:33:21 +08:00
|
|
|
|
}
|
2025-07-11 13:51:31 +08:00
|
|
|
|
},
|
|
|
|
|
|
);
|
2025-06-25 17:29:57 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
|
<Page auto-content-height>
|
|
|
|
|
|
<Grid />
|
|
|
|
|
|
</Page>
|
|
|
|
|
|
</template>
|