Compare commits

..

5 Commits

Author SHA1 Message Date
ChenYi
a5781829e9 完善设备数据查询,优化get请求处理。 2025-07-14 11:43:20 +08:00
ChenYi
551323d5d1 完善设备数据跳转 2025-07-14 11:06:36 +08:00
ChenYi
6563b24045 完善设备数据查询 2025-07-14 10:32:02 +08:00
ChenYi
598f0d8399 可以正常发起请求 2025-07-14 09:09:44 +08:00
ChenYi
31c6a15aae 完善表单表头 2025-07-14 08:57:04 +08:00
4 changed files with 195 additions and 193 deletions

View File

@ -2,17 +2,22 @@
import type { VbenFormProps } from '#/adapter/form'; import type { VbenFormProps } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table'; import type { VxeGridProps } from '#/adapter/vxe-table';
import { computed, nextTick, ref, watch } from 'vue'; import { computed, nextTick, ref, watch, onMounted } from 'vue';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import { Page } from '@vben/common-ui'; import { Page } from '@vben/common-ui';
import { useVbenVxeGrid } from '#/adapter/vxe-table'; import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { postTreeModelDeviceDataInfoPage, postMetersPage } from '#/api-client'; import { postMetersPage, postTreeModelDeviceDataInfoPage } from '#/api-client';
import { $t } from '#/locales';
import { generateDynamicColumns } from './dynamicColumns'; import { generateDynamicColumns } from './dynamicColumns';
import { querySchema } from './schema'; import { querySchema } from './schema';
defineOptions({
name: 'DeviceData',
});
// //
const deviceOptions = ref<any[]>([]); const deviceOptions = ref<any[]>([]);
@ -25,7 +30,7 @@ const fetchDeviceOptions = async () => {
pageSize: 1000, pageSize: 1000,
}, },
}); });
if (data?.items) { if (data?.items) {
deviceOptions.value = data.items; deviceOptions.value = data.items;
console.log('设备信息选项:', deviceOptions.value); console.log('设备信息选项:', deviceOptions.value);
@ -37,30 +42,28 @@ const fetchDeviceOptions = async () => {
// ID // ID
const getDeviceInfoById = (deviceId: string) => { const getDeviceInfoById = (deviceId: string) => {
return deviceOptions.value.find(device => device.id === deviceId); return deviceOptions.value.find((device) => device.id === deviceId);
}; };
defineOptions({
name: 'DeviceData',
});
const route = useRoute(); const route = useRoute();
const { DeviceType, DeviceId, FocusAddress } = route.query; const { DeviceType, DeviceId, FocusAddress, SystemName } = route.query;
// //
const dynamicColumns = ref<any[]>([]); const dynamicColumns = ref<any[]>([]);
// - IoTDBTreeModelDeviceDataDto // - IoTDBTreeModelDeviceDataDto
const fixedColumns = [ const fixedColumns = [
{ title: '序号', type: 'seq', width: 50 }, { title: '序号', type: 'seq', width: 50 },
{ field: 'Timestamps', title: '时间戳', minWidth: 150 }, { field: 'Timestamps', title: $t('abp.IoTDBBase.Timestamps'), minWidth: 150 },
{ field: 'SystemName', title: '系统名称', minWidth: 150 }, { field: 'SystemName', title: $t('abp.IoTDBBase.SystemName'), minWidth: 150 },
{ field: 'ProjectId', title: '项目ID', minWidth: 150 }, { field: 'ProjectId', title: $t('abp.IoTDBBase.ProjectId'), minWidth: 150 },
{ field: 'DeviceType', title: '设备类型', minWidth: 150 }, { field: 'DeviceType', title: $t('abp.IoTDBBase.DeviceType'), minWidth: 150 },
{ field: 'IoTDataType', title: 'IoT数据类型', minWidth: 150 }, {
{ field: 'DeviceId', title: '设备ID', minWidth: 150 }, field: 'IoTDataType',
title: $t('abp.IoTDBBase.IoTDataType'),
minWidth: 150,
},
{ field: 'DeviceId', title: $t('abp.IoTDBBase.DeviceId'), minWidth: 150 },
]; ];
// - 使 // - 使
@ -86,18 +89,30 @@ const formOptions: VbenFormProps = {
FocusAddress: FocusAddress as string, FocusAddress: FocusAddress as string,
DeviceType: DeviceType ? Number(DeviceType) : undefined, DeviceType: DeviceType ? Number(DeviceType) : undefined,
DeviceId: DeviceId as string, DeviceId: DeviceId as string,
SystemName: SystemName as string,
}, },
// 使 // 使
submitOnChange: false, submitOnChange: false,
// //
handleValuesChange: async (values, changedFields) => { handleValuesChange: async (values, changedFields) => {
// //
const relevantFields = ['SystemName', 'DeviceType', 'IoTDataType', 'DeviceId', 'FocusAddress']; const relevantFields = new Set([
const hasRelevantChange = changedFields.some(field => relevantFields.includes(field)); 'DeviceId',
'DeviceType',
'FocusAddress',
'IoTDataType',
'SystemName',
]);
const hasRelevantChange = changedFields.some((field) =>
relevantFields.has(field),
);
if (hasRelevantChange) { if (hasRelevantChange) {
console.log('表单字段变化:', { values, changedFields }); console.log('表单字段变化:', { values, changedFields });
console.log('相关字段变化:', changedFields.filter(field => relevantFields.includes(field))); console.log(
'相关字段变化:',
changedFields.filter((field) => relevantFields.has(field)),
);
// 使 setTimeout // 使 setTimeout
setTimeout(async () => { setTimeout(async () => {
@ -147,62 +162,45 @@ const gridOptions: VxeGridProps<any> = {
console.log('=== API调用开始 ==='); console.log('=== API调用开始 ===');
// DeviceTypeIoTDataType // DeviceTypeIoTDataType
const deviceTypeValue = formValues.DeviceType || DeviceType; const deviceTypeValue = formValues.DeviceType || DeviceType;
const deviceTypeNumber = deviceTypeValue ? Number(deviceTypeValue) : undefined; const deviceTypeNumber = deviceTypeValue
? Number(deviceTypeValue)
: undefined;
const ioTDataTypeValue = formValues.IoTDataType; const ioTDataTypeValue = formValues.IoTDataType;
const ioTDataTypeNumber = ioTDataTypeValue ? Number(ioTDataTypeValue) : undefined;
console.log('=== API调用开始 ===2', ioTDataTypeValue);
// DeviceId(10)使focusId // DeviceId(10)使focusId
let finalDeviceId = formValues.DeviceId || DeviceId; let finalDeviceId = formValues.DeviceId || DeviceId;
if (deviceTypeNumber === 10 && formValues.DeviceId) { if (formValues.DeviceId) {
const deviceInfo = getDeviceInfoById(formValues.DeviceId); const deviceInfo = getDeviceInfoById(formValues.DeviceId);
if (deviceInfo && deviceInfo.focusId) { if (deviceInfo) {
finalDeviceId = deviceInfo.focusId; if (deviceTypeNumber === 10) {
console.log('设备类型为集中器使用focusId:', { // 使focusId
originalDeviceId: formValues.DeviceId, if (deviceInfo.focusId) {
focusId: deviceInfo.focusId, finalDeviceId = deviceInfo.focusId;
deviceInfo: deviceInfo, console.log('设备类型为集中器使用focusId:', {
}); originalDeviceId: formValues.DeviceId,
focusId: deviceInfo.focusId,
deviceInfo: deviceInfo,
});
}
} else {
// 使meterId
if (deviceInfo.meterId) {
finalDeviceId = deviceInfo.meterId;
console.log('设备类型为非集中器使用meterId:', {
originalDeviceId: formValues.DeviceId,
meterId: deviceInfo.meterId,
deviceInfo: deviceInfo,
});
}
}
} }
} }
console.log('请求参数:', {
page,
formValues,
routeParams: { DeviceType, DeviceId, FocusAddress },
typeConversions: {
deviceType: {
originalValue: deviceTypeValue,
convertedValue: deviceTypeNumber,
type: typeof deviceTypeNumber,
},
ioTDataType: {
originalValue: ioTDataTypeValue,
convertedValue: ioTDataTypeNumber,
type: typeof ioTDataTypeNumber,
},
deviceId: {
originalValue: formValues.DeviceId || DeviceId,
finalValue: finalDeviceId,
isFocusId: deviceTypeNumber === 10 && formValues.DeviceId && getDeviceInfoById(formValues.DeviceId)?.focusId,
},
},
finalParams: {
...formValues,
pageIndex: page.currentPage,
pageSize: page.pageSize,
DeviceType: deviceTypeNumber,
DeviceId: finalDeviceId,
FocusAddress: formValues.FocusAddress || FocusAddress,
SystemName: formValues.SystemName,
IoTDataType: ioTDataTypeNumber,
},
});
try { try {
const { data } = await postTreeModelDeviceDataInfoPage({ const { data } = await postTreeModelDeviceDataInfoPage({
body: { body: {
...formValues,
pageIndex: page.currentPage, pageIndex: page.currentPage,
pageSize: page.pageSize, pageSize: page.pageSize,
// 使使 // 使使
@ -210,8 +208,8 @@ const gridOptions: VxeGridProps<any> = {
DeviceId: finalDeviceId, DeviceId: finalDeviceId,
FocusAddress: formValues.FocusAddress || FocusAddress, FocusAddress: formValues.FocusAddress || FocusAddress,
// //
SystemName: formValues.SystemName, SystemName: formValues.SystemName || SystemName,
IoTDataType: ioTDataTypeNumber, IoTDataType: ioTDataTypeValue,
}, },
}); });
@ -265,14 +263,19 @@ const gridOptions: VxeGridProps<any> = {
items: data.items || [], items: data.items || [],
totalCount: data.totalCount || 0, totalCount: data.totalCount || 0,
}; };
console.log('返回给表格的数据:', result); console.log('返回给表格的数据:', result);
console.log('总数:', result.totalCount, '当前页数据量:', result.items.length); console.log(
'总数:',
result.totalCount,
'当前页数据量:',
result.items.length,
);
console.log('分页信息:', { console.log('分页信息:', {
currentPage: page.currentPage, currentPage: page.currentPage,
pageSize: page.pageSize, pageSize: page.pageSize,
}); });
return result; return result;
} }
@ -311,6 +314,40 @@ watch(
} }
}, },
); );
//
watch(
() => [DeviceType, DeviceId, FocusAddress, SystemName],
async (newValues, oldValues) => {
console.log('路由参数变化:', { newValues, oldValues });
//
if (newValues.some(val => val) && gridApi) {
//
await fetchDeviceOptions();
//
setTimeout(() => {
console.log('自动触发查询,路由参数:', { DeviceType, DeviceId, FocusAddress, SystemName });
gridApi.reload();
}, 100);
}
},
{ immediate: true }
);
//
onMounted(async () => {
console.log('页面挂载完成,检查路由参数:', { DeviceType, DeviceId, FocusAddress, SystemName });
//
if (DeviceType || DeviceId || FocusAddress || SystemName) {
//
await fetchDeviceOptions();
//
setTimeout(() => {
console.log('页面初始化时自动触发查询');
gridApi.reload();
}, 200);
}
});
</script> </script>
<template> <template>

View File

@ -50,8 +50,8 @@ export const querySchema = computed(() => [
TypeName: 'MeterTypeEnum', TypeName: 'MeterTypeEnum',
}, },
}, },
labelField: 'secondValue', labelField: 'value',
valueField: 'value', valueField: 'key',
optionsPropName: 'options', optionsPropName: 'options',
immediate: true, immediate: true,
afterFetch: (res: any) => { afterFetch: (res: any) => {

View File

@ -123,9 +123,9 @@ async function submit() {
const formValues = await formApi.getValues(); const formValues = await formApi.getValues();
const fetchParams: any = isEdit const fetchParams: any = isEdit
? { ? {
id: editRow.value.id, id: editRow.value.id,
...formValues, ...formValues,
} }
: formValues; : formValues;
try { try {
@ -171,11 +171,12 @@ function onDel(row: any) {
const toStatusData = (row: Record<string, any>) => { const toStatusData = (row: Record<string, any>) => {
// 使 // 使
router.push({ router.push({
path: '/iotdb/status', path: '/iotdb/deviceData',
query: { query: {
DeviceType: 10, DeviceType: 10,
DeviceId: row.focusId, DeviceId: row.focusId,
FocusAddress: row.focusAddress, FocusAddress: row.focusAddress,
SystemName: row.businessSystemName,
}, },
}); });
}; };
@ -202,59 +203,46 @@ const openAddModal = async () => {
<Page auto-content-height> <Page auto-content-height>
<Grid> <Grid>
<template #toolbar-actions> <template #toolbar-actions>
<TableAction <TableAction :actions="[
:actions="[ {
{ label: $t('common.add'),
label: $t('common.add'), type: 'primary',
type: 'primary', icon: 'ant-design:plus-outlined',
icon: 'ant-design:plus-outlined', onClick: openAddModal.bind(null),
onClick: openAddModal.bind(null), auth: ['AbpIdentity.Users.Create'],
auth: ['AbpIdentity.Users.Create'], },
}, ]" />
]"
/>
</template> </template>
<template #isSelfDevelop="{ row }"> <template #isSelfDevelop="{ row }">
<component <component :is="h(Tag, { color: row.selfDevelop ? 'green' : 'red' }, () =>
:is=" row.selfDevelop ? $t('common.yes') : $t('common.no'),
h(Tag, { color: row.selfDevelop ? 'green' : 'red' }, () => )
row.selfDevelop ? $t('common.yes') : $t('common.no'), " />
)
"
/>
</template> </template>
<template #isStatus="{ row }"> <template #isStatus="{ row }">
<component <component :is="h(Tag, { color: row.status ? 'green' : 'red' }, () =>
:is=" row.status ? $t('common.yes') : $t('common.no'),
h(Tag, { color: row.status ? 'green' : 'red' }, () => )
row.status ? $t('common.yes') : $t('common.no'), " />
)
"
/>
</template> </template>
<template #isEnable="{ row }"> <template #isEnable="{ row }">
<component <component :is="h(Tag, { color: row.enabled ? 'green' : 'red' }, () =>
:is=" row.enabled ? $t('common.yes') : $t('common.no'),
h(Tag, { color: row.enabled ? 'green' : 'red' }, () => )
row.enabled ? $t('common.yes') : $t('common.no'), " />
)
"
/>
</template> </template>
<template #action="{ row }"> <template #action="{ row }">
<TableAction <TableAction :actions="[
:actions="[ {
{ label: $t('common.edit'),
label: $t('common.edit'), type: 'link',
type: 'link', size: 'small',
size: 'small', auth: ['AbpIdentity.Users.Update'],
auth: ['AbpIdentity.Users.Update'], onClick: onEdit.bind(null, row),
onClick: onEdit.bind(null, row), },
}, ]" :drop-down-actions="[
]"
:drop-down-actions="[
{ {
label: row.enabled ? $t('common.disabled') : $t('common.enabled'), label: row.enabled ? $t('common.disabled') : $t('common.enabled'),
icon: `ant-design:${row.enabled ? 'close' : 'check'}-outlined`, icon: `ant-design:${row.enabled ? 'close' : 'check'}-outlined`,
@ -280,15 +268,11 @@ const openAddModal = async () => {
auth: ['AbpIdentity.Users.Delete'], auth: ['AbpIdentity.Users.Delete'],
onClick: toStatusData.bind(null, row), onClick: toStatusData.bind(null, row),
}, },
]" ]" />
/>
</template> </template>
</Grid> </Grid>
<UserModal <UserModal :title="editRow.id ? $t('common.edit') : $t('common.add')" class="w-[800px]">
:title="editRow.id ? $t('common.edit') : $t('common.add')"
class="w-[800px]"
>
<component :is="editRow.id ? EditForm : AddForm" /> <component :is="editRow.id ? EditForm : AddForm" />
</UserModal> </UserModal>
</Page> </Page>

View File

@ -127,14 +127,14 @@ async function submit() {
const formValues = await formApi.getValues(); const formValues = await formApi.getValues();
const fetchParams: any = isEdit const fetchParams: any = isEdit
? { ? {
id: editRow.value.id, id: editRow.value.id,
...formValues, ...formValues,
password: formValues.password || '000000', password: formValues.password || '000000',
} }
: { : {
...formValues, ...formValues,
password: formValues.password || '000000', password: formValues.password || '000000',
}; };
try { try {
userModalApi.setState({ loading: true, confirmLoading: true }); userModalApi.setState({ loading: true, confirmLoading: true });
@ -178,11 +178,12 @@ function onDel(row: any) {
const toStatusData = (row: Record<string, any>) => { const toStatusData = (row: Record<string, any>) => {
// 使 // 使
router.push({ router.push({
path: '/iotdb/point', path: '/iotdb/deviceData',
query: { query: {
DeviceType: row.meterType, DeviceType: row.meterType,
DeviceId: row.meterId, DeviceId: row.meterId,
FocusAddress: row.focusAddress, FocusAddress: row.focusAddress,
SystemName: row.businessSystemName,
}, },
}); });
}; };
@ -212,24 +213,22 @@ const openAddModal = async () => {
<Page auto-content-height> <Page auto-content-height>
<Grid> <Grid>
<template #toolbar-actions> <template #toolbar-actions>
<TableAction <TableAction :actions="[
:actions="[ {
{ label: $t('common.add'),
label: $t('common.add'), type: 'primary',
type: 'primary', icon: 'ant-design:plus-outlined',
icon: 'ant-design:plus-outlined', onClick: openAddModal.bind(null),
onClick: openAddModal.bind(null), auth: ['AbpIdentity.Users.Create'],
auth: ['AbpIdentity.Users.Create'], },
}, ]" />
]"
/>
</template> </template>
<template #isMeterType="{ row }"> <template #isMeterType="{ row }">
{{ meterTypeOptions[row.meterType - 1]?.label }} {{ meterTypeOptions[row.meterType - 1]?.label }}
</template> </template>
<template #isSingleRate="{ row }"> <template #isSingleRate="{ row }">
{{ rateOptions.find((item) => item.value === row.singleRate)?.label }} {{rateOptions.find((item) => item.value === row.singleRate)?.label}}
</template> </template>
<template #isArchiveStatus="{ row }"> <template #isArchiveStatus="{ row }">
{{ {{
@ -240,54 +239,40 @@ const openAddModal = async () => {
{{ row.tripState ? $t('common.SwitchOff') : $t('common.Closing') }} {{ row.tripState ? $t('common.SwitchOff') : $t('common.Closing') }}
</template> </template>
<template #isHaveValve="{ row }"> <template #isHaveValve="{ row }">
<component <component :is="h(Tag, { color: row.haveValve ? 'green' : 'red' }, () =>
:is=" row.haveValve ? $t('common.yes') : $t('common.no'),
h(Tag, { color: row.haveValve ? 'green' : 'red' }, () => )
row.haveValve ? $t('common.yes') : $t('common.no'), " />
)
"
/>
</template> </template>
<template #isSelfDevelop="{ row }"> <template #isSelfDevelop="{ row }">
<component <component :is="h(Tag, { color: row.selfDevelop ? 'green' : 'red' }, () =>
:is=" row.selfDevelop ? $t('common.yes') : $t('common.no'),
h(Tag, { color: row.selfDevelop ? 'green' : 'red' }, () => )
row.selfDevelop ? $t('common.yes') : $t('common.no'), " />
)
"
/>
</template> </template>
<template #isDynamicPassword="{ row }"> <template #isDynamicPassword="{ row }">
<component <component :is="h(Tag, { color: row.dynamicPassword ? 'green' : 'red' }, () =>
:is=" row.dynamicPassword ? $t('common.yes') : $t('common.no'),
h(Tag, { color: row.dynamicPassword ? 'green' : 'red' }, () => )
row.dynamicPassword ? $t('common.yes') : $t('common.no'), " />
)
"
/>
</template> </template>
<template #isEnable="{ row }"> <template #isEnable="{ row }">
<component <component :is="h(Tag, { color: row.enabled ? 'green' : 'red' }, () =>
:is=" row.enabled ? $t('common.yes') : $t('common.no'),
h(Tag, { color: row.enabled ? 'green' : 'red' }, () => )
row.enabled ? $t('common.yes') : $t('common.no'), " />
)
"
/>
</template> </template>
<template #action="{ row }"> <template #action="{ row }">
<TableAction <TableAction :actions="[
:actions="[ {
{ label: $t('common.edit'),
label: $t('common.edit'), type: 'link',
type: 'link', size: 'small',
size: 'small', auth: ['AbpIdentity.Users.Update'],
auth: ['AbpIdentity.Users.Update'], onClick: onEdit.bind(null, row),
onClick: onEdit.bind(null, row), },
}, ]" :drop-down-actions="[
]"
:drop-down-actions="[
{ {
label: $t('common.delete'), label: $t('common.delete'),
icon: 'ant-design:delete-outlined', icon: 'ant-design:delete-outlined',
@ -312,14 +297,10 @@ const openAddModal = async () => {
auth: ['AbpIdentity.Users.Delete'], auth: ['AbpIdentity.Users.Delete'],
onClick: archivesIssued.bind(null, row), onClick: archivesIssued.bind(null, row),
}, },
]" ]" />
/>
</template> </template>
</Grid> </Grid>
<UserModal <UserModal :title="editRow.id ? $t('common.edit') : $t('common.add')" class="w-[800px]">
:title="editRow.id ? $t('common.edit') : $t('common.add')"
class="w-[800px]"
>
<component :is="editRow.id ? EditForm : AddForm" /> <component :is="editRow.id ? EditForm : AddForm" />
</UserModal> </UserModal>
</Page> </Page>