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 },
|
|
|
|
|
// 可以在这里添加其他固定列
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// 合并固定列和动态列
|
|
|
|
|
const allColumns = computed(() => [
|
|
|
|
|
...fixedColumns.value,
|
|
|
|
|
...dynamicColumns.value,
|
|
|
|
|
]);
|
|
|
|
|
|
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,
|
|
|
|
|
pagerConfig: {},
|
|
|
|
|
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
|
|
|
|
|
|
|
|
// 处理数据并动态生成列定义
|
|
|
|
|
if (data?.items && data.items.length > 0) {
|
|
|
|
|
// 验证和清理数据
|
|
|
|
|
const cleanedData = validateAndCleanData(data.items);
|
|
|
|
|
|
|
|
|
|
// 动态生成列定义
|
|
|
|
|
dynamicColumns.value = generateDynamicColumns(cleanedData);
|
|
|
|
|
|
|
|
|
|
// 返回处理后的数据
|
|
|
|
|
return {
|
|
|
|
|
...data,
|
|
|
|
|
items: cleanedData,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
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>
|