Compare commits
No commits in common. "180718974d3ee06465ff11d873024f510980efe2" and "8b24e4219e6dcc8c8c67078b6489bb9ff1a36196" have entirely different histories.
180718974d
...
8b24e4219e
@ -8,7 +8,7 @@ import { useRoute } from 'vue-router';
|
||||
import { Page } from '@vben/common-ui';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { postCTWingLogInfoPage, postMetersPage } from '#/api-client';
|
||||
import { postMetersPage, postCTWingLogInfoPage } from '#/api-client';
|
||||
|
||||
import DeviceSelect from '../deviceData/DeviceSelect.vue';
|
||||
import { querySchema, tableSchema } from './schema';
|
||||
@ -52,7 +52,7 @@ const getDeviceInfoById = (deviceId: string) => {
|
||||
if (!deviceId || !deviceOptions.value || deviceOptions.value.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
const device = deviceOptions.value.find((device) => device.id === deviceId);
|
||||
return device;
|
||||
};
|
||||
@ -86,43 +86,38 @@ const formOptions: VbenFormProps = {
|
||||
// 当 DeviceId 发生变化时,更新 selectedDeviceInfo
|
||||
if (changedFields.includes('DeviceId')) {
|
||||
const deviceId = values.DeviceId;
|
||||
|
||||
|
||||
if (deviceId) {
|
||||
// 先尝试从 deviceOptions 中查找(备用方案)
|
||||
let device =
|
||||
deviceOptions.value.length > 0
|
||||
? deviceOptions.value.find((d) => d.id === deviceId)
|
||||
: null;
|
||||
|
||||
let device = deviceOptions.value.length > 0 ? deviceOptions.value.find(d => d.id === deviceId) : null;
|
||||
|
||||
// 如果没找到,尝试从 DeviceSelect 组件中获取
|
||||
if (!device && gridApi?.formApi) {
|
||||
try {
|
||||
// 获取 DeviceSelect 组件的实例
|
||||
const deviceSelectRef =
|
||||
gridApi.formApi.getFieldComponentRef('DeviceId');
|
||||
const deviceSelectRef = gridApi.formApi.getFieldComponentRef('DeviceId');
|
||||
if (deviceSelectRef && deviceSelectRef.getSelectedDevice) {
|
||||
device = deviceSelectRef.getSelectedDevice();
|
||||
}
|
||||
} catch {
|
||||
} catch (error) {
|
||||
// 静默处理错误
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (device) {
|
||||
selectedDeviceInfo.value = device;
|
||||
} else {
|
||||
// 如果还是没找到,尝试延迟获取(组件可能还没完全更新)
|
||||
setTimeout(() => {
|
||||
try {
|
||||
const deviceSelectRef =
|
||||
gridApi.formApi.getFieldComponentRef('DeviceId');
|
||||
const deviceSelectRef = gridApi.formApi.getFieldComponentRef('DeviceId');
|
||||
if (deviceSelectRef && deviceSelectRef.getSelectedDevice) {
|
||||
const delayedDevice = deviceSelectRef.getSelectedDevice();
|
||||
if (delayedDevice) {
|
||||
selectedDeviceInfo.value = delayedDevice;
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
} catch (error) {
|
||||
// 静默处理错误
|
||||
}
|
||||
}, 100);
|
||||
@ -131,15 +126,15 @@ const formOptions: VbenFormProps = {
|
||||
selectedDeviceInfo.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 当任何相关字段发生变化时,刷新表格数据
|
||||
const relevantFields = new Set([
|
||||
'DeviceId',
|
||||
'DeviceType',
|
||||
'EndCreationTime',
|
||||
'IoTDataType',
|
||||
'StartCreationTime',
|
||||
'SystemName',
|
||||
'StartCreationTime',
|
||||
'EndCreationTime',
|
||||
]);
|
||||
const hasRelevantChange = changedFields.some((field) =>
|
||||
relevantFields.has(field),
|
||||
@ -178,23 +173,19 @@ const gridOptions: VxeGridProps<any> = {
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
// 总是从表单API获取最新的表单值,确保分页时参数完整
|
||||
const currentFormValues = gridApi?.formApi ? await gridApi.formApi.getValues() : {};
|
||||
|
||||
// 获取当前表单值,如果formValues为空则从表单API获取
|
||||
const currentFormValues = formValues || (gridApi?.formApi ? await gridApi.formApi.getValues() : {}) || {};
|
||||
|
||||
// 获取选中的设备信息
|
||||
let deviceId = currentFormValues.DeviceId || '';
|
||||
let systemName = '';
|
||||
const deviceType = currentFormValues.DeviceType || '';
|
||||
|
||||
|
||||
// 优先使用选中的设备信息
|
||||
const deviceInfo =
|
||||
selectedDeviceInfo.value ||
|
||||
(currentFormValues.DeviceId && deviceOptions.value.length > 0
|
||||
? getDeviceInfoById(currentFormValues.DeviceId)
|
||||
: null);
|
||||
|
||||
const deviceInfo = selectedDeviceInfo.value || (currentFormValues.DeviceId && deviceOptions.value.length > 0 ? getDeviceInfoById(currentFormValues.DeviceId) : null);
|
||||
|
||||
if (deviceInfo) {
|
||||
systemName = deviceInfo.businessSystemName || '';
|
||||
systemName = deviceInfo.systemName || '';
|
||||
// 根据设备类型获取正确的 id
|
||||
if (Number(deviceType) === 10) {
|
||||
// 集中器类型使用 focusId
|
||||
@ -204,6 +195,7 @@ const gridOptions: VxeGridProps<any> = {
|
||||
deviceId = deviceInfo.meterId || deviceId;
|
||||
}
|
||||
}
|
||||
|
||||
// 构建查询参数
|
||||
const queryParams = {
|
||||
pageIndex: page.currentPage,
|
||||
@ -217,7 +209,7 @@ const gridOptions: VxeGridProps<any> = {
|
||||
EndCreationTime: formatDate(currentFormValues.EndCreationTime),
|
||||
FocusAddress: currentFormValues.FocusAddress || '',
|
||||
};
|
||||
|
||||
|
||||
if (DeviceType) queryParams.DeviceType = DeviceType;
|
||||
if (DeviceId) queryParams.DeviceId = DeviceId;
|
||||
const { data } = await postCTWingLogInfoPage({
|
||||
|
||||
@ -4,7 +4,7 @@ import { computed } from 'vue';
|
||||
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import { getSelectResultList } from '#/api-client';
|
||||
import { getSelectResultList, postMetersPage } from '#/api-client';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
export const querySchema = computed(() => [
|
||||
@ -150,20 +150,7 @@ export const tableSchema: any = computed((): VxeGridProps['columns'] => [
|
||||
minWidth: 150,
|
||||
slots: {},
|
||||
},
|
||||
{
|
||||
field: 'formattedTimestamps',
|
||||
title: $t('abp.IoTDBBase.FormattedTimestamps'),
|
||||
minWidth: '150',
|
||||
formatter: ({ cellValue }) => {
|
||||
return cellValue ? dayjs(cellValue).format('YYYY-MM-DD HH:mm:ss') : '';
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'systemName',
|
||||
title: $t('abp.IoTDBBase.SystemName'),
|
||||
minWidth: 150,
|
||||
slots: {},
|
||||
},
|
||||
{ field: 'systemName', title: $t('abp.IoTDBBase.SystemName'), minWidth: 150, slots: {} },
|
||||
{
|
||||
field: 'deviceType',
|
||||
title: $t('abp.IoTDBBase.DeviceType'),
|
||||
|
||||
@ -1,9 +1,4 @@
|
||||
import type {
|
||||
ColumnConfig,
|
||||
DynamicDeviceData,
|
||||
FieldMapping,
|
||||
FieldTypeConfig,
|
||||
} from './types';
|
||||
import type { FieldMapping, FieldTypeConfig, ColumnConfig, DynamicDeviceData } from './types';
|
||||
|
||||
// 字段名映射配置
|
||||
export const fieldNameMapping: FieldMapping = {
|
||||
@ -35,35 +30,32 @@ export const fieldTypeConfig: FieldTypeConfig = {
|
||||
// 固定字段列表 - 这些字段已经在固定列中定义,不需要在动态列中重复生成
|
||||
const FIXED_FIELDS = [
|
||||
'SystemName',
|
||||
'ProjectId',
|
||||
'ProjectId',
|
||||
'DeviceType',
|
||||
'IoTDataType',
|
||||
'DeviceId',
|
||||
'Timestamps',
|
||||
'FormattedTimestamps',
|
||||
'Timestamps'
|
||||
];
|
||||
|
||||
// 动态生成表格列
|
||||
export const generateDynamicColumns = (
|
||||
data: DynamicDeviceData[],
|
||||
): ColumnConfig[] => {
|
||||
export const generateDynamicColumns = (data: DynamicDeviceData[]): ColumnConfig[] => {
|
||||
if (!data || data.length === 0) return [];
|
||||
|
||||
|
||||
// 获取第一条数据的所有字段
|
||||
const firstRow = data[0];
|
||||
if (!firstRow) return [];
|
||||
const fields = Object.keys(firstRow);
|
||||
|
||||
|
||||
// 过滤掉不需要显示的字段和固定字段
|
||||
const excludeFields = new Set(['__typename', 'id', 'key', ...FIXED_FIELDS]);
|
||||
|
||||
const excludeFields = ['id', 'key', '__typename', ...FIXED_FIELDS];
|
||||
|
||||
return fields
|
||||
.filter((field) => !excludeFields.has(field))
|
||||
.map((field) => {
|
||||
.filter(field => !excludeFields.includes(field))
|
||||
.map(field => {
|
||||
// 确保字段名是有效的字符串
|
||||
const safeField = String(field || '').trim();
|
||||
if (!safeField) return null;
|
||||
|
||||
|
||||
const columnConfig: ColumnConfig = {
|
||||
field: safeField,
|
||||
title: fieldNameMapping[safeField] || safeField,
|
||||
@ -75,10 +67,7 @@ export const generateDynamicColumns = (
|
||||
// 应用字段类型配置,确保配置是安全的
|
||||
if (fieldTypeConfig[safeField]) {
|
||||
const typeConfig = fieldTypeConfig[safeField];
|
||||
if (
|
||||
typeConfig.formatter &&
|
||||
typeof typeConfig.formatter === 'function'
|
||||
) {
|
||||
if (typeConfig.formatter && typeof typeConfig.formatter === 'function') {
|
||||
columnConfig.formatter = typeConfig.formatter;
|
||||
}
|
||||
if (typeConfig.width !== undefined) {
|
||||
@ -105,11 +94,11 @@ export const getAllPossibleFields = () => {
|
||||
|
||||
// 预定义列配置(可选)
|
||||
export const getPredefinedColumns = () => {
|
||||
return getAllPossibleFields().map((field) => ({
|
||||
return getAllPossibleFields().map(field => ({
|
||||
field,
|
||||
title: fieldNameMapping[field] || field,
|
||||
minWidth: 150,
|
||||
showOverflow: true,
|
||||
...fieldTypeConfig[field],
|
||||
}));
|
||||
};
|
||||
};
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
import type { VbenFormProps } from '#/adapter/form';
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
|
||||
import { computed, nextTick, onMounted, ref, watch } from 'vue';
|
||||
import { computed, nextTick, ref, watch, onMounted } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
@ -52,20 +52,21 @@ const getDeviceInfoById = (deviceId: string) => {
|
||||
// 格式化日期为 yyyy-MM-dd HH:mm:ss 格式
|
||||
const formatDate = (date: Date | string) => {
|
||||
if (!date) return undefined;
|
||||
|
||||
|
||||
const d = new Date(date);
|
||||
if (isNaN(d.getTime())) return undefined;
|
||||
|
||||
|
||||
const year = d.getFullYear();
|
||||
const month = String(d.getMonth() + 1).padStart(2, '0');
|
||||
const month = String(d.getMonth() +1).padStart(2, '0');
|
||||
const day = String(d.getDate()).padStart(2, '0');
|
||||
const hours = String(d.getHours()).padStart(2, '0');
|
||||
const minutes = String(d.getMinutes()).padStart(2, '0');
|
||||
const seconds = String(d.getSeconds()).padStart(2, '0');
|
||||
|
||||
|
||||
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
||||
};
|
||||
|
||||
|
||||
const route = useRoute();
|
||||
const { DeviceType, DeviceId, FocusAddress, SystemName } = route.query;
|
||||
|
||||
@ -75,41 +76,11 @@ const dynamicColumns = ref<any[]>([]);
|
||||
// 固定列定义(始终显示)- 基于 IoTDBTreeModelDeviceDataDto 类型
|
||||
const fixedColumns = [
|
||||
{ title: '序号', type: 'seq', width: 50, field: 'seq', slots: {} },
|
||||
{
|
||||
field: 'Timestamps',
|
||||
title: $t('abp.IoTDBBase.Timestamps'),
|
||||
minWidth: 150,
|
||||
showOverflow: true,
|
||||
slots: {},
|
||||
},
|
||||
{
|
||||
field: 'FormattedTimestamps',
|
||||
title: $t('abp.IoTDBBase.FormattedTimestamps'),
|
||||
minWidth: 150,
|
||||
showOverflow: true,
|
||||
slots: {},
|
||||
},
|
||||
{
|
||||
field: 'SystemName',
|
||||
title: $t('abp.IoTDBBase.SystemName'),
|
||||
minWidth: 150,
|
||||
showOverflow: true,
|
||||
slots: {},
|
||||
},
|
||||
{
|
||||
field: 'ProjectId',
|
||||
title: $t('abp.IoTDBBase.ProjectId'),
|
||||
minWidth: 150,
|
||||
showOverflow: true,
|
||||
slots: {},
|
||||
},
|
||||
{
|
||||
field: 'DeviceType',
|
||||
title: $t('abp.IoTDBBase.DeviceType'),
|
||||
minWidth: 150,
|
||||
showOverflow: true,
|
||||
slots: {},
|
||||
},
|
||||
{ field: 'Timestamps', title: $t('abp.IoTDBBase.Timestamps'), minWidth: 150, showOverflow: true, slots: {} },
|
||||
{ field: 'FormattedTimestamps', title: $t('abp.IoTDBBase.FormattedTimestamps'), minWidth: 150, showOverflow: true, slots: {} },
|
||||
{ field: 'SystemName', title: $t('abp.IoTDBBase.SystemName'), minWidth: 150, showOverflow: true, slots: {} },
|
||||
{ field: 'ProjectId', title: $t('abp.IoTDBBase.ProjectId'), minWidth: 150, showOverflow: true, slots: {} },
|
||||
{ field: 'DeviceType', title: $t('abp.IoTDBBase.DeviceType'), minWidth: 150, showOverflow: true, slots: {} },
|
||||
{
|
||||
field: 'IoTDataType',
|
||||
title: $t('abp.IoTDBBase.IoTDataType'),
|
||||
@ -117,13 +88,7 @@ const fixedColumns = [
|
||||
showOverflow: true,
|
||||
slots: {},
|
||||
},
|
||||
{
|
||||
field: 'DeviceId',
|
||||
title: $t('abp.IoTDBBase.DeviceId'),
|
||||
minWidth: 150,
|
||||
showOverflow: true,
|
||||
slots: {},
|
||||
},
|
||||
{ field: 'DeviceId', title: $t('abp.IoTDBBase.DeviceId'), minWidth: 150, showOverflow: true, slots: {} },
|
||||
];
|
||||
|
||||
// 合并固定列和动态列 - 使用计算属性确保响应式
|
||||
@ -132,20 +97,20 @@ 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属性
|
||||
}));
|
||||
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;
|
||||
});
|
||||
|
||||
@ -179,11 +144,11 @@ const formOptions: VbenFormProps = {
|
||||
const relevantFields = new Set([
|
||||
'DeviceId',
|
||||
'DeviceType',
|
||||
'EndCreationTime',
|
||||
'FocusAddress',
|
||||
'IoTDataType',
|
||||
'StartCreationTime',
|
||||
'SystemName',
|
||||
'StartCreationTime',
|
||||
'EndCreationTime',
|
||||
]);
|
||||
const hasRelevantChange = changedFields.some((field) =>
|
||||
relevantFields.has(field),
|
||||
@ -192,43 +157,38 @@ const formOptions: VbenFormProps = {
|
||||
// 新增:DeviceId变化时同步selectedDeviceInfo
|
||||
if (changedFields.includes('DeviceId')) {
|
||||
const deviceId = values.DeviceId;
|
||||
|
||||
|
||||
if (deviceId) {
|
||||
// 先尝试从 deviceOptions 中查找(备用方案)
|
||||
let device =
|
||||
deviceOptions.value.length > 0
|
||||
? deviceOptions.value.find((d) => d.id === deviceId)
|
||||
: null;
|
||||
|
||||
let device = deviceOptions.value.length > 0 ? deviceOptions.value.find(d => d.id === deviceId) : null;
|
||||
|
||||
// 如果没找到,尝试从 DeviceSelect 组件中获取
|
||||
if (!device && gridApi?.formApi) {
|
||||
try {
|
||||
// 获取 DeviceSelect 组件的实例
|
||||
const deviceSelectRef =
|
||||
gridApi.formApi.getFieldComponentRef('DeviceId');
|
||||
const deviceSelectRef = gridApi.formApi.getFieldComponentRef('DeviceId');
|
||||
if (deviceSelectRef && deviceSelectRef.getSelectedDevice) {
|
||||
device = deviceSelectRef.getSelectedDevice();
|
||||
}
|
||||
} catch {
|
||||
} catch (error) {
|
||||
// 静默处理错误
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (device) {
|
||||
selectedDeviceInfo.value = device;
|
||||
} else {
|
||||
// 如果还是没找到,尝试延迟获取(组件可能还没完全更新)
|
||||
setTimeout(() => {
|
||||
try {
|
||||
const deviceSelectRef =
|
||||
gridApi.formApi.getFieldComponentRef('DeviceId');
|
||||
const deviceSelectRef = gridApi.formApi.getFieldComponentRef('DeviceId');
|
||||
if (deviceSelectRef && deviceSelectRef.getSelectedDevice) {
|
||||
const delayedDevice = deviceSelectRef.getSelectedDevice();
|
||||
if (delayedDevice) {
|
||||
selectedDeviceInfo.value = delayedDevice;
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
} catch (error) {
|
||||
// 静默处理错误
|
||||
}
|
||||
}, 100);
|
||||
@ -279,10 +239,7 @@ const gridOptions: VxeGridProps<any> = {
|
||||
return { items: [], totalCount: 0 };
|
||||
}
|
||||
// 获取当前表单值,如果formValues为空则从表单API获取
|
||||
const currentFormValues =
|
||||
formValues ||
|
||||
(gridApi?.formApi ? await gridApi.formApi.getValues() : {}) ||
|
||||
{};
|
||||
const currentFormValues = formValues || (gridApi?.formApi ? await gridApi.formApi.getValues() : {}) || {};
|
||||
// 处理DeviceType和IoTDataType,确保传递数字类型
|
||||
const deviceTypeValue = currentFormValues.DeviceType || DeviceType;
|
||||
const deviceTypeNumber = deviceTypeValue
|
||||
@ -292,27 +249,19 @@ const gridOptions: VxeGridProps<any> = {
|
||||
const ioTDataTypeValue = currentFormValues.IoTDataType;
|
||||
|
||||
// 处理日期范围参数
|
||||
const startCreationTime = currentFormValues.StartCreationTime
|
||||
? formatDate(currentFormValues.StartCreationTime)
|
||||
: undefined;
|
||||
const endCreationTime = currentFormValues.EndCreationTime
|
||||
? formatDate(currentFormValues.EndCreationTime)
|
||||
: undefined;
|
||||
const startCreationTime = currentFormValues.StartCreationTime ? formatDate(currentFormValues.StartCreationTime) : undefined;
|
||||
const endCreationTime = currentFormValues.EndCreationTime ? formatDate(currentFormValues.EndCreationTime) : undefined;
|
||||
|
||||
// 处理DeviceId,当设备类型为集中器(10)时,使用focusId
|
||||
let finalDeviceId = currentFormValues.DeviceId || DeviceId || '';
|
||||
let finalFocusAddress = currentFormValues.FocusAddress || '';
|
||||
|
||||
|
||||
// 优先使用选中的设备信息
|
||||
const deviceInfo =
|
||||
selectedDeviceInfo.value ||
|
||||
(currentFormValues.DeviceId && deviceOptions.value.length > 0
|
||||
? getDeviceInfoById(currentFormValues.DeviceId)
|
||||
: null);
|
||||
|
||||
const deviceInfo = selectedDeviceInfo.value || (currentFormValues.DeviceId && deviceOptions.value.length > 0 ? getDeviceInfoById(currentFormValues.DeviceId) : null);
|
||||
|
||||
if (deviceInfo) {
|
||||
finalFocusAddress = deviceInfo.focusAddress || '';
|
||||
|
||||
|
||||
if (deviceTypeNumber === 10) {
|
||||
// 集中器类型使用focusId
|
||||
if (deviceInfo.focusId) {
|
||||
@ -343,6 +292,8 @@ const gridOptions: VxeGridProps<any> = {
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
|
||||
// 简化处理逻辑,直接使用接口返回的数据
|
||||
if (data?.items && data.items.length > 0) {
|
||||
try {
|
||||
@ -423,10 +374,10 @@ const initializeGrid = async () => {
|
||||
try {
|
||||
// 获取设备信息数据
|
||||
await fetchDeviceOptions();
|
||||
|
||||
|
||||
// 标记表格已初始化
|
||||
isGridInitialized.value = true;
|
||||
|
||||
|
||||
// 更新表格列定义
|
||||
if (gridApi && gridApi.setState) {
|
||||
await nextTick();
|
||||
@ -440,7 +391,7 @@ const initializeGrid = async () => {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// 如果有路由参数,自动触发查询
|
||||
if (DeviceType || DeviceId || FocusAddress || SystemName) {
|
||||
// 延迟一下确保表格已完全初始化
|
||||
@ -460,14 +411,14 @@ watch(
|
||||
() => [DeviceType, DeviceId, FocusAddress, SystemName],
|
||||
async (newValues, oldValues) => {
|
||||
// 如果有路由参数,等待设备信息加载完成后自动触发查询
|
||||
if (newValues.some(Boolean) && gridApi && isGridInitialized.value) {
|
||||
if (newValues.some(val => val) && gridApi && isGridInitialized.value) {
|
||||
// 延迟一下确保表单值已经设置
|
||||
setTimeout(() => {
|
||||
gridApi.reload();
|
||||
}, 100);
|
||||
}
|
||||
},
|
||||
{ immediate: false }, // 改为false,避免立即触发
|
||||
{ immediate: false } // 改为false,避免立即触发
|
||||
);
|
||||
|
||||
// 页面初始化时,延迟初始化表格
|
||||
|
||||
@ -146,6 +146,11 @@ export const tableSchema: any = computed((): VxeGridProps['columns'] => [
|
||||
title: $t('abp.IoTDBBase.Timestamps'),
|
||||
minWidth: '150',
|
||||
},
|
||||
{
|
||||
field: 'FormattedTimestamps',
|
||||
title: $t('abp.IoTDBBase.FormattedTimestamps'),
|
||||
minWidth: '150',
|
||||
},
|
||||
{
|
||||
field: 'SystemName',
|
||||
title: $t('abp.IoTDBBase.SystemName'),
|
||||
|
||||
@ -52,7 +52,7 @@ const getDeviceInfoById = (deviceId: string) => {
|
||||
if (!deviceId || !deviceOptions.value || deviceOptions.value.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
const device = deviceOptions.value.find((device) => device.id === deviceId);
|
||||
return device;
|
||||
};
|
||||
@ -85,43 +85,38 @@ const formOptions: VbenFormProps = {
|
||||
// 当 DeviceId 发生变化时,更新 selectedDeviceInfo
|
||||
if (changedFields.includes('DeviceId')) {
|
||||
const deviceId = values.DeviceId;
|
||||
|
||||
|
||||
if (deviceId) {
|
||||
// 先尝试从 deviceOptions 中查找(备用方案)
|
||||
let device =
|
||||
deviceOptions.value.length > 0
|
||||
? deviceOptions.value.find((d) => d.id === deviceId)
|
||||
: null;
|
||||
|
||||
let device = deviceOptions.value.length > 0 ? deviceOptions.value.find(d => d.id === deviceId) : null;
|
||||
|
||||
// 如果没找到,尝试从 DeviceSelect 组件中获取
|
||||
if (!device && gridApi?.formApi) {
|
||||
try {
|
||||
// 获取 DeviceSelect 组件的实例
|
||||
const deviceSelectRef =
|
||||
gridApi.formApi.getFieldComponentRef('DeviceId');
|
||||
const deviceSelectRef = gridApi.formApi.getFieldComponentRef('DeviceId');
|
||||
if (deviceSelectRef && deviceSelectRef.getSelectedDevice) {
|
||||
device = deviceSelectRef.getSelectedDevice();
|
||||
}
|
||||
} catch {
|
||||
} catch (error) {
|
||||
// 静默处理错误
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (device) {
|
||||
selectedDeviceInfo.value = device;
|
||||
} else {
|
||||
// 如果还是没找到,尝试延迟获取(组件可能还没完全更新)
|
||||
setTimeout(() => {
|
||||
try {
|
||||
const deviceSelectRef =
|
||||
gridApi.formApi.getFieldComponentRef('DeviceId');
|
||||
const deviceSelectRef = gridApi.formApi.getFieldComponentRef('DeviceId');
|
||||
if (deviceSelectRef && deviceSelectRef.getSelectedDevice) {
|
||||
const delayedDevice = deviceSelectRef.getSelectedDevice();
|
||||
if (delayedDevice) {
|
||||
selectedDeviceInfo.value = delayedDevice;
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
} catch (error) {
|
||||
// 静默处理错误
|
||||
}
|
||||
}, 100);
|
||||
@ -130,15 +125,15 @@ const formOptions: VbenFormProps = {
|
||||
selectedDeviceInfo.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 当任何相关字段发生变化时,刷新表格数据
|
||||
const relevantFields = new Set([
|
||||
'DeviceId',
|
||||
'DeviceType',
|
||||
'EndCreationTime',
|
||||
'IoTDataType',
|
||||
'StartCreationTime',
|
||||
'SystemName',
|
||||
'StartCreationTime',
|
||||
'EndCreationTime',
|
||||
]);
|
||||
const hasRelevantChange = changedFields.some((field) =>
|
||||
relevantFields.has(field),
|
||||
@ -162,6 +157,7 @@ const gridOptions: VxeGridProps<any> = {
|
||||
columns: tableSchema.value,
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
// 确保分页功能正常工作
|
||||
pager: true,
|
||||
pagerConfig: {
|
||||
currentPage: 1,
|
||||
@ -176,23 +172,19 @@ const gridOptions: VxeGridProps<any> = {
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues) => {
|
||||
// 总是从表单API获取最新的表单值,确保分页时参数完整
|
||||
const currentFormValues = gridApi?.formApi ? await gridApi.formApi.getValues() : {};
|
||||
|
||||
// 获取当前表单值,如果formValues为空则从表单API获取
|
||||
const currentFormValues = formValues || (gridApi?.formApi ? await gridApi.formApi.getValues() : {}) || {};
|
||||
|
||||
// 获取选中的设备信息
|
||||
let deviceId = currentFormValues.DeviceId || '';
|
||||
let systemName = '';
|
||||
const deviceType = currentFormValues.DeviceType || '';
|
||||
|
||||
|
||||
// 优先使用选中的设备信息
|
||||
const deviceInfo =
|
||||
selectedDeviceInfo.value ||
|
||||
(currentFormValues.DeviceId && deviceOptions.value.length > 0
|
||||
? getDeviceInfoById(currentFormValues.DeviceId)
|
||||
: null);
|
||||
|
||||
const deviceInfo = selectedDeviceInfo.value || (currentFormValues.DeviceId && deviceOptions.value.length > 0 ? getDeviceInfoById(currentFormValues.DeviceId) : null);
|
||||
|
||||
if (deviceInfo) {
|
||||
systemName = deviceInfo.businessSystemName || '';
|
||||
systemName = deviceInfo.systemName || '';
|
||||
// 根据设备类型获取正确的 id
|
||||
if (Number(deviceType) === 10) {
|
||||
// 集中器类型使用 focusId
|
||||
@ -202,7 +194,7 @@ const gridOptions: VxeGridProps<any> = {
|
||||
deviceId = deviceInfo.meterId || deviceId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 构建查询参数
|
||||
const queryParams = {
|
||||
pageIndex: page.currentPage,
|
||||
@ -215,7 +207,7 @@ const gridOptions: VxeGridProps<any> = {
|
||||
StartCreationTime: formatDate(currentFormValues.StartCreationTime),
|
||||
EndCreationTime: formatDate(currentFormValues.EndCreationTime),
|
||||
};
|
||||
|
||||
|
||||
if (DeviceType) queryParams.DeviceType = DeviceType;
|
||||
if (DeviceId) queryParams.DeviceId = DeviceId;
|
||||
const { data } = await postOneNETLogInfoPage({
|
||||
@ -259,6 +251,7 @@ watch(
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
// 页面初始化时获取设备信息
|
||||
onMounted(async () => {
|
||||
await fetchDeviceOptions();
|
||||
|
||||
@ -150,14 +150,6 @@ export const tableSchema: any = computed((): VxeGridProps['columns'] => [
|
||||
minWidth: '150',
|
||||
slots: {},
|
||||
},
|
||||
{
|
||||
field: 'formattedTimestamps',
|
||||
title: $t('abp.IoTDBBase.FormattedTimestamps'),
|
||||
minWidth: '150',
|
||||
formatter: ({ cellValue }) => {
|
||||
return cellValue ? dayjs(cellValue).format('YYYY-MM-DD HH:mm:ss') : '';
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'systemName',
|
||||
title: $t('abp.IoTDBBase.SystemName'),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user