设备数据查看优化

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

@ -197,12 +197,12 @@ async function submit() {
const fetchParams: any = isEdit
? {
id: editRow.value.id,
...formValues,
}
id: editRow.value.id,
...formValues,
}
: {
...formValues,
};
...formValues,
};
try {
const resp = await api({ body: fetchParams });
@ -311,20 +311,20 @@ async function onStatusChange(record: any) {
<Grid>
<template #toolbar-actions>
<TableAction :actions="[
{
label: $t('common.add'),
type: 'primary',
icon: 'ant-design:plus-outlined',
onClick: openAddModal.bind(null),
auth: ['AbpIdentity.Users.Create'],
},
{
label: $t('common.add'),
type: 'primary',
icon: 'ant-design:plus-outlined',
onClick: openAddModal.bind(null),
auth: ['AbpIdentity.Users.Create'],
},
]" />
</template>
<template #isEnable="{ row }">
<component :is="h(Tag, { color: row.isEnabled ? 'green' : 'red' }, () =>
row.isEnabled ? $t('common.yes') : $t('common.no'),
)
)
" />
</template>
@ -338,13 +338,13 @@ async function onStatusChange(record: any) {
<template #action="{ row }">
<TableAction :actions="[
{
label: $t('common.edit'),
type: 'link',
size: 'small',
auth: ['AbpIdentity.Users.Update'],
onClick: onEdit.bind(null, row),
},
{
label: $t('common.edit'),
type: 'link',
size: 'small',
auth: ['AbpIdentity.Users.Update'],
onClick: onEdit.bind(null, row),
},
{
label: row.isEnabled ? '禁用' : '启用',
type: 'link',

View File

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

View File

@ -16,7 +16,7 @@ export const querySchema = computed(() => [
api: getCommonGetSelectList,
params: {
query: {
typeName: 'IoTDBDataTypeConst',
typeName: 'IoTDBDataTypeConst',
},
},
labelField: 'value',

View File

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