管理后台前端:批量同步对接复选框选中
This commit is contained in:
parent
363157188d
commit
f17cc21c57
File diff suppressed because one or more lines are too long
@ -194,6 +194,24 @@ export type BatchCreateDeviceAggregationInput = {
|
||||
encryptionType?: DeviceAuthenticationModeEnum;
|
||||
};
|
||||
|
||||
/**
|
||||
* 从OneNET批量查询设备信息并同步更新本地
|
||||
*/
|
||||
export type BatchSyncDeviceFromOneNETInput = {
|
||||
/**
|
||||
* 物联网平台类型
|
||||
*/
|
||||
ioTPlatform: IoTPlatformTypeEnum;
|
||||
/**
|
||||
* 物联网平台中对应的产品Id
|
||||
*/
|
||||
ioTPlatformProductId: string;
|
||||
/**
|
||||
* 要同步的设备地址列表(可选)
|
||||
*/
|
||||
deviceAddresses?: Array<(string)> | null;
|
||||
};
|
||||
|
||||
/**
|
||||
* 批量更新设备升级记录状态信息输入
|
||||
*/
|
||||
@ -4716,6 +4734,10 @@ export type PageDeviceInput = {
|
||||
* 设备地址列表(批量查询)
|
||||
*/
|
||||
addressList?: Array<(string)> | null;
|
||||
/**
|
||||
* 平台推送是否成功(null=不过滤,true=已同步,false=未同步)
|
||||
*/
|
||||
isPlatformPushSuccess?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -7216,6 +7238,14 @@ export type PostAggregationDeviceBatchCreateAsyncResponse = (boolean);
|
||||
|
||||
export type PostAggregationDeviceBatchCreateAsyncError = unknown;
|
||||
|
||||
export type PostAggregationDeviceBatchSyncFromOneNETAsyncData = {
|
||||
body?: BatchSyncDeviceFromOneNETInput;
|
||||
};
|
||||
|
||||
export type PostAggregationDeviceBatchSyncFromOneNETAsyncResponse = (boolean);
|
||||
|
||||
export type PostAggregationDeviceBatchSyncFromOneNETAsyncError = unknown;
|
||||
|
||||
export type PostAggregationDeviceDeleteAsyncData = {
|
||||
query?: {
|
||||
input?: IdInput;
|
||||
|
||||
@ -29,6 +29,7 @@ import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
getCommonGetSelectList,
|
||||
postAggregationDeviceBatchCreateAsync,
|
||||
postAggregationDeviceBatchSyncFromOneNETAsync,
|
||||
postAggregationDeviceBindingDeviceThingModel,
|
||||
postAggregationDeviceCallDeviceServiceForApiAsync,
|
||||
postAggregationDeviceCreateAsync,
|
||||
@ -315,6 +316,7 @@ watch(
|
||||
);
|
||||
|
||||
const cacheRefreshLoading = ref(false);
|
||||
const batchSyncLoading = ref(false);
|
||||
const pageLoading = ref(false);
|
||||
const loadingTip = ref('缓存刷新中...');
|
||||
const commandRow: Record<string, any> = ref({});
|
||||
@ -1640,6 +1642,7 @@ const [BatchAddModal, batchAddModalApi] = useVbenModal({
|
||||
},
|
||||
});
|
||||
|
||||
// 批量同步OneNET设备表单
|
||||
// 批量设备升级表单
|
||||
const [BatchUpgradeForm, batchUpgradeFormApi] = useVbenForm({
|
||||
collapsed: false,
|
||||
@ -2632,6 +2635,96 @@ async function submitBatchAdd() {
|
||||
}
|
||||
}
|
||||
|
||||
// 批量同步OneNET/CTWing 设备(优先筛选条件,其次取表格数据)
|
||||
async function handleBatchSync() {
|
||||
const EMQX = 3;
|
||||
|
||||
// 读取复选框选中的设备地址
|
||||
const gridInstance = gridApi.grid as any;
|
||||
const selectedRows: any[] = gridInstance?.getCheckboxRecords?.() ?? [];
|
||||
const selectedAddresses: string[] = selectedRows
|
||||
.map((row: any) => row.deviceAddress)
|
||||
.filter(Boolean);
|
||||
|
||||
// 优先读取筛选表单中的值
|
||||
const filterValues = await gridApi.formApi.getValues();
|
||||
let ioTPlatform: number | undefined = undefined;
|
||||
let ioTPlatformProductId: string | undefined = undefined;
|
||||
|
||||
// 筛选条件中的平台
|
||||
const filterPlatform = filterValues.ioTPlatform;
|
||||
|
||||
// 判断平台:优先筛选条件
|
||||
if (filterPlatform !== undefined && filterPlatform !== null && filterPlatform !== '') {
|
||||
const fp = Number(filterPlatform);
|
||||
if (fp === EMQX) {
|
||||
Message.warning('批量同步不支持 EMQX 平台,仅支持 OneNET 和 CTWing');
|
||||
return;
|
||||
}
|
||||
ioTPlatform = fp;
|
||||
ioTPlatformProductId = filterValues.ioTPlatformProductId;
|
||||
}
|
||||
|
||||
// 平台或产品未从筛选获取到,从选中设备或表格数据补全
|
||||
if (!ioTPlatform || !ioTPlatformProductId) {
|
||||
// 优先用选中设备推导
|
||||
const sourceRows: any[] = selectedRows.length > 0
|
||||
? selectedRows
|
||||
: (() => {
|
||||
const tableData = gridInstance?.getTableData?.();
|
||||
return tableData?.fullData || tableData?.visibleData || [];
|
||||
})();
|
||||
|
||||
// 收集源数据中所有有效平台(排除 EMQX)
|
||||
const platforms = new Set<number>();
|
||||
for (const row of sourceRows) {
|
||||
const rp = Number(row.ioTPlatform);
|
||||
if (rp && rp !== EMQX) {
|
||||
platforms.add(rp);
|
||||
if (!ioTPlatformProductId && row.ioTPlatformProductId) {
|
||||
ioTPlatformProductId = row.ioTPlatformProductId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (platforms.size === 0) {
|
||||
Message.warning('列表中无 OneNET 或 CTWing 设备,请先筛选产品');
|
||||
return;
|
||||
}
|
||||
if (platforms.size > 1) {
|
||||
Message.warning('列表中包含多个平台的设备,请先筛选为单一平台后再同步');
|
||||
return;
|
||||
}
|
||||
|
||||
ioTPlatform = ioTPlatform || [...platforms][0];
|
||||
}
|
||||
|
||||
if (!ioTPlatformProductId) {
|
||||
Message.warning('未找到产品信息,请先在筛选条件中选择产品');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
batchSyncLoading.value = true;
|
||||
const body: any = { ioTPlatform: ioTPlatform!, ioTPlatformProductId };
|
||||
if (selectedAddresses.length > 0) {
|
||||
body.deviceAddresses = selectedAddresses;
|
||||
}
|
||||
const resp = await postAggregationDeviceBatchSyncFromOneNETAsync({ body });
|
||||
if (resp.data) {
|
||||
Message.success('批量同步设备信息成功');
|
||||
gridApi.reload();
|
||||
} else {
|
||||
Message.error('批量同步设备信息失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('批量同步设备信息失败:', error);
|
||||
Message.error('批量同步设备信息失败');
|
||||
} finally {
|
||||
batchSyncLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 打开批量添加模态框
|
||||
const openBatchAddModal = () => {
|
||||
console.log('打开批量添加模态框');
|
||||
@ -2906,6 +2999,16 @@ const toolbarActions = computed(() => [
|
||||
onClick: openBatchAddModal.bind(null),
|
||||
auth: ['AbpIdentity.Users.Create'],
|
||||
},
|
||||
{
|
||||
label: '批量同步',
|
||||
type: 'primary',
|
||||
icon: batchSyncLoading.value
|
||||
? 'ant-design:loading-outlined'
|
||||
: 'ant-design:sync-outlined',
|
||||
onClick: handleBatchSync,
|
||||
disabled: batchSyncLoading.value,
|
||||
auth: ['AbpIdentity.Users.Create'],
|
||||
},
|
||||
{
|
||||
label: '批量绑定设备端物模型',
|
||||
type: 'default',
|
||||
|
||||
@ -118,6 +118,20 @@ export const querySchema = computed(() => [
|
||||
};
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
fieldName: 'isPlatformPushSuccess',
|
||||
label: '同步状态',
|
||||
componentProps: {
|
||||
options: [
|
||||
{ label: '全部', value: undefined },
|
||||
{ label: '已同步', value: true },
|
||||
{ label: '未同步', value: false },
|
||||
],
|
||||
allowClear: true,
|
||||
placeholder: '请选择同步状态',
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
export const tableSchema: any = computed((): VxeGridProps['columns'] => [
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user