设备数据查看优化

This commit is contained in:
ChenYi 2025-08-01 15:40:26 +08:00
parent fa8a4c9cc7
commit b4530f1360
4 changed files with 80 additions and 39 deletions

View File

@ -229,15 +229,12 @@ function onDel(row: any) {
}, },
}); });
} }
const toStatusData = (row: Record<string, any>) => { const toDeviceInfoData = (row: Record<string, any>) => {
// 使 // 使
router.push({ router.push({
path: '/iotdb/deviceData', path: '/iotdbdatamanagement/deviceData',
query: { query: {
DeviceType: row.ioTPlatform, DeviceAddress: row.deviceAddress,
DeviceId: row.deviceAddress,
FocusAddress: row.ioTPlatformDeviceOpenInfo,
DataBaseName: row.deviceName,
}, },
}); });
}; };
@ -359,7 +356,7 @@ const toolbarActions = computed(() => [
type: 'link', type: 'link',
size: 'small', size: 'small',
auth: ['AbpIdentity.Users.Update'], auth: ['AbpIdentity.Users.Update'],
onClick: toStatusData.bind(null, row), onClick: toDeviceInfoData.bind(null, row),
}, },
]" :drop-down-actions="[ ]" :drop-down-actions="[
{ {

View File

@ -68,7 +68,7 @@ const formatDate = (date: Date | string) => {
}; };
const route = useRoute(); const route = useRoute();
const { DeviceType, DeviceId } = route.query; const { DeviceType, DeviceAddress } = route.query;
// //
const dynamicColumns = ref<any[]>([]); const dynamicColumns = ref<any[]>([]);
@ -146,6 +146,8 @@ const initDefaultColumns = () => {
// //
const isGridInitialized = ref(false); const isGridInitialized = ref(false);
//
const isInitializing = ref(false);
// //
initDefaultColumns(); initDefaultColumns();
@ -154,12 +156,17 @@ const formOptions: VbenFormProps = {
schema: querySchema.value, schema: querySchema.value,
initialValues: { initialValues: {
DeviceType: DeviceType ? Number(DeviceType) : undefined, DeviceType: DeviceType ? Number(DeviceType) : undefined,
DeviceAddress: DeviceId as string, // 使DeviceIdDeviceAddress DeviceAddress: DeviceAddress as string, // 使DeviceAddress
}, },
// 使 // 使
submitOnChange: false, submitOnChange: false,
// //
handleValuesChange: async (values, changedFields) => { handleValuesChange: async (values, changedFields) => {
//
if (isInitializing.value) {
return;
}
// //
const relevantFields = new Set([ const relevantFields = new Set([
'DeviceAddress', 'DeviceAddress',
@ -266,6 +273,11 @@ const gridOptions: VxeGridProps<any> = {
formValues || formValues ||
(gridApi?.formApi ? await gridApi.formApi.getValues() : {}) || (gridApi?.formApi ? await gridApi.formApi.getValues() : {}) ||
{}; {};
// DeviceAddress使
if (!currentFormValues.DeviceAddress && DeviceAddress) {
currentFormValues.DeviceAddress = DeviceAddress as string;
}
// DeviceTypeIoTDataType // DeviceTypeIoTDataType
const deviceTypeValue = currentFormValues.DeviceType; const deviceTypeValue = currentFormValues.DeviceType;
const deviceTypeNumber = deviceTypeValue const deviceTypeNumber = deviceTypeValue
@ -285,11 +297,16 @@ const gridOptions: VxeGridProps<any> = {
// //
let deviceAddress = currentFormValues.DeviceAddress || ''; let deviceAddress = currentFormValues.DeviceAddress || '';
// DeviceAddress使
if (!deviceAddress && DeviceAddress) {
deviceAddress = DeviceAddress as string;
}
// 使 // 使
const deviceInfo = const deviceInfo =
selectedDeviceInfo.value || selectedDeviceInfo.value ||
(currentFormValues.DeviceAddress && deviceOptions.value.length > 0 (deviceAddress && deviceOptions.value.length > 0
? getDeviceInfoByAddress(currentFormValues.DeviceAddress) ? getDeviceInfoByAddress(deviceAddress)
: null); : null);
if (deviceInfo) { if (deviceInfo) {
@ -365,7 +382,7 @@ const [Grid, gridApi] = useVbenVxeGrid({ formOptions, gridOptions });
watch( watch(
() => gridApi?.pagerApi?.pageSize, () => gridApi?.pagerApi?.pageSize,
(newSize, oldSize) => { (newSize, oldSize) => {
if (newSize !== oldSize && oldSize) { if (newSize !== oldSize && oldSize && !isInitializing.value) {
// //
gridApi.pagerApi.currentPage = 1; gridApi.pagerApi.currentPage = 1;
// //
@ -378,7 +395,7 @@ watch(
watch( watch(
() => gridApi?.pagerApi?.currentPage, () => gridApi?.pagerApi?.currentPage,
(newPage, oldPage) => { (newPage, oldPage) => {
if (newPage !== oldPage && oldPage) { if (newPage !== oldPage && oldPage && !isInitializing.value) {
// //
gridApi.reload(); gridApi.reload();
} }
@ -388,6 +405,9 @@ watch(
// //
const initializeGrid = async () => { const initializeGrid = async () => {
try { try {
//
isInitializing.value = true;
// //
await fetchDeviceOptions(); await fetchDeviceOptions();
@ -409,23 +429,47 @@ const initializeGrid = async () => {
} }
// //
if (DeviceType || DeviceId) { if (DeviceType || DeviceAddress) {
// //
setTimeout(async () => {
if (gridApi && gridApi.formApi) {
//
const currentValues = await gridApi.formApi.getValues();
if (!currentValues.DeviceAddress && DeviceAddress) {
await gridApi.formApi.setValues({
...currentValues,
DeviceAddress: DeviceAddress as string,
});
}
//
setTimeout(() => { setTimeout(() => {
if (gridApi) { isInitializing.value = false;
//
gridApi.reload(); gridApi.reload();
}, 200);
} else {
isInitializing.value = false;
} }
}, 300); }, 300);
} else {
//
isInitializing.value = false;
} }
} catch (error) { } catch (error) {
console.error('初始化表格失败:', error); console.error('初始化表格失败:', error);
isInitializing.value = false;
} }
}; };
// //
watch( watch(
() => [DeviceType, DeviceId], () => [DeviceType, DeviceAddress],
async (newValues, oldValues) => { async (newValues, oldValues) => {
//
if (isInitializing.value) {
return;
}
// //
if (newValues.some(Boolean) && gridApi && isGridInitialized.value) { if (newValues.some(Boolean) && gridApi && isGridInitialized.value) {
// //