设备日志数据查看

This commit is contained in:
ChenYi 2025-08-01 16:01:58 +08:00
parent b4530f1360
commit b501552616
8 changed files with 201 additions and 54 deletions

View File

@ -97,7 +97,8 @@
"receivedMessageHexString": "Received Message (Hex)",
"receivedTime": "Received Time",
"isReceived": "Received Status",
"receivedRemark": "Report Parsing Remarks"
"receivedRemark": "Report Parsing Remarks",
"title": "Title"
},
"message": {
"title": "Title",

View File

@ -97,7 +97,8 @@
"receivedMessageHexString": "消息上报内容",
"receivedTime": "消息上报时间",
"isReceived": "是否已上报",
"receivedRemark": "上报报文解析备注"
"receivedRemark": "上报报文解析备注",
"title": "日志"
},
"message": {
"title": "标题",

View File

@ -238,6 +238,27 @@ const toDeviceInfoData = (row: Record<string, any>) => {
},
});
};
const toDeviceLog = (row: Record<string, any>) => {
//
if (row.ioTPlatform === 1 || row.ioTPlatform === '1') {
// CTWing
router.push({
path: '/iotdbdatamanagement/ctwingLog',
query: {
DeviceAddress: row.deviceAddress,
},
});
} else if (row.ioTPlatform === 2 || row.ioTPlatform === '2') {
// OneNET
router.push({
path: '/iotdbdatamanagement/onenetLog',
query: {
DeviceAddress: row.deviceAddress,
},
});
}
};
const openAddModal = async () => {
editRow.value = {};
userModalApi.open();
@ -358,6 +379,13 @@ const toolbarActions = computed(() => [
auth: ['AbpIdentity.Users.Update'],
onClick: toDeviceInfoData.bind(null, row),
},
{
label: $t('abp.log.title'),
type: 'link',
size: 'small',
auth: ['AbpIdentity.Users.Update'],
onClick: toDeviceLog.bind(null, row),
},
]" :drop-down-actions="[
{
label: $t('common.delete'),

View File

@ -83,7 +83,7 @@ export const tableSchema: any = computed((): VxeGridProps['columns'] => [
title: $t('common.action'),
field: 'action',
fixed: 'right',
width: '150',
width: '165',
slots: { default: 'action' },
},
]);
@ -105,7 +105,8 @@ export const addDeviceFormSchema: any = computed(() => [
optionsPropName: 'options',
immediate: true,
allowClear: true,
placeholder: $t('common.pleaseSelect') + $t('abp.deviceInfos.ioTPlatform'),
placeholder:
$t('common.pleaseSelect') + $t('abp.deviceInfos.ioTPlatform'),
afterFetch: (res: any) => {
// 确保返回的是数组格式
if (Array.isArray(res)) {

View File

@ -19,7 +19,10 @@ defineOptions({
});
const route = useRoute();
const { DeviceType, DeviceId, FocusAddress } = route.query;
const { DeviceAddress } = route.query;
//
const isInitializing = ref(false);
//
const deviceSelectRef = ref();
@ -48,13 +51,13 @@ const fetchDeviceOptions = async () => {
}
};
// ID
const getDeviceInfoById = (deviceId: string) => {
if (!deviceId || !deviceOptions.value || deviceOptions.value.length === 0) {
//
const getDeviceInfoByAddress = (deviceAddress: string) => {
if (!deviceAddress || !deviceOptions.value || deviceOptions.value.length === 0) {
return null;
}
const device = deviceOptions.value.find((device) => device.id === deviceId);
const device = deviceOptions.value.find((device) => device.deviceAddress === deviceAddress);
return device;
};
@ -80,19 +83,27 @@ const getDeviceInfoFromRef = async () => {
const formOptions: VbenFormProps = {
schema: querySchema.value,
initialValues: {
DeviceAddress: DeviceAddress as string,
},
// 使
submitOnChange: false,
//
handleValuesChange: async (values, changedFields) => {
// DeviceId selectedDeviceInfo
if (changedFields.includes('DeviceId')) {
const deviceId = values.DeviceId;
//
if (isInitializing.value) {
return;
}
if (deviceId) {
// DeviceAddress selectedDeviceInfo
if (changedFields.includes('DeviceAddress')) {
const deviceAddress = values.DeviceAddress;
if (deviceAddress) {
// deviceOptions
let device =
deviceOptions.value.length > 0
? deviceOptions.value.find((d) => d.id === deviceId)
? deviceOptions.value.find((d) => d.deviceAddress === deviceAddress)
: null;
// DeviceSelect
@ -100,7 +111,7 @@ const formOptions: VbenFormProps = {
try {
// DeviceSelect
const deviceSelectRef =
gridApi.formApi.getFieldComponentRef('DeviceId');
gridApi.formApi.getFieldComponentRef('DeviceAddress');
if (deviceSelectRef && deviceSelectRef.getSelectedDevice) {
device = deviceSelectRef.getSelectedDevice();
}
@ -116,7 +127,7 @@ const formOptions: VbenFormProps = {
setTimeout(() => {
try {
const deviceSelectRef =
gridApi.formApi.getFieldComponentRef('DeviceId');
gridApi.formApi.getFieldComponentRef('DeviceAddress');
if (deviceSelectRef && deviceSelectRef.getSelectedDevice) {
const delayedDevice = deviceSelectRef.getSelectedDevice();
if (delayedDevice) {
@ -135,7 +146,7 @@ const formOptions: VbenFormProps = {
//
const relevantFields = new Set([
'DeviceId',
'DeviceAddress',
'EndCreationTime',
'IoTDataType',
'StartCreationTime',
@ -180,14 +191,19 @@ const gridOptions: VxeGridProps<any> = {
// API
const currentFormValues = gridApi?.formApi ? await gridApi.formApi.getValues() : {};
// DeviceAddress使
if (!currentFormValues.DeviceAddress && DeviceAddress) {
currentFormValues.DeviceAddress = DeviceAddress as string;
}
//
let deviceAddress = currentFormValues.DeviceId || '';
let deviceAddress = currentFormValues.DeviceAddress || '';
// 使
const deviceInfo =
selectedDeviceInfo.value ||
(currentFormValues.DeviceId && deviceOptions.value.length > 0
? getDeviceInfoById(currentFormValues.DeviceId)
(deviceAddress && deviceOptions.value.length > 0
? getDeviceInfoByAddress(deviceAddress)
: null);
if (deviceInfo) {
@ -199,13 +215,11 @@ const gridOptions: VxeGridProps<any> = {
pageSize: page.pageSize,
SearchKeyword: currentFormValues.SearchKeyword || '',
IoTDataType: currentFormValues.IoTDataType || '',
DeviceId: deviceAddress, // 使
DeviceAddress: deviceAddress, // 使
StartCreationTime: formatDate(currentFormValues.StartCreationTime),
EndCreationTime: formatDate(currentFormValues.EndCreationTime),
};
if (DeviceType) queryParams.DeviceType = DeviceType;
if (DeviceId) queryParams.DeviceId = DeviceId;
const { data } = await postTableModelCtWingLogInfo({
body: queryParams,
});
@ -221,11 +235,52 @@ const gridOptions: VxeGridProps<any> = {
const [Grid, gridApi] = useVbenVxeGrid({ formOptions, gridOptions });
//
const initializeGrid = async () => {
try {
//
isInitializing.value = true;
//
await fetchDeviceOptions();
//
if (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(() => {
isInitializing.value = false;
gridApi.reload();
}, 200);
} else {
isInitializing.value = false;
}
}, 300);
} else {
//
isInitializing.value = false;
}
} catch (error) {
console.error('初始化表格失败:', error);
isInitializing.value = false;
}
};
//
watch(
() => gridApi?.pagerApi?.pageSize,
async (newSize, oldSize) => {
if (newSize !== oldSize && oldSize) {
if (newSize !== oldSize && oldSize && !isInitializing.value) {
//
gridApi.pagerApi.currentPage = 1;
//
@ -239,7 +294,7 @@ watch(
watch(
() => gridApi?.pagerApi?.currentPage,
async (newPage, oldPage) => {
if (newPage !== oldPage && oldPage) {
if (newPage !== oldPage && oldPage && !isInitializing.value) {
//
const latestValues = await gridApi.formApi.getValues();
gridApi.reload(latestValues);
@ -247,16 +302,19 @@ watch(
},
);
//
//
onMounted(async () => {
await fetchDeviceOptions();
// VXE
setTimeout(async () => {
await initializeGrid();
}, 100);
});
</script>
<template>
<Page auto-content-height>
<Grid>
<template #DeviceId="{ model, field }">
<template #DeviceAddress="{ model, field }">
<DeviceSelect ref="deviceSelectRef" v-model:value="model[field]"
:placeholder="$t('common.pleaseSelect') + $t('abp.log.deviceInfo')" allow-clear />
</template>

View File

@ -45,7 +45,7 @@ export const querySchema = computed(() => [
},
{
component: 'DeviceSelect',
fieldName: 'DeviceId',
fieldName: 'DeviceAddress',
label: $t('abp.log.deviceInfo'),
componentProps: {
placeholder: $t('common.pleaseSelect') + $t('abp.log.deviceInfo'),

View File

@ -19,7 +19,10 @@ defineOptions({
});
const route = useRoute();
const { DeviceType, DeviceId, FocusAddress } = route.query;
const { DeviceAddress } = route.query;
//
const isInitializing = ref(false);
//
const deviceSelectRef = ref();
@ -48,13 +51,13 @@ const fetchDeviceOptions = async () => {
}
};
// ID
const getDeviceInfoById = (deviceId: string) => {
if (!deviceId || !deviceOptions.value || deviceOptions.value.length === 0) {
//
const getDeviceInfoByAddress = (deviceAddress: string) => {
if (!deviceAddress || !deviceOptions.value || deviceOptions.value.length === 0) {
return null;
}
const device = deviceOptions.value.find((device) => device.id === deviceId);
const device = deviceOptions.value.find((device) => device.deviceAddress === deviceAddress);
return device;
};
@ -79,19 +82,27 @@ const getDeviceInfoFromRef = async () => {
const formOptions: VbenFormProps = {
schema: querySchema.value,
initialValues: {
DeviceAddress: DeviceAddress as string,
},
// 使
submitOnChange: false,
//
handleValuesChange: async (values, changedFields) => {
// DeviceId selectedDeviceInfo
if (changedFields.includes('DeviceId')) {
const deviceId = values.DeviceId;
//
if (isInitializing.value) {
return;
}
if (deviceId) {
// DeviceAddress selectedDeviceInfo
if (changedFields.includes('DeviceAddress')) {
const deviceAddress = values.DeviceAddress;
if (deviceAddress) {
// deviceOptions
let device =
deviceOptions.value.length > 0
? deviceOptions.value.find((d) => d.id === deviceId)
? deviceOptions.value.find((d) => d.deviceAddress === deviceAddress)
: null;
// DeviceSelect
@ -99,7 +110,7 @@ const formOptions: VbenFormProps = {
try {
// DeviceSelect
const deviceSelectRef =
gridApi.formApi.getFieldComponentRef('DeviceId');
gridApi.formApi.getFieldComponentRef('DeviceAddress');
if (deviceSelectRef && deviceSelectRef.getSelectedDevice) {
device = deviceSelectRef.getSelectedDevice();
}
@ -115,7 +126,7 @@ const formOptions: VbenFormProps = {
setTimeout(() => {
try {
const deviceSelectRef =
gridApi.formApi.getFieldComponentRef('DeviceId');
gridApi.formApi.getFieldComponentRef('DeviceAddress');
if (deviceSelectRef && deviceSelectRef.getSelectedDevice) {
const delayedDevice = deviceSelectRef.getSelectedDevice();
if (delayedDevice) {
@ -134,7 +145,7 @@ const formOptions: VbenFormProps = {
//
const relevantFields = new Set([
'DeviceId',
'DeviceAddress',
'EndCreationTime',
'IoTDataType',
'StartCreationTime',
@ -178,14 +189,19 @@ const gridOptions: VxeGridProps<any> = {
// API
const currentFormValues = gridApi?.formApi ? await gridApi.formApi.getValues() : {};
// DeviceAddress使
if (!currentFormValues.DeviceAddress && DeviceAddress) {
currentFormValues.DeviceAddress = DeviceAddress as string;
}
//
let deviceAddress = currentFormValues.DeviceId || '';
let deviceAddress = currentFormValues.DeviceAddress || '';
// 使
const deviceInfo =
selectedDeviceInfo.value ||
(currentFormValues.DeviceId && deviceOptions.value.length > 0
? getDeviceInfoById(currentFormValues.DeviceId)
(deviceAddress && deviceOptions.value.length > 0
? getDeviceInfoByAddress(deviceAddress)
: null);
if (deviceInfo) {
@ -198,13 +214,11 @@ const gridOptions: VxeGridProps<any> = {
pageSize: page.pageSize,
SearchKeyword: currentFormValues.SearchKeyword || '',
IoTDataType: currentFormValues.IoTDataType || '',
DeviceId: deviceAddress, // 使
DeviceAddress: deviceAddress, // 使
StartCreationTime: formatDate(currentFormValues.StartCreationTime),
EndCreationTime: formatDate(currentFormValues.EndCreationTime),
};
if (DeviceType) queryParams.DeviceType = DeviceType;
if (DeviceId) queryParams.DeviceId = DeviceId;
const { data } = await postTableModelOneNetLogInfo({
body: queryParams,
});
@ -220,11 +234,52 @@ const gridOptions: VxeGridProps<any> = {
const [Grid, gridApi] = useVbenVxeGrid({ formOptions, gridOptions });
//
const initializeGrid = async () => {
try {
//
isInitializing.value = true;
//
await fetchDeviceOptions();
//
if (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(() => {
isInitializing.value = false;
gridApi.reload();
}, 200);
} else {
isInitializing.value = false;
}
}, 300);
} else {
//
isInitializing.value = false;
}
} catch (error) {
console.error('初始化表格失败:', error);
isInitializing.value = false;
}
};
//
watch(
() => gridApi?.pagerApi?.pageSize,
async (newSize, oldSize) => {
if (newSize !== oldSize && oldSize) {
if (newSize !== oldSize && oldSize && !isInitializing.value) {
//
gridApi.pagerApi.currentPage = 1;
//
@ -238,7 +293,7 @@ watch(
watch(
() => gridApi?.pagerApi?.currentPage,
async (newPage, oldPage) => {
if (newPage !== oldPage && oldPage) {
if (newPage !== oldPage && oldPage && !isInitializing.value) {
//
const latestValues = await gridApi.formApi.getValues();
gridApi.reload(latestValues);
@ -246,16 +301,19 @@ watch(
},
);
//
//
onMounted(async () => {
await fetchDeviceOptions();
// VXE
setTimeout(async () => {
await initializeGrid();
}, 100);
});
</script>
<template>
<Page auto-content-height>
<Grid>
<template #DeviceId="{ model, field }">
<template #DeviceAddress="{ model, field }">
<DeviceSelect ref="deviceSelectRef" v-model:value="model[field]"
:placeholder="$t('common.pleaseSelect') + $t('abp.log.deviceInfo')" allow-clear />
</template>

View File

@ -45,7 +45,7 @@ export const querySchema = computed(() => [
},
{
component: 'DeviceSelect',
fieldName: 'DeviceId',
fieldName: 'DeviceAddress',
label: $t('abp.log.deviceInfo'),
componentProps: {
placeholder: $t('common.pleaseSelect') + $t('abp.log.deviceInfo'),