onenetlog

This commit is contained in:
ChenYi 2025-07-17 10:50:47 +08:00
parent 8609e3198a
commit b706f70e06
2 changed files with 231 additions and 45 deletions

View File

@ -3,6 +3,7 @@ import type { VbenFormProps } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table'; import type { VxeGridProps } from '#/adapter/vxe-table';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import { ref, nextTick, watch } from 'vue';
import { Page } from '@vben/common-ui'; import { Page } from '@vben/common-ui';
@ -10,6 +11,7 @@ import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { postOneNETLogInfoPage } from '#/api-client'; import { postOneNETLogInfoPage } from '#/api-client';
import { querySchema, tableSchema } from './schema'; import { querySchema, tableSchema } from './schema';
import DeviceSelect from '../deviceData/DeviceSelect.vue';
defineOptions({ defineOptions({
name: 'OneNETLog', name: 'OneNETLog',
@ -17,9 +19,24 @@ defineOptions({
const route = useRoute(); const route = useRoute();
const { DeviceType, DeviceId, FocusAddress } = route.query; const { DeviceType, DeviceId, FocusAddress } = route.query;
//
const deviceSelectRef = ref();
//
const selectedDeviceInfo = ref<any>(null);
//
const formatDate = (date: any) => {
if (!date) return '';
if (typeof date === 'string') return date;
if (date.toISOString) return date.format('YYYY-MM-DD HH:mm:ss');
return '';
};
const formOptions: VbenFormProps = { const formOptions: VbenFormProps = {
schema: querySchema.value, schema: querySchema.value,
}; };
const gridOptions: VxeGridProps<any> = { const gridOptions: VxeGridProps<any> = {
checkboxConfig: { checkboxConfig: {
highlight: true, highlight: true,
@ -28,7 +45,12 @@ const gridOptions: VxeGridProps<any> = {
columns: tableSchema.value, columns: tableSchema.value,
height: 'auto', height: 'auto',
keepSource: true, keepSource: true,
pagerConfig: {}, pagerConfig: {
currentPage: 1,
pageSize: 10,
pageSizes: [10, 20, 100],
layouts: ['PrevPage', 'JumpNumber', 'NextPage', 'FullJump', 'Sizes', 'Total'],
},
toolbarConfig: { toolbarConfig: {
custom: true, custom: true,
}, },
@ -38,27 +60,43 @@ const gridOptions: VxeGridProps<any> = {
proxyConfig: { proxyConfig: {
ajax: { ajax: {
query: async ({ page }, formValues) => { query: async ({ page }, formValues) => {
//
let deviceId = '';
let systemName = '';
let deviceType = formValues?.DeviceType || '';
if (deviceSelectRef.value) {
const deviceInfo = deviceSelectRef.value.getSelectedDevice();
if (deviceInfo) {
systemName = deviceInfo.systemName || '';
// 10focusIdmeterId
if (Number(deviceType) === 10) {
deviceId = deviceInfo.focusId || '';
} else {
deviceId = deviceInfo.meterId || '';
}
}
}
// deviceInfo退DeviceId
if (!deviceId) {
deviceId = formValues?.DeviceId || '';
}
// //
const queryParams: any = { const queryParams: any = {
pageIndex: page.currentPage, pageIndex: page.currentPage,
pageSize: page.pageSize, pageSize: page.pageSize,
SearchKeyword: formValues?.SearchKeyword || '',
DeviceType: deviceType,
IoTDataType: formValues?.IoTDataType || '',
DeviceId: deviceId,
SystemName: systemName || formValues?.SystemName || '',
StartCreationTime: formatDate(formValues?.StartCreationTime),
EndCreationTime: formatDate(formValues?.EndCreationTime),
}; };
//
if (formValues) {
Object.assign(queryParams, formValues);
}
//
if (DeviceType) queryParams.DeviceType = DeviceType; if (DeviceType) queryParams.DeviceType = DeviceType;
if (DeviceId) queryParams.DeviceId = DeviceId; if (DeviceId) queryParams.DeviceId = DeviceId;
if (FocusAddress) queryParams.FocusAddress = FocusAddress;
const { data } = await postOneNETLogInfoPage({ const { data } = await postOneNETLogInfoPage({
body: queryParams, body: queryParams,
}); });
// totalCount
const result = { const result = {
items: data.items || [], items: data.items || [],
totalCount: data.totalCount || (data.items ? data.items.length : 0), totalCount: data.totalCount || (data.items ? data.items.length : 0),
@ -69,11 +107,48 @@ const gridOptions: VxeGridProps<any> = {
}, },
}; };
const [Grid] = useVbenVxeGrid({ formOptions, gridOptions }); const [Grid, gridApi] = useVbenVxeGrid({ formOptions, gridOptions });
//
watch(
() => gridApi?.pagerApi?.pageSize,
(newSize, oldSize) => {
if (newSize !== oldSize && oldSize) {
gridApi.pagerApi.currentPage = 1;
gridApi.reload();
}
},
);
//
watch(
() => gridApi?.pagerApi?.currentPage,
(newPage, oldPage) => {
if (newPage !== oldPage && oldPage) {
gridApi.reload();
}
},
);
// DeviceId
watch(
() => gridApi?.getFormModel?.()?.DeviceId,
(newVal, oldVal) => {
if (newVal !== oldVal) {
gridApi.reload();
}
},
);
</script> </script>
<template> <template>
<Page auto-content-height> <Page auto-content-height>
<Grid /> <Grid>
<template #DeviceId="{ model, field }"> <DeviceSelect
ref="deviceSelectRef"
v-model:value="model[field]"
:placeholder="$t('common.pleaseSelect') + $t('abp.log.deviceInfo')"
allow-clear
/>
</template>
</Grid>
</Page> </Page>
</template> </template>

View File

@ -4,86 +4,193 @@ import { computed } from 'vue';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import { getSelectResultList } from '#/api-client';
import { $t } from '#/locales'; import { $t } from '#/locales';
export const querySchema = computed(() => [ export const querySchema = computed(() => [
{ {
component: 'Input', component: 'ApiSelect',
fieldName: 'FocusAddress', fieldName: 'SystemName',
label: $t('abp.OneNETLog.FocusAddress'), label: $t('abp.IoTDBBase.SystemName'),
componentProps: {
api: getSelectResultList,
params: {
query: {
TypeName: 'BusinessSystemEnum',
},
},
labelField: 'secondValue',
valueField: 'value',
optionsPropName: 'options',
immediate: true,
afterFetch: (res: any) => {
// 确保返回的是数组格式
if (Array.isArray(res)) {
return res;
}
// 如果是包装在 items 中的,提取出来
if (res && Array.isArray(res.items)) {
return res.items;
}
// 如果是包装在 data 中的,提取出来
if (res && Array.isArray(res.data)) {
return res.data;
}
// 如果都不是,返回空数组
return [];
},
},
}, },
{ {
component: 'Input', component: 'ApiSelect',
fieldName: 'DeviceId',
label: $t('abp.IoTDBBase.DeviceId'),
},
{
component: 'Input',
fieldName: 'DeviceType', fieldName: 'DeviceType',
label: $t('abp.IoTDBBase.DeviceType'), label: $t('abp.IoTDBBase.DeviceType'),
componentProps: {
api: getSelectResultList,
params: {
query: {
TypeName: 'MeterTypeEnum',
},
},
labelField: 'value',
valueField: 'key',
optionsPropName: 'options',
immediate: true,
afterFetch: (res: any) => {
// 确保返回的是数组格式
if (Array.isArray(res)) {
return res;
}
// 如果是包装在 items 中的,提取出来
if (res && Array.isArray(res.items)) {
return res.items;
}
// 如果是包装在 data 中的,提取出来
if (res && Array.isArray(res.data)) {
return res.data;
}
// 如果都不是,返回空数组
return [];
},
},
}, },
{ {
component: 'Input', component: 'ApiSelect',
fieldName: 'ProductId', fieldName: 'IoTDataType',
label: $t('abp.OneNETLog.ProductId'), label: $t('abp.IoTDBBase.IoTDataType'),
componentProps: {
api: getSelectResultList,
params: {
query: {
TypeName: 'IoTDBDataTypeConst',
},
},
labelField: 'value',
valueField: 'key',
optionsPropName: 'options',
immediate: true,
afterFetch: (res: any) => {
// 确保返回的是数组格式
if (Array.isArray(res)) {
return res;
}
// 如果是包装在 items 中的,提取出来
if (res && Array.isArray(res.items)) {
return res.items;
}
// 如果是包装在 data 中的,提取出来
if (res && Array.isArray(res.data)) {
return res.data;
}
// 如果都不是,返回空数组
return [];
},
},
}, },
{ {
component: 'Input', component: 'DeviceSelect',
fieldName: 'PlatformDeviceId', fieldName: 'DeviceId',
label: $t('abp.OneNETLog.PlatformDeviceId'), label: $t('abp.log.deviceInfo'),
componentProps: {
placeholder: $t('common.pleaseSelect') + $t('abp.log.deviceInfo'),
allowClear: true,
},
},
// 新增开始时间选择器
{
component: 'DatePicker',
fieldName: 'StartCreationTime',
label: '开始时间',
componentProps: {
placeholder: '开始时间',
format: 'YYYY-MM-DD HH:mm:ss',
showTime: true,
allowClear: true,
},
},
// 新增结束时间选择器
{
component: 'DatePicker',
fieldName: 'EndCreationTime',
label: '结束时间',
componentProps: {
placeholder: '结束时间',
format: 'YYYY-MM-DD HH:mm:ss',
showTime: true,
allowClear: true,
},
}, },
]); ]);
export const tableSchema: any = computed((): VxeGridProps['columns'] => [ export const tableSchema: any = computed((): VxeGridProps['columns'] => [
{ title: $t('common.seq'), type: 'seq', width: 50 }, { title: $t('common.seq'), type: 'seq', width: 50, slots: {} },
{ {
field: 'timestamps', field: 'timestamps',
title: $t('abp.IoTDBBase.Timestamps'), title: $t('abp.IoTDBBase.Timestamps'),
minWidth: '150', minWidth: '150',
slots: {},
}, },
{ {
field: 'systemName', field: 'systemName',
title: $t('abp.IoTDBBase.SystemName'), title: $t('abp.IoTDBBase.SystemName'),
minWidth: '120', minWidth: '120',
slots: {},
}, },
{ field: 'projectId', title: $t('abp.IoTDBBase.ProjectId'), minWidth: '120' },
{ {
field: 'deviceType', field: 'deviceType',
title: $t('abp.IoTDBBase.DeviceType'), title: $t('abp.IoTDBBase.DeviceType'),
minWidth: '120', minWidth: '120',
slots: {},
}, },
{ {
field: 'ioTDataType', field: 'ioTDataType',
title: $t('abp.IoTDBBase.IoTDataType'), title: $t('abp.IoTDBBase.IoTDataType'),
minWidth: '120', minWidth: '120',
slots: {},
}, },
{ field: 'deviceId', title: $t('abp.IoTDBBase.DeviceId'), minWidth: '120' },
{ field: 'productId', title: $t('abp.OneNETLog.ProductId'), minWidth: '120' },
{ {
field: 'platformDeviceId', field: 'deviceId',
title: $t('abp.OneNETLog.PlatformDeviceId'), title: $t('abp.IoTDBBase.DeviceId'),
minWidth: '150', minWidth: '120',
slots: {},
}, },
{ {
field: 'messageType', field: 'messageType',
title: $t('abp.OneNETLog.MessageType'), title: $t('abp.OneNETLog.MessageType'),
minWidth: '120', minWidth: '120',
}, slots: {},
{ field: 'protocol', title: $t('abp.OneNETLog.Protocol'), minWidth: '100' },
{
field: 'focusAddress',
title: $t('abp.OneNETLog.FocusAddress'),
minWidth: '120',
}, },
{ {
field: 'meterAddress', field: 'protocol',
title: $t('abp.OneNETLog.MeterAddress'), title: $t('abp.OneNETLog.Protocol'),
minWidth: '120', minWidth: '100',
slots: {},
}, },
{ {
field: 'receivedTime', field: 'receivedTime',
title: $t('abp.OneNETLog.ReceivedTime'), title: $t('abp.OneNETLog.ReceivedTime'),
minWidth: '150', minWidth: '150',
slots: {},
formatter: ({ cellValue }) => { formatter: ({ cellValue }) => {
return cellValue ? dayjs(cellValue).format('YYYY-MM-DD HH:mm:ss') : ''; return cellValue ? dayjs(cellValue).format('YYYY-MM-DD HH:mm:ss') : '';
}, },
@ -92,20 +199,24 @@ export const tableSchema: any = computed((): VxeGridProps['columns'] => [
field: 'isEncrypted', field: 'isEncrypted',
title: $t('abp.OneNETLog.IsEncrypted'), title: $t('abp.OneNETLog.IsEncrypted'),
minWidth: '200', minWidth: '200',
slots: {},
}, },
{ {
field: 'plaintextMessage', field: 'plaintextMessage',
title: $t('abp.OneNETLog.PlaintextMessage'), title: $t('abp.OneNETLog.PlaintextMessage'),
minWidth: '200', minWidth: '200',
slots: {},
}, },
{ {
field: 'rawMessage', field: 'rawMessage',
title: $t('abp.OneNETLog.RawMessage'), title: $t('abp.OneNETLog.RawMessage'),
minWidth: '200', minWidth: '200',
slots: {},
}, },
{ {
field: 'receivedPayload', field: 'receivedPayload',
title: $t('abp.OneNETLog.ReceivedPayload'), title: $t('abp.OneNETLog.ReceivedPayload'),
minWidth: '200', minWidth: '200',
slots: {},
}, },
]); ]);