批量绑定设备端物模型

This commit is contained in:
ChenYi 2025-12-23 09:45:09 +08:00
parent 33dd206da0
commit 0b96ff4ff7
6 changed files with 229 additions and 7 deletions

View File

@ -2144,6 +2144,11 @@ export const DeviceManagementInfoDtoSchema = {
description: '设备物模型数据Id', description: '设备物模型数据Id',
format: 'uuid', format: 'uuid',
nullable: true nullable: true
},
deviceThingModelName: {
type: 'string',
description: '设备物模型名称',
nullable: true
} }
}, },
additionalProperties: false additionalProperties: false
@ -6885,6 +6890,11 @@ export const PageDeviceInputSchema = {
description: '物联网平台中对应的设备Id或者名称', description: '物联网平台中对应的设备Id或者名称',
nullable: true nullable: true
}, },
ioTPlatformProductId: {
type: 'string',
description: '物联网平台中对应的产品Id',
nullable: true
},
searchKeyword: { searchKeyword: {
type: 'string', type: 'string',
description: '搜索关键字', description: '搜索关键字',

View File

@ -1183,6 +1183,10 @@ export type DeviceManagementInfoDto = {
* Id * Id
*/ */
deviceThingModelDataId?: (string) | null; deviceThingModelDataId?: (string) | null;
/**
*
*/
deviceThingModelName?: (string) | null;
}; };
export type DeviceManagementInfoDtoPagedResultDto = { export type DeviceManagementInfoDtoPagedResultDto = {
@ -3648,6 +3652,10 @@ export type PageDeviceInput = {
* Id或者名称 * Id或者名称
*/ */
ioTPlatformDeviceOpenInfo?: (string) | null; ioTPlatformDeviceOpenInfo?: (string) | null;
/**
* Id
*/
ioTPlatformProductId?: (string) | null;
/** /**
* *
*/ */

View File

@ -216,7 +216,9 @@
"LastOnlineTime": "LastOnlineTime", "LastOnlineTime": "LastOnlineTime",
"LastOfflineTime": "LastOfflineTime", "LastOfflineTime": "LastOfflineTime",
"deviceInfoManage": "DeviceInfoManage", "deviceInfoManage": "DeviceInfoManage",
"thingModelInfoManage": "ThingModelInfoManage" "thingModelInfoManage": "ThingModelInfoManage",
"isNeedConfigDevicMdoel": "IsNeedConfigDevicMdoel",
"deviceThingModelName": "ThingModelInfoManage"
}, },
"thingModelInfos": { "thingModelInfos": {
"FiledType": "FiledType", "FiledType": "FiledType",

View File

@ -209,7 +209,9 @@
"LastOnlineTime": "最后在线时间", "LastOnlineTime": "最后在线时间",
"LastOfflineTime": "最后离线时间", "LastOfflineTime": "最后离线时间",
"deviceInfoManage": "设备管理", "deviceInfoManage": "设备管理",
"thingModelInfoManage": "物模型管理" "thingModelInfoManage": "物模型管理",
"isNeedConfigDevicMdoel": "是否绑定设备模型",
"deviceThingModelName": "设备物模型名称"
}, },
"thingModelInfos": { "thingModelInfos": {
"FiledType": "物模型类型", "FiledType": "物模型类型",

View File

@ -82,6 +82,82 @@ const gridOptions: VxeGridProps<any> = {
}, },
}, },
}, },
//
onCheckboxChange: ({ row, checked }: any) => {
if (!checked) {
//
return;
}
//
let currentSelected: any[] = [];
if (gridApi?.grid) {
const gridInstance = gridApi.grid as any;
if (typeof gridInstance.getCheckboxRecords === 'function') {
currentSelected = gridInstance.getCheckboxRecords();
} else if (gridInstance.checkboxRecords) {
currentSelected = gridInstance.checkboxRecords;
}
}
// ID
if (currentSelected.length > 0) {
const firstProductId = currentSelected[0]?.ioTPlatformProductId;
const currentProductId = row?.ioTPlatformProductId;
// ID
if (firstProductId && currentProductId && firstProductId !== currentProductId) {
// ID
Message.warning('只能选择同一种产品的设备进行批量绑定,当前设备的产品与已选设备的产品不一致');
//
setTimeout(() => {
if (gridApi?.grid) {
const gridInstance = gridApi.grid as any;
if (typeof gridInstance.setCheckboxRow === 'function') {
gridInstance.setCheckboxRow(row, false);
} else if (typeof gridInstance.clearCheckboxRow === 'function') {
gridInstance.clearCheckboxRow(row);
}
}
}, 100);
return;
}
}
},
//
onCheckboxAll: ({ checked, records }: any) => {
if (!checked || records.length <= 1) {
//
return;
}
// ID
const productIds = records
.map((r: any) => r.ioTPlatformProductId)
.filter((id: any) => id);
if (productIds.length > 0) {
const uniqueProductIds = [...new Set(productIds)];
if (uniqueProductIds.length > 1) {
// ID
Message.warning('只能选择同一种产品的设备进行批量绑定,当前页面包含多种产品');
//
setTimeout(() => {
if (gridApi?.grid) {
const gridInstance = gridApi.grid as any;
if (typeof gridInstance.clearCheckboxAll === 'function') {
gridInstance.clearCheckboxAll();
} else if (typeof gridInstance.setAllCheckboxRow === 'function') {
gridInstance.setAllCheckboxRow(false);
}
}
}, 100);
return;
}
}
},
}; };
const [Grid, gridApi] = useVbenVxeGrid({ formOptions, gridOptions }); const [Grid, gridApi] = useVbenVxeGrid({ formOptions, gridOptions });
@ -640,7 +716,26 @@ const openBindModal = async (rowOrRows?: Record<string, any> | Array<Record<stri
} else { } else {
// //
try { try {
const checkboxRecords = gridApi?.getCheckboxRecords?.() || []; let checkboxRecords: any[] = [];
// grid
if (gridApi?.grid) {
const gridInstance = gridApi.grid as any;
if (typeof gridInstance.getCheckboxRecords === 'function') {
checkboxRecords = gridInstance.getCheckboxRecords();
} else if (gridInstance.checkboxRecords) {
checkboxRecords = gridInstance.checkboxRecords;
}
}
// store
if (checkboxRecords.length === 0 && gridApi?.store) {
const store = gridApi.store as any;
if (store.checkboxRecords) {
checkboxRecords = store.checkboxRecords;
}
}
selectedRows = checkboxRecords; selectedRows = checkboxRecords;
} catch (error) { } catch (error) {
console.warn('无法获取表格选中的设备:', error); console.warn('无法获取表格选中的设备:', error);
@ -652,6 +747,25 @@ const openBindModal = async (rowOrRows?: Record<string, any> | Array<Record<stri
return; return;
} }
//
if (selectedRows.length > 1) {
const productIds = selectedRows
.map((row) => row.ioTPlatformProductId)
.filter((id) => id); //
if (productIds.length === 0) {
Message.error('选中的设备中没有有效的产品ID无法进行绑定');
return;
}
// ID
const uniqueProductIds = [...new Set(productIds)];
if (uniqueProductIds.length > 1) {
Message.error(`选中的设备包含 ${uniqueProductIds.length} 种不同的产品,请只选择同一种产品的设备进行批量绑定`);
return;
}
}
console.log('打开绑定弹窗,选中的设备:', selectedRows); console.log('打开绑定弹窗,选中的设备:', selectedRows);
bindRows.value = selectedRows; bindRows.value = selectedRows;
@ -1043,15 +1157,87 @@ const handleCacheRefresh = async () => {
const openBatchBindModal = async () => { const openBatchBindModal = async () => {
// //
try { try {
const checkboxRecords = gridApi?.getCheckboxRecords?.() || []; console.log('gridApi:', gridApi);
if (checkboxRecords.length === 0) { console.log('gridApi.grid:', gridApi?.grid);
Message.warning('请先在表格中选择要绑定的设备');
//
let checkboxRecords: any[] = [];
// 1 grid
if (gridApi?.grid) {
console.log('grid 可用,尝试获取选中行');
const gridInstance = gridApi.grid as any;
//
if (typeof gridInstance.getCheckboxRecords === 'function') {
checkboxRecords = gridInstance.getCheckboxRecords();
console.log('通过 grid.getCheckboxRecords 获取:', checkboxRecords);
} else if (typeof gridInstance.getCheckboxReserveRecords === 'function') {
checkboxRecords = gridInstance.getCheckboxReserveRecords();
console.log('通过 grid.getCheckboxReserveRecords 获取:', checkboxRecords);
}
// 访
if (checkboxRecords.length === 0 && gridInstance.checkboxRecords) {
checkboxRecords = gridInstance.checkboxRecords;
console.log('通过 grid.checkboxRecords 属性获取:', checkboxRecords);
}
// store
if (checkboxRecords.length === 0 && gridInstance.$store) {
const store = gridInstance.$store;
if (store.checkboxRecords) {
checkboxRecords = store.checkboxRecords;
console.log('通过 grid.$store.checkboxRecords 获取:', checkboxRecords);
}
}
}
// 2 gridApi.store
if (checkboxRecords.length === 0 && gridApi?.store) {
const store = gridApi.store as any;
if (store.checkboxRecords) {
checkboxRecords = store.checkboxRecords;
console.log('通过 gridApi.store.checkboxRecords 获取:', checkboxRecords);
}
}
// 3 gridApi
if (checkboxRecords.length === 0 && typeof (gridApi as any).getCheckboxRecords === 'function') {
checkboxRecords = (gridApi as any).getCheckboxRecords();
console.log('通过 gridApi.getCheckboxRecords 获取:', checkboxRecords);
}
console.log('最终获取到的选中设备:', checkboxRecords);
console.log('选中设备数量:', checkboxRecords.length);
if (!checkboxRecords || checkboxRecords.length === 0) {
Message.warning('请先在表格中勾选要绑定的设备(点击每行前面的复选框)');
return; return;
} }
//
const productIds = checkboxRecords
.map((row) => row.ioTPlatformProductId)
.filter((id) => id); //
if (productIds.length === 0) {
Message.error('选中的设备中没有有效的产品ID无法进行绑定');
return;
}
// ID
const uniqueProductIds = [...new Set(productIds)];
if (uniqueProductIds.length > 1) {
Message.error(`选中的设备包含 ${uniqueProductIds.length} 种不同的产品,请只选择同一种产品的设备进行批量绑定`);
return;
}
await openBindModal(checkboxRecords); await openBindModal(checkboxRecords);
} catch (error) { } catch (error) {
console.error('获取表格选中的设备失败:', error); console.error('获取表格选中的设备失败:', error);
Message.error('获取表格选中的设备失败'); console.error('错误详情:', error);
Message.error('获取表格选中的设备失败,请确保已勾选设备');
} }
}; };

View File

@ -173,6 +173,7 @@ export const querySchema = computed(() => [
export const tableSchema: any = computed((): VxeGridProps['columns'] => [ export const tableSchema: any = computed((): VxeGridProps['columns'] => [
{ title: $t('common.seq'), type: 'seq', width: 50 }, { title: $t('common.seq'), type: 'seq', width: 50 },
{ title: '', type: 'checkbox', width: 50 },
{ {
field: 'ioTPlatformName', field: 'ioTPlatformName',
title: $t('common.BelongingIoTPlatform'), title: $t('common.BelongingIoTPlatform'),
@ -225,6 +226,19 @@ export const tableSchema: any = computed((): VxeGridProps['columns'] => [
return cellValue ? dayjs(cellValue).format('YYYY-MM-DD HH:mm:ss') : ''; return cellValue ? dayjs(cellValue).format('YYYY-MM-DD HH:mm:ss') : '';
}, },
}, },
{
field: 'isNeedConfigDevicMdoel',
title: $t('abp.deviceInfos.isNeedConfigDevicMdoel'),
minWidth: '150',
formatter: ({ cellValue }) => {
return cellValue ? '是' : '否';
},
},
{
field: 'deviceThingModelName',
title: $t('abp.deviceInfos.deviceThingModelName'),
minWidth: '150',
},
{ {
field: 'platformPassword', field: 'platformPassword',
title: $t('abp.deviceInfos.platformPassword'), title: $t('abp.deviceInfos.platformPassword'),