设备数据查询优化

This commit is contained in:
ChenYi 2025-07-31 17:34:07 +08:00
parent 67261b19c9
commit 6c1fdb7adb
5 changed files with 36 additions and 91 deletions

View File

@ -104,6 +104,8 @@ export const addDeviceFormSchema: any = computed(() => [
valueField: 'key',
optionsPropName: 'options',
immediate: true,
allowClear: true,
placeholder: $t('common.pleaseSelect') + $t('abp.deviceInfos.ioTPlatform'),
afterFetch: (res: any) => {
// 确保返回的是数组格式
if (Array.isArray(res)) {

View File

@ -23,6 +23,8 @@ export const querySchema = computed(() => [
valueField: 'key',
optionsPropName: 'options',
immediate: true,
allowClear: true,
placeholder: $t('common.pleaseSelect') + $t('abp.IoTDBBase.IoTDataType'),
afterFetch: (res: any) => {
// 确保返回的是数组格式
if (Array.isArray(res)) {

View File

@ -42,12 +42,12 @@ 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;
}
return deviceOptions.value.find((device) => device.id === deviceId);
return deviceOptions.value.find((device) => device.deviceAddress === deviceAddress);
};
// yyyy-MM-dd HH:mm:ss
@ -68,7 +68,7 @@ const formatDate = (date: Date | string) => {
};
const route = useRoute();
const { DeviceType, DeviceId, FocusAddress, DataBaseName } = route.query;
const { DeviceType, DeviceId } = route.query;
//
const dynamicColumns = ref<any[]>([]);
@ -90,13 +90,6 @@ const fixedColumns = [
showOverflow: true,
slots: {},
},
{
field: 'DataBaseName',
title: $t('abp.IoTDBBase.DataBaseName'),
minWidth: 150,
showOverflow: true,
slots: {},
},
{
field: 'DeviceType',
title: $t('abp.IoTDBBase.DeviceType'),
@ -160,10 +153,8 @@ initDefaultColumns();
const formOptions: VbenFormProps = {
schema: querySchema.value,
initialValues: {
FocusAddress: FocusAddress as string,
DeviceType: DeviceType ? Number(DeviceType) : undefined,
DeviceId: DeviceId as string,
DataBaseName: DataBaseName as string,
DeviceAddress: DeviceId as string, // 使DeviceIdDeviceAddress
},
// 使
submitOnChange: false,
@ -171,27 +162,25 @@ const formOptions: VbenFormProps = {
handleValuesChange: async (values, changedFields) => {
//
const relevantFields = new Set([
'DeviceId',
'DeviceAddress',
'DeviceType',
'EndCreationTime',
'FocusAddress',
'IoTDataType',
'StartCreationTime',
'DataBaseName',
]);
const hasRelevantChange = changedFields.some((field) =>
relevantFields.has(field),
);
// DeviceIdselectedDeviceInfo
if (changedFields.includes('DeviceId')) {
const deviceId = values.DeviceId;
// DeviceAddressselectedDeviceInfo
if (changedFields.includes('DeviceAddress')) {
const deviceAddress = values.DeviceAddress;
if (deviceId) {
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
@ -199,7 +188,7 @@ const formOptions: VbenFormProps = {
try {
// DeviceSelect
const deviceSelectRef =
gridApi.formApi.getFieldComponentRef('DeviceId');
gridApi.formApi.getFieldComponentRef('DeviceAddress');
if (deviceSelectRef && deviceSelectRef.getSelectedDevice) {
device = deviceSelectRef.getSelectedDevice();
}
@ -215,7 +204,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) {
@ -278,7 +267,7 @@ const gridOptions: VxeGridProps<any> = {
(gridApi?.formApi ? await gridApi.formApi.getValues() : {}) ||
{};
// DeviceTypeIoTDataType
const deviceTypeValue = currentFormValues.DeviceType || DeviceType;
const deviceTypeValue = currentFormValues.DeviceType;
const deviceTypeNumber = deviceTypeValue
? Number(deviceTypeValue)
: undefined;
@ -293,43 +282,27 @@ const gridOptions: VxeGridProps<any> = {
? formatDate(currentFormValues.EndCreationTime)
: undefined;
// DeviceId(10)使focusId
let finalDeviceId = currentFormValues.DeviceId || DeviceId || '';
let finalFocusAddress = currentFormValues.FocusAddress || '';
//
let deviceAddress = currentFormValues.DeviceAddress || '';
// 使
const deviceInfo =
selectedDeviceInfo.value ||
(currentFormValues.DeviceId && deviceOptions.value.length > 0
? getDeviceInfoById(currentFormValues.DeviceId)
(currentFormValues.DeviceAddress && deviceOptions.value.length > 0
? getDeviceInfoByAddress(currentFormValues.DeviceAddress)
: null);
if (deviceInfo) {
finalFocusAddress = deviceInfo.focusAddress || '';
if (deviceTypeNumber === 10) {
// 使focusId
if (deviceInfo.focusId) {
finalDeviceId = deviceInfo.focusId;
}
} else {
// 使meterId
if (deviceInfo.meterId) {
finalDeviceId = deviceInfo.meterId;
}
}
deviceAddress = deviceInfo.deviceAddress || deviceAddress;
}
try {
const { data } = await postTreeModelDeviceDataInfoPage({
body: {
pageIndex: page.currentPage,
pageSize: page.pageSize,
// 使使
// 使DeviceAddress
DeviceAddress: deviceAddress,
DeviceType: deviceTypeNumber || undefined,
DeviceId: finalDeviceId ? finalDeviceId.toString() : '',
FocusAddress: finalFocusAddress || FocusAddress || '',
//
DataBaseName: currentFormValues.DataBaseName || DataBaseName,
IoTDataType: ioTDataTypeValue || undefined,
//
StartCreationTime: startCreationTime || undefined,
@ -436,7 +409,7 @@ const initializeGrid = async () => {
}
//
if (DeviceType || DeviceId || FocusAddress || DataBaseName) {
if (DeviceType || DeviceId) {
//
setTimeout(() => {
if (gridApi) {
@ -451,7 +424,7 @@ const initializeGrid = async () => {
//
watch(
() => [DeviceType, DeviceId, FocusAddress, DataBaseName],
() => [DeviceType, DeviceId],
async (newValues, oldValues) => {
//
if (newValues.some(Boolean) && gridApi && isGridInitialized.value) {

View File

@ -6,39 +6,6 @@ import { getCommonGetSelectList } from '#/api-client';
import { $t } from '#/locales';
export const querySchema = computed(() => [
{
component: 'ApiSelect',
fieldName: 'DataBaseName',
label: $t('abp.IoTDBBase.DataBaseName'),
componentProps: {
api: getCommonGetSelectList,
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: 'ApiSelect',
fieldName: 'DeviceType',
@ -47,13 +14,15 @@ export const querySchema = computed(() => [
api: getCommonGetSelectList,
params: {
query: {
typeName: 'MeterTypeEnum',
typeName: 'DeviceTypeEnum',
},
},
labelField: 'value',
valueField: 'key',
optionsPropName: 'options',
immediate: true,
allowClear: true,
placeholder: $t('common.pleaseSelect') + $t('abp.IoTDBBase.DeviceType'),
afterFetch: (res: any) => {
// 确保返回的是数组格式
if (Array.isArray(res)) {
@ -87,6 +56,8 @@ export const querySchema = computed(() => [
valueField: 'key',
optionsPropName: 'options',
immediate: true,
allowClear: true,
placeholder: $t('common.pleaseSelect') + $t('abp.IoTDBBase.IoTDataType'),
afterFetch: (res: any) => {
// 确保返回的是数组格式
if (Array.isArray(res)) {
@ -107,7 +78,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'),
@ -146,11 +117,6 @@ export const tableSchema: any = computed((): VxeGridProps['columns'] => [
title: $t('abp.IoTDBBase.Timestamps'),
minWidth: '150',
},
{
field: 'DataBaseName',
title: $t('abp.IoTDBBase.DataBaseName'),
minWidth: '150',
},
{
field: 'DeviceType',
title: $t('abp.IoTDBBase.DeviceType'),

View File

@ -23,6 +23,8 @@ export const querySchema = computed(() => [
valueField: 'key',
optionsPropName: 'options',
immediate: true,
allowClear: true,
placeholder: $t('common.pleaseSelect') + $t('abp.IoTDBBase.IoTDataType'),
afterFetch: (res: any) => {
// 确保返回的是数组格式
if (Array.isArray(res)) {