完善平台物模型管理
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 { 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) => {
|
||||||
// 优先使用表单值,如果没有则使用响应式变量
|
// 总是从表单API获取最新的表单值,确保参数完整(分页、刷新时formValues可能不完整)
|
||||||
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);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user