完善平台物模型管理

This commit is contained in:
ChenYi 2025-12-22 10:49:46 +08:00
parent f3ac09394c
commit 45240cac7e

View File

@ -12,14 +12,12 @@ import { message as Message, Tag } from 'ant-design-vue';
import { useVbenForm } from '#/adapter/form';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import {
postCtWingProductListAsync,
postIoTplatformThingModelInfoCopyAnotherThingModelAsync,
postIoTplatformThingModelInfoCopyStandardThingModel,
postIoTplatformThingModelInfoCreateAsync,
postIoTplatformThingModelInfoDeleteAsync,
postIoTplatformThingModelInfoPageAsync,
postIoTplatformThingModelInfoUpdateAsync,
postOneNetProductListAsync,
} from '#/api-client';
import { TableAction } from '#/components/table-action';
import { $t } from '#/locales';
@ -70,43 +68,19 @@ const formOptions: VbenFormProps = {
if (changedFields.includes('ioTPlatformProductId')) {
if (values.ioTPlatformProductId) {
productId.value = String(values.ioTPlatformProductId);
//
const platform = values.ioTPlatform;
if (platform) {
try {
const api = platform === 2 || platform === '2'
? postOneNetProductListAsync
: platform === 1 || platform === '1'
? postCtWingProductListAsync
: null;
if (api) {
const { data } = await api({
body: {
pageIndex: 1,
pageSize: 1000,
},
});
const items = data?.items || [];
const selectedProduct = items.find((item: any) =>
String(item.ioTPlatformProductId) === String(values.ioTPlatformProductId)
);
if (selectedProduct) {
productName.value = selectedProduct.productName || '';
}
}
} catch (error) {
console.error('获取产品名称失败:', error);
}
}
// ApiSelect
//
} else {
productId.value = '';
productName.value = '';
}
//
await nextTick();
setTimeout(async () => {
if (gridApi && gridApi.reload) {
try {
// 使
await gridApi.reload();
} catch (error) {
console.error('重新加载数据时出错:', error);
@ -135,28 +109,42 @@ const gridOptions: VxeGridProps<any> = {
proxyConfig: {
ajax: {
query: async ({ page }, formValues) => {
// 使使
const currentPlatform = formValues?.ioTPlatform || ioTPlatform.value;
const currentProductId = formValues?.ioTPlatformProductId || productId.value;
// APIformValues
const currentFormValues = gridApi?.formApi
? await gridApi.formApi.getValues()
: formValues || {};
// ID
if (!currentProductId || !currentPlatform) {
hasData.value = false;
return {
items: [],
totalCount: 0,
};
}
// 使API使formValues
const finalFormValues = { ...(formValues || {}), ...currentFormValues };
const currentPlatform = finalFormValues?.ioTPlatform;
const currentProductId = finalFormValues?.ioTPlatformProductId;
// 使ID
try {
//
const queryParams: any = {
pageIndex: page.currentPage,
pageSize: page.pageSize,
};
//
if (finalFormValues?.SearchKeyWords) {
queryParams.searchKeyWords = finalFormValues.SearchKeyWords;
}
//
if (currentPlatform) {
queryParams.ioTPlatform = Number.parseInt(String(currentPlatform)) as 1 | 2;
}
// ID
if (currentProductId) {
queryParams.ioTPlatformProductId = String(currentProductId);
}
const { data } = await postIoTplatformThingModelInfoPageAsync({
body: {
pageIndex: page.currentPage,
pageSize: page.pageSize,
ioTPlatform: Number.parseInt(String(currentPlatform)) as 1 | 2,
ioTPlatformProductId: String(currentProductId),
...(formValues?.SearchKeyWords && { searchKeyWords: formValues.SearchKeyWords }),
},
body: queryParams,
});
//
hasData.value = data?.items && data.items.length > 0;
@ -309,21 +297,20 @@ onMounted(async () => {
setTimeout(async () => {
if (gridApi && gridApi.reload) {
try {
//
if (route.query.ioTPlatform || route.query.productId) {
const formValues = await gridApi.formApi.getValues();
if (route.query.ioTPlatform && !formValues.ioTPlatform) {
await gridApi.formApi.setValues({
ioTPlatform: route.query.ioTPlatform,
});
}
if (route.query.productId && !formValues.ioTPlatformProductId) {
await gridApi.formApi.setValues({
ioTPlatformProductId: route.query.productId,
});
}
await nextTick();
//
const formValues = await gridApi.formApi.getValues();
if (route.query.ioTPlatform && !formValues.ioTPlatform) {
await gridApi.formApi.setValues({
ioTPlatform: route.query.ioTPlatform,
});
}
if (route.query.productId && !formValues.ioTPlatformProductId) {
await gridApi.formApi.setValues({
ioTPlatformProductId: route.query.productId,
});
}
await nextTick();
//
await gridApi.reload();
} catch (error) {
console.error('初始化加载数据时出错:', error);