完善设备端物模型界面

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

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