完善平台物模型管理
This commit is contained in:
parent
f3ac09394c
commit
45240cac7e
@ -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;
|
||||
// 总是从表单API获取最新的表单值,确保参数完整(分页、刷新时formValues可能不完整)
|
||||
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 { data } = await postIoTplatformThingModelInfoPageAsync({
|
||||
body: {
|
||||
// 构建查询参数
|
||||
const queryParams: any = {
|
||||
pageIndex: page.currentPage,
|
||||
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;
|
||||
@ -309,8 +297,7 @@ 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({
|
||||
@ -323,7 +310,7 @@ onMounted(async () => {
|
||||
});
|
||||
}
|
||||
await nextTick();
|
||||
}
|
||||
// 无论是否有参数,都触发查询
|
||||
await gridApi.reload();
|
||||
} catch (error) {
|
||||
console.error('初始化加载数据时出错:', error);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user