完善设备端物模型界面

This commit is contained in:
ChenYi 2025-12-18 17:14:47 +08:00
parent 031364ba7e
commit 6e9791711a
2 changed files with 74 additions and 19 deletions

View File

@ -329,8 +329,8 @@ function onThingModelManagement(record: any) {
path: '/thingmodelinfo/ioTPlatformThingModelInfo', path: '/thingmodelinfo/ioTPlatformThingModelInfo',
query: { query: {
productId: record.ioTPlatformProductId, // ID productId: record.ioTPlatformProductId, // ID
productName: record.productName, productName: record.productName,
ioTPlatform: '2', // OneNET2 ioTPlatform: '2', // OneNET2
}, },
}); });
} }

View File

@ -2,7 +2,7 @@
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 { h, nextTick, ref } from 'vue'; import { h, nextTick, onMounted, ref } from 'vue';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import { Page, useVbenModal } from '@vben/common-ui'; import { Page, useVbenModal } from '@vben/common-ui';
@ -73,7 +73,9 @@ const formOptions: VbenFormProps = {
setTimeout(async () => { setTimeout(async () => {
if (gridApi && gridApi.reload) { if (gridApi && gridApi.reload) {
try { try {
await gridApi.reload(); // 使
const latestValues = await gridApi.formApi.getValues();
await gridApi.reload(latestValues);
} catch (error) { } catch (error) {
console.error('重新加载设备端物模型列表时出错:', error); console.error('重新加载设备端物模型列表时出错:', error);
} }
@ -81,6 +83,16 @@ const formOptions: VbenFormProps = {
}, 100); }, 100);
} }
}, },
//
handleSubmit: async (values) => {
if (gridApi && gridApi.reload) {
try {
await gridApi.reload(values);
} catch (error) {
console.error('搜索设备端物模型列表失败:', error);
}
}
},
}; };
const gridOptions: VxeGridProps<any> = { const gridOptions: VxeGridProps<any> = {
@ -106,24 +118,24 @@ const gridOptions: VxeGridProps<any> = {
const currentProductId = const currentProductId =
formValues?.ioTPlatformProductId || productId.value; formValues?.ioTPlatformProductId || productId.value;
if (!currentPlatform || !currentProductId) {
return {
items: [],
totalCount: 0,
};
}
try { try {
const { data } = await postDeviceThingModelManagementPageAsync({ const { data } = await postDeviceThingModelManagementPageAsync({
// 使 JSON Body
body: { body: {
pageIndex: page.currentPage, pageIndex: page.currentPage,
pageSize: page.pageSize, pageSize: page.pageSize,
ioTPlatform: ...(currentPlatform && {
typeof currentPlatform === 'string' ioTPlatform:
? Number.parseInt(currentPlatform) typeof currentPlatform === 'string'
: currentPlatform, ? Number.parseInt(currentPlatform)
ioTPlatformProductId: String(currentProductId), : currentPlatform,
searchKeyWords: formValues?.SearchKeyWords, }),
...(currentProductId && {
ioTPlatformProductId: String(currentProductId),
}),
...(formValues?.SearchKeyWords && {
searchKeyWords: formValues.SearchKeyWords,
}),
}, },
}); });
@ -157,7 +169,12 @@ const [ThingModelModal, thingModelModalApi] = useVbenModal({
if (isOpen && editRow.value.id) { if (isOpen && editRow.value.id) {
// //
nextTick(() => { nextTick(() => {
editFormApi.setValues({ ...editRow.value }); const values: any = { ...editRow.value };
//
if (values.ioTPlatform !== undefined && values.ioTPlatform !== null) {
values.ioTPlatform = String(values.ioTPlatform);
}
editFormApi.setValues(values);
}); });
} }
}, },
@ -223,7 +240,11 @@ async function submit() {
); );
thingModelModalApi.close(); thingModelModalApi.close();
editRow.value = {}; editRow.value = {};
gridApi.reload(); // 使
if (gridApi && gridApi.reload && gridApi.formApi) {
const latestValues = await gridApi.formApi.getValues();
await gridApi.reload(latestValues);
}
} else { } else {
Message.error( Message.error(
isEdit ? $t('common.editFail') : $t('common.addFail'), isEdit ? $t('common.editFail') : $t('common.addFail'),
@ -264,6 +285,40 @@ async function onDel(record: any) {
Message.error($t('common.deleteFail')); Message.error($t('common.deleteFail'));
} }
} }
// ID
onMounted(async () => {
await nextTick();
setTimeout(async () => {
if (!gridApi || !gridApi.reload) return;
try {
//
const formValues = await gridApi.formApi.getValues();
const newValues: any = { ...formValues };
if (route.query.ioTPlatform && !formValues.ioTPlatform) {
newValues.ioTPlatform = route.query.ioTPlatform;
}
if (route.query.productId && !formValues.ioTPlatformProductId) {
newValues.ioTPlatformProductId = route.query.productId;
}
if (
newValues.ioTPlatform !== formValues.ioTPlatform ||
newValues.ioTPlatformProductId !== formValues.ioTPlatformProductId
) {
await gridApi.formApi.setValues(newValues);
await nextTick();
}
// ID
await gridApi.reload(newValues);
} catch (error) {
console.error('初始化加载设备端物模型列表失败:', error);
}
}, 300);
});
</script> </script>
<template> <template>