Compare commits

...

5 Commits

Author SHA1 Message Date
ChenYi
3d4b568a3b 修复错误 2025-07-16 17:08:11 +08:00
ChenYi
cd772d5b04 修复错误。 2025-07-16 17:05:52 +08:00
ChenYi
150c5a96f5 修复错误 2025-07-16 16:53:43 +08:00
ChenYi
ba7ebdb348 修复bug 2025-07-16 16:48:20 +08:00
ChenYi
92c14fe460 移除日志打印 2025-07-16 16:31:01 +08:00
4 changed files with 139 additions and 146 deletions

View File

@ -107,11 +107,9 @@ const handleValueChange = (value: string) => {
const selectedDevice = options.value.find(option => option.value === value); const selectedDevice = options.value.find(option => option.value === value);
if (selectedDevice) { if (selectedDevice) {
emit('device-change', selectedDevice); emit('device-change', selectedDevice);
console.log('DeviceSelect 发送设备信息:', selectedDevice);
} }
} else { } else {
emit('device-change', null); emit('device-change', null);
console.log('DeviceSelect 清空设备信息');
} }
}; };

View File

@ -52,20 +52,39 @@ export const generateDynamicColumns = (data: DynamicDeviceData[]): ColumnConfig[
return fields return fields
.filter(field => !excludeFields.includes(field)) .filter(field => !excludeFields.includes(field))
.map(field => { .map(field => {
const columnConfig: any = { // 确保字段名是有效的字符串
field, const safeField = String(field || '').trim();
title: fieldNameMapping[field] || field, if (!safeField) return null;
const columnConfig: ColumnConfig = {
field: safeField,
title: fieldNameMapping[safeField] || safeField,
minWidth: 150, minWidth: 150,
showOverflow: true, showOverflow: true,
slots: {}, // 添加空的slots属性避免VXE表格报错
}; };
// 应用字段类型配置 // 应用字段类型配置,确保配置是安全的
if (fieldTypeConfig[field]) { if (fieldTypeConfig[safeField]) {
Object.assign(columnConfig, fieldTypeConfig[field]); const typeConfig = fieldTypeConfig[safeField];
if (typeConfig.formatter && typeof typeConfig.formatter === 'function') {
columnConfig.formatter = typeConfig.formatter;
}
if (typeConfig.width !== undefined) {
columnConfig.width = typeConfig.width;
}
if (typeConfig.minWidth !== undefined) {
columnConfig.minWidth = typeConfig.minWidth;
}
// 确保slots属性始终存在
if (!columnConfig.slots) {
columnConfig.slots = {};
}
} }
return columnConfig; return columnConfig;
}); })
.filter(Boolean) as ColumnConfig[]; // 过滤掉null值
}; };
// 获取所有可能的字段(用于预定义列) // 获取所有可能的字段(用于预定义列)

View File

@ -26,7 +26,6 @@ const selectedDeviceInfo = ref<any>(null);
// ID // ID
const fetchDeviceOptions = async () => { const fetchDeviceOptions = async () => {
try { try {
console.log('开始获取设备信息...');
const { data } = await postMetersPage({ const { data } = await postMetersPage({
body: { body: {
pageIndex: 1, pageIndex: 1,
@ -36,10 +35,6 @@ const fetchDeviceOptions = async () => {
if (data?.items) { if (data?.items) {
deviceOptions.value = data.items; deviceOptions.value = data.items;
console.log('设备信息获取成功,总数:', data.items.length);
console.log('设备信息选项前3项:', deviceOptions.value.slice(0, 3));
} else {
console.log('设备信息为空');
} }
} catch (error) { } catch (error) {
console.error('获取设备信息失败:', error); console.error('获取设备信息失败:', error);
@ -48,6 +43,9 @@ const fetchDeviceOptions = async () => {
// ID // ID
const getDeviceInfoById = (deviceId: string) => { const getDeviceInfoById = (deviceId: string) => {
if (!deviceId || !deviceOptions.value || deviceOptions.value.length === 0) {
return null;
}
return deviceOptions.value.find((device) => device.id === deviceId); return deviceOptions.value.find((device) => device.id === deviceId);
}; };
@ -61,36 +59,58 @@ const dynamicColumns = ref<any[]>([]);
// - IoTDBTreeModelDeviceDataDto // - IoTDBTreeModelDeviceDataDto
const fixedColumns = [ const fixedColumns = [
{ title: '序号', type: 'seq', width: 50 }, { title: '序号', type: 'seq', width: 50, field: 'seq', slots: {} },
{ field: 'Timestamps', title: $t('abp.IoTDBBase.Timestamps'), minWidth: 150 }, { field: 'Timestamps', title: $t('abp.IoTDBBase.Timestamps'), minWidth: 150, showOverflow: true, slots: {} },
{ field: 'SystemName', title: $t('abp.IoTDBBase.SystemName'), minWidth: 150 }, { field: 'SystemName', title: $t('abp.IoTDBBase.SystemName'), minWidth: 150, showOverflow: true, slots: {} },
{ field: 'ProjectId', title: $t('abp.IoTDBBase.ProjectId'), minWidth: 150 }, { field: 'ProjectId', title: $t('abp.IoTDBBase.ProjectId'), minWidth: 150, showOverflow: true, slots: {} },
{ field: 'DeviceType', title: $t('abp.IoTDBBase.DeviceType'), minWidth: 150 }, { field: 'DeviceType', title: $t('abp.IoTDBBase.DeviceType'), minWidth: 150, showOverflow: true, slots: {} },
{ {
field: 'IoTDataType', field: 'IoTDataType',
title: $t('abp.IoTDBBase.IoTDataType'), title: $t('abp.IoTDBBase.IoTDataType'),
minWidth: 150, minWidth: 150,
showOverflow: true,
slots: {},
}, },
{ field: 'DeviceId', title: $t('abp.IoTDBBase.DeviceId'), minWidth: 150 }, { field: 'DeviceId', title: $t('abp.IoTDBBase.DeviceId'), minWidth: 150, showOverflow: true, slots: {} },
]; ];
// - 使 // - 使
const allColumns = computed(() => [...fixedColumns, ...dynamicColumns.value]); const allColumns = computed(() => {
//
if (!isGridInitialized.value) {
return [...fixedColumns];
}
const columns = [...fixedColumns];
//
if (dynamicColumns.value && Array.isArray(dynamicColumns.value)) {
const validDynamicColumns = dynamicColumns.value.filter(col =>
col && typeof col === 'object' && col.field && col.title
).map(col => ({
...col,
slots: col.slots || {} // slots
}));
columns.push(...validDynamicColumns);
}
return columns;
});
// //
const initDefaultColumns = () => { const initDefaultColumns = () => {
if (dynamicColumns.value.length === 0) { // dynamicColumns
// if (!Array.isArray(dynamicColumns.value)) {
dynamicColumns.value = []; dynamicColumns.value = [];
} }
}; };
//
const isGridInitialized = ref(false);
// //
initDefaultColumns(); initDefaultColumns();
//
fetchDeviceOptions();
const formOptions: VbenFormProps = { const formOptions: VbenFormProps = {
schema: querySchema.value, schema: querySchema.value,
initialValues: { initialValues: {
@ -118,32 +138,27 @@ const formOptions: VbenFormProps = {
// DeviceIdselectedDeviceInfo // DeviceIdselectedDeviceInfo
if (changedFields.includes('DeviceId')) { if (changedFields.includes('DeviceId')) {
const deviceId = values.DeviceId; const deviceId = values.DeviceId;
console.log('DeviceId变化:', deviceId);
if (deviceId) { if (deviceId) {
// deviceOptions // deviceOptions
let device = deviceOptions.value.find(d => d.id === deviceId); let device = deviceOptions.value.length > 0 ? deviceOptions.value.find(d => d.id === deviceId) : null;
// DeviceSelect // DeviceSelect
if (!device && gridApi?.formApi) { if (!device && gridApi?.formApi) {
try { try {
// DeviceSelect // DeviceSelect
const deviceSelectRef = gridApi.formApi.getFieldComponentRef('DeviceId'); const deviceSelectRef = gridApi.formApi.getFieldComponentRef('DeviceId');
console.log('DeviceSelect组件实例:', deviceSelectRef);
if (deviceSelectRef && deviceSelectRef.getSelectedDevice) { if (deviceSelectRef && deviceSelectRef.getSelectedDevice) {
device = deviceSelectRef.getSelectedDevice(); device = deviceSelectRef.getSelectedDevice();
console.log('从DeviceSelect组件获取设备信息:', device);
} }
} catch (error) { } catch (error) {
console.log('无法从DeviceSelect组件获取设备信息:', error); //
} }
} }
if (device) { if (device) {
selectedDeviceInfo.value = device; selectedDeviceInfo.value = device;
console.log('同步设备信息成功:', device);
} else { } else {
console.log('未找到匹配的设备deviceId:', deviceId);
// //
setTimeout(() => { setTimeout(() => {
try { try {
@ -152,31 +167,22 @@ const formOptions: VbenFormProps = {
const delayedDevice = deviceSelectRef.getSelectedDevice(); const delayedDevice = deviceSelectRef.getSelectedDevice();
if (delayedDevice) { if (delayedDevice) {
selectedDeviceInfo.value = delayedDevice; selectedDeviceInfo.value = delayedDevice;
console.log('延迟获取设备信息成功:', delayedDevice);
} }
} }
} catch (error) { } catch (error) {
console.log('延迟获取设备信息失败:', error); //
} }
}, 100); }, 100);
} }
} else { } else {
selectedDeviceInfo.value = null; selectedDeviceInfo.value = null;
console.log('DeviceId为空清空selectedDeviceInfo');
} }
} }
if (hasRelevantChange) { if (hasRelevantChange) {
console.log('表单字段变化:', { values, changedFields });
console.log(
'相关字段变化:',
changedFields.filter((field) => relevantFields.has(field)),
);
// 使 setTimeout // 使 setTimeout
setTimeout(async () => { setTimeout(async () => {
const latestValues = await gridApi.formApi.getValues(); const latestValues = await gridApi.formApi.getValues();
console.log('最新表单值:', latestValues);
gridApi.reload(latestValues); gridApi.reload(latestValues);
}, 0); }, 0);
} }
@ -188,7 +194,7 @@ const gridOptions: VxeGridProps<any> = {
highlight: true, highlight: true,
labelField: 'name', labelField: 'name',
}, },
columns: allColumns, // 使 columns: fixedColumns, // 使
height: 'auto', height: 'auto',
keepSource: true, keepSource: true,
pagerConfig: { pagerConfig: {
@ -196,10 +202,8 @@ const gridOptions: VxeGridProps<any> = {
pageSize: 20, pageSize: 20,
// //
onChange: (currentPage: number, pageSize: number) => { onChange: (currentPage: number, pageSize: number) => {
console.log('分页变化:', { currentPage, pageSize });
// pageSize // pageSize
if (pageSize !== gridOptions.pagerConfig.pageSize) { if (pageSize !== gridOptions.pagerConfig.pageSize) {
console.log('页面大小变化,重置到第一页');
// pageSize // pageSize
gridOptions.pagerConfig.pageSize = pageSize; gridOptions.pagerConfig.pageSize = pageSize;
gridOptions.pagerConfig.currentPage = 1; gridOptions.pagerConfig.currentPage = 1;
@ -218,7 +222,6 @@ const gridOptions: VxeGridProps<any> = {
proxyConfig: { proxyConfig: {
ajax: { ajax: {
query: async ({ page }, formValues) => { query: async ({ page }, formValues) => {
console.log('=== API调用开始 ===');
// DeviceTypeIoTDataType // DeviceTypeIoTDataType
const deviceTypeValue = formValues.DeviceType || DeviceType; const deviceTypeValue = formValues.DeviceType || DeviceType;
const deviceTypeNumber = deviceTypeValue const deviceTypeNumber = deviceTypeValue
@ -227,38 +230,27 @@ const gridOptions: VxeGridProps<any> = {
const ioTDataTypeValue = formValues.IoTDataType; const ioTDataTypeValue = formValues.IoTDataType;
console.log('=== API调用开始 ===2', ioTDataTypeValue);
// DeviceId(10)使focusId // DeviceId(10)使focusId
let finalDeviceId = formValues.DeviceId || DeviceId; let finalDeviceId = formValues.DeviceId || DeviceId || '';
let finalFocusAddress = formValues.FocusAddress; let finalFocusAddress = formValues.FocusAddress || '';
// 使 // 使
console.log('API调用时的selectedDeviceInfo:', selectedDeviceInfo.value); const deviceInfo = selectedDeviceInfo.value || (formValues.DeviceId && deviceOptions.value.length > 0 ? getDeviceInfoById(formValues.DeviceId) : null);
console.log('API调用时的formValues.DeviceId:', formValues.DeviceId);
const deviceInfo = selectedDeviceInfo.value || (formValues.DeviceId ? getDeviceInfoById(formValues.DeviceId) : null);
console.log('最终使用的deviceInfo:', deviceInfo);
if (deviceInfo) { if (deviceInfo) {
finalFocusAddress = deviceInfo.focusAddress; finalFocusAddress = deviceInfo.focusAddress || '';
console.log('使用focusAddress:', finalFocusAddress);
if (deviceTypeNumber === 10) { if (deviceTypeNumber === 10) {
// 使focusId // 使focusId
if (deviceInfo.focusId) { if (deviceInfo.focusId) {
finalDeviceId = deviceInfo.focusId; finalDeviceId = deviceInfo.focusId;
console.log('集中器类型使用focusId:', finalDeviceId);
} }
} else { } else {
// 使meterId // 使meterId
if (deviceInfo.meterId) { if (deviceInfo.meterId) {
finalDeviceId = deviceInfo.meterId; finalDeviceId = deviceInfo.meterId;
console.log('其他类型使用meterId:', finalDeviceId);
} }
} }
} else {
console.log('没有找到设备信息使用原始DeviceId:', finalDeviceId);
} }
try { try {
const { data } = await postTreeModelDeviceDataInfoPage({ const { data } = await postTreeModelDeviceDataInfoPage({
@ -266,59 +258,41 @@ const gridOptions: VxeGridProps<any> = {
pageIndex: page.currentPage, pageIndex: page.currentPage,
pageSize: page.pageSize, pageSize: page.pageSize,
// 使使 // 使使
DeviceType: deviceTypeNumber, DeviceType: deviceTypeNumber || undefined,
DeviceId: finalDeviceId.toString(), DeviceId: finalDeviceId ? finalDeviceId.toString() : '',
FocusAddress: finalFocusAddress || FocusAddress, FocusAddress: finalFocusAddress || FocusAddress || '',
// //
SystemName: formValues.SystemName || SystemName, SystemName: formValues.SystemName || SystemName || '',
IoTDataType: ioTDataTypeValue, IoTDataType: ioTDataTypeValue || undefined,
}, },
}); });
console.log('API返回的原始数据:', data);
console.log('数据类型:', typeof data);
console.log(
'data是否为null/undefined:',
data === null || data === undefined,
);
if (data) {
console.log('data.items存在:', !!data.items);
console.log(
'data.items类型:',
Array.isArray(data.items) ? 'Array' : typeof data.items,
);
if (data.items) {
console.log('data.items长度:', data.items.length);
if (data.items.length > 0) {
console.log('第一条数据:', data.items[0]);
console.log(
'第一条数据的所有字段:',
Object.keys(data.items[0]),
);
}
}
}
// 使 // 使
if (data?.items && data.items.length > 0) { if (data?.items && data.items.length > 0) {
console.log('原始items数据:', data.items); try {
//
const generatedColumns = generateDynamicColumns(data.items);
// //
const generatedColumns = generateDynamicColumns(data.items); dynamicColumns.value = generatedColumns;
console.log('生成的列定义:', generatedColumns);
// // 使setStategridOptions
dynamicColumns.value = generatedColumns; await nextTick();
if (gridApi && gridApi.setState) {
// 使setStategridOptions gridApi.setState({
await nextTick(); gridOptions: {
gridApi.setState({ ...gridOptions,
gridOptions: { columns: allColumns.value,
...gridOptions, },
columns: allColumns.value, });
}, }
}); } catch (error) {
console.error('更新列定义时出错:', error);
// 使
dynamicColumns.value = [];
}
// 使totalCount // 使totalCount
const result = { const result = {
@ -326,22 +300,8 @@ const gridOptions: VxeGridProps<any> = {
totalCount: data.totalCount || 0, totalCount: data.totalCount || 0,
}; };
console.log('返回给表格的数据:', result);
console.log(
'总数:',
result.totalCount,
'当前页数据量:',
result.items.length,
);
console.log('分页信息:', {
currentPage: page.currentPage,
pageSize: page.pageSize,
});
return result; return result;
} }
console.log('没有数据或数据为空');
return { return {
items: [], items: [],
totalCount: 0, totalCount: 0,
@ -358,57 +318,71 @@ const gridOptions: VxeGridProps<any> = {
const [Grid, gridApi] = useVbenVxeGrid({ formOptions, gridOptions }); const [Grid, gridApi] = useVbenVxeGrid({ formOptions, gridOptions });
// //
watch(
() => gridApi?.pagerApi?.currentPage,
(newPage, oldPage) => {
console.log('当前页变化:', { newPage, oldPage });
},
);
watch( watch(
() => gridApi?.pagerApi?.pageSize, () => gridApi?.pagerApi?.pageSize,
(newSize, oldSize) => { (newSize, oldSize) => {
console.log('页面大小变化:', { newSize, oldSize });
if (newSize !== oldSize && oldSize) { if (newSize !== oldSize && oldSize) {
console.log('页面大小从', oldSize, '变为', newSize, ',重置到第一页');
// //
gridApi.pagerApi.currentPage = 1; gridApi.pagerApi.currentPage = 1;
} }
}, },
); );
//
const initializeGrid = async () => {
try {
//
await fetchDeviceOptions();
//
isGridInitialized.value = true;
//
if (gridApi && gridApi.setState) {
await nextTick();
gridApi.setState({
gridOptions: {
...gridOptions,
columns: allColumns.value,
},
});
}
//
if (DeviceType || DeviceId || FocusAddress || SystemName) {
//
setTimeout(() => {
if (gridApi) {
gridApi.reload();
}
}, 300);
}
} catch (error) {
console.error('初始化表格失败:', error);
}
};
// //
watch( watch(
() => [DeviceType, DeviceId, FocusAddress, SystemName], () => [DeviceType, DeviceId, FocusAddress, SystemName],
async (newValues, oldValues) => { async (newValues, oldValues) => {
console.log('路由参数变化:', { newValues, oldValues });
// //
if (newValues.some(val => val) && gridApi) { if (newValues.some(val => val) && gridApi && isGridInitialized.value) {
//
await fetchDeviceOptions();
// //
setTimeout(() => { setTimeout(() => {
console.log('自动触发查询,路由参数:', { DeviceType, DeviceId, FocusAddress, SystemName });
gridApi.reload(); gridApi.reload();
}, 100); }, 100);
} }
}, },
{ immediate: true } { immediate: false } // false
); );
// //
onMounted(async () => { onMounted(async () => {
console.log('页面挂载完成,检查路由参数:', { DeviceType, DeviceId, FocusAddress, SystemName }); // VXE
// setTimeout(async () => {
if (DeviceType || DeviceId || FocusAddress || SystemName) { await initializeGrid();
// }, 100);
await fetchDeviceOptions();
//
setTimeout(() => {
console.log('页面初始化时自动触发查询');
gridApi.reload();
}, 200);
}
}); });
</script> </script>

View File

@ -30,6 +30,7 @@ export interface ColumnConfig {
width?: string | number; width?: string | number;
showOverflow?: boolean; showOverflow?: boolean;
formatter?: (value: any) => string; formatter?: (value: any) => string;
slots?: Record<string, any>; // 添加slots属性
[key: string]: any; [key: string]: any;
} }
@ -44,6 +45,7 @@ export interface FieldTypeConfig {
formatter?: (value: any) => string; formatter?: (value: any) => string;
width?: string | number; width?: string | number;
minWidth?: string | number; minWidth?: string | number;
slots?: Record<string, any>;
[key: string]: any; [key: string]: any;
}; };
} }