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';
|
|
|
|
|
|
|
|
|
|
import { useRoute } from 'vue-router';
|
2025-07-10 10:28:06 +08:00
|
|
|
import { nextTick, watch, ref, computed } from 'vue';
|
2025-06-25 17:29:57 +08:00
|
|
|
|
|
|
|
|
import { Page } from '@vben/common-ui';
|
|
|
|
|
|
|
|
|
|
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
2025-07-09 17:07:25 +08:00
|
|
|
import { postTreeModelDeviceDataInfoPage } from '#/api-client';
|
2025-06-25 17:29:57 +08:00
|
|
|
|
|
|
|
|
import { querySchema, tableSchema } from './schema';
|
2025-07-10 10:28:06 +08:00
|
|
|
import { generateDynamicColumns } from './dynamicColumns';
|
|
|
|
|
import { handleStandardIoTDBData, validateAndCleanData } from './example';
|
2025-06-25 17:29:57 +08:00
|
|
|
|
|
|
|
|
defineOptions({
|
2025-07-09 17:07:25 +08:00
|
|
|
name: 'DeviceData',
|
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[]>([]);
|
|
|
|
|
|
|
|
|
|
// 固定列定义(始终显示)
|
|
|
|
|
const fixedColumns = computed(() => [
|
|
|
|
|
{ title: '序号', type: 'seq', width: 50 },
|
|
|
|
|
// 可以在这里添加其他固定列
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// 合并固定列和动态列
|
2025-07-10 10:36:02 +08:00
|
|
|
const allColumns = computed(() => {
|
|
|
|
|
const columns = [
|
|
|
|
|
...fixedColumns.value,
|
|
|
|
|
...dynamicColumns.value,
|
|
|
|
|
];
|
|
|
|
|
console.log('当前所有列定义:', columns);
|
|
|
|
|
return columns;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 初始化默认列(防止表格空白)
|
|
|
|
|
const initDefaultColumns = () => {
|
|
|
|
|
if (dynamicColumns.value.length === 0) {
|
|
|
|
|
dynamicColumns.value = [
|
|
|
|
|
{ field: 'SystemName', title: '系统名称', minWidth: '150' },
|
|
|
|
|
{ field: 'DeviceType', title: '设备类型', minWidth: '150' },
|
|
|
|
|
{ field: 'DeviceId', title: '设备ID', minWidth: '150' },
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 初始化默认列
|
|
|
|
|
initDefaultColumns();
|
2025-07-10 10:28:06 +08:00
|
|
|
|
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-10 10:28:06 +08:00
|
|
|
// 禁用表单值变化时自动提交,使用自定义处理函数
|
|
|
|
|
submitOnChange: false,
|
|
|
|
|
// 添加表单值变化的处理函数
|
|
|
|
|
handleValuesChange: async (values, changedFields) => {
|
|
|
|
|
// 当系统类型发生变化时,刷新表格数据
|
|
|
|
|
if (changedFields.includes('SystemName')) {
|
|
|
|
|
console.log('SystemName changed, values:', values);
|
|
|
|
|
console.log('Changed fields:', changedFields);
|
|
|
|
|
|
|
|
|
|
// 使用 setTimeout 确保表单值已经完全更新
|
|
|
|
|
setTimeout(async () => {
|
|
|
|
|
const latestValues = await gridApi.formApi.getValues();
|
|
|
|
|
console.log('Latest values after timeout:', latestValues);
|
|
|
|
|
gridApi.reload(latestValues);
|
|
|
|
|
}, 0);
|
|
|
|
|
}
|
|
|
|
|
},
|
2025-06-25 17:29:57 +08:00
|
|
|
};
|
|
|
|
|
const gridOptions: VxeGridProps<any> = {
|
|
|
|
|
checkboxConfig: {
|
|
|
|
|
highlight: true,
|
|
|
|
|
labelField: 'name',
|
|
|
|
|
},
|
2025-07-10 10:28:06 +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-06-25 17:29:57 +08:00
|
|
|
toolbarConfig: {
|
|
|
|
|
custom: true,
|
2025-07-09 17:07:25 +08:00
|
|
|
search: true,
|
2025-06-25 17:29:57 +08:00
|
|
|
},
|
|
|
|
|
customConfig: {
|
|
|
|
|
storage: true,
|
|
|
|
|
},
|
|
|
|
|
proxyConfig: {
|
|
|
|
|
ajax: {
|
|
|
|
|
query: async ({ page }, formValues) => {
|
2025-07-09 17:07:25 +08:00
|
|
|
const { data } = await postTreeModelDeviceDataInfoPage({
|
2025-06-25 17:29:57 +08:00
|
|
|
body: {
|
|
|
|
|
...formValues,
|
|
|
|
|
pageIndex: page.currentPage,
|
|
|
|
|
pageSize: page.pageSize,
|
|
|
|
|
DeviceType,
|
|
|
|
|
DeviceId,
|
|
|
|
|
FocusAddress,
|
|
|
|
|
},
|
|
|
|
|
});
|
2025-07-10 10:28:06 +08:00
|
|
|
|
2025-07-10 10:36:02 +08:00
|
|
|
console.log('API返回的原始数据:', data);
|
|
|
|
|
|
|
|
|
|
// 简化处理逻辑,先确保基本功能正常
|
2025-07-10 10:28:06 +08:00
|
|
|
if (data?.items && data.items.length > 0) {
|
2025-07-10 10:36:02 +08:00
|
|
|
console.log('原始items数据:', data.items);
|
|
|
|
|
|
|
|
|
|
// 直接使用原始数据,不进行复杂处理
|
|
|
|
|
const items = data.items;
|
2025-07-10 10:28:06 +08:00
|
|
|
|
|
|
|
|
// 动态生成列定义
|
2025-07-10 10:36:02 +08:00
|
|
|
const generatedColumns = generateDynamicColumns(items);
|
|
|
|
|
console.log('生成的列定义:', generatedColumns);
|
|
|
|
|
|
|
|
|
|
// 更新动态列
|
|
|
|
|
dynamicColumns.value = generatedColumns;
|
|
|
|
|
|
|
|
|
|
// 强制更新列定义
|
|
|
|
|
await nextTick();
|
2025-07-10 10:28:06 +08:00
|
|
|
|
2025-07-10 10:36:02 +08:00
|
|
|
console.log('返回给表格的数据:', data);
|
|
|
|
|
return data;
|
2025-07-10 10:28:06 +08:00
|
|
|
}
|
|
|
|
|
|
2025-07-10 10:36:02 +08:00
|
|
|
console.log('没有数据或数据为空');
|
2025-06-25 17:29:57 +08:00
|
|
|
return data;
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
2025-07-10 10:28:06 +08:00
|
|
|
const [Grid, gridApi] = useVbenVxeGrid({ formOptions, gridOptions });
|
2025-06-25 17:29:57 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<Page auto-content-height>
|
|
|
|
|
<Grid />
|
|
|
|
|
</Page>
|
|
|
|
|
</template>
|