完善平台物模型管理

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