管理后台前端:批量同步对接复选框选中

This commit is contained in:
ChenYi 2026-06-30 16:17:10 +08:00
parent 363157188d
commit f17cc21c57
4 changed files with 158 additions and 1 deletions

File diff suppressed because one or more lines are too long

View File

@ -194,6 +194,24 @@ export type BatchCreateDeviceAggregationInput = {
encryptionType?: DeviceAuthenticationModeEnum; 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; addressList?: Array<(string)> | null;
/**
* null=true=false=
*/
isPlatformPushSuccess?: boolean;
}; };
/** /**
@ -7216,6 +7238,14 @@ export type PostAggregationDeviceBatchCreateAsyncResponse = (boolean);
export type PostAggregationDeviceBatchCreateAsyncError = unknown; export type PostAggregationDeviceBatchCreateAsyncError = unknown;
export type PostAggregationDeviceBatchSyncFromOneNETAsyncData = {
body?: BatchSyncDeviceFromOneNETInput;
};
export type PostAggregationDeviceBatchSyncFromOneNETAsyncResponse = (boolean);
export type PostAggregationDeviceBatchSyncFromOneNETAsyncError = unknown;
export type PostAggregationDeviceDeleteAsyncData = { export type PostAggregationDeviceDeleteAsyncData = {
query?: { query?: {
input?: IdInput; input?: IdInput;

View File

@ -29,6 +29,7 @@ import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { import {
getCommonGetSelectList, getCommonGetSelectList,
postAggregationDeviceBatchCreateAsync, postAggregationDeviceBatchCreateAsync,
postAggregationDeviceBatchSyncFromOneNETAsync,
postAggregationDeviceBindingDeviceThingModel, postAggregationDeviceBindingDeviceThingModel,
postAggregationDeviceCallDeviceServiceForApiAsync, postAggregationDeviceCallDeviceServiceForApiAsync,
postAggregationDeviceCreateAsync, postAggregationDeviceCreateAsync,
@ -315,6 +316,7 @@ watch(
); );
const cacheRefreshLoading = ref(false); const cacheRefreshLoading = ref(false);
const batchSyncLoading = ref(false);
const pageLoading = ref(false); const pageLoading = ref(false);
const loadingTip = ref('缓存刷新中...'); const loadingTip = ref('缓存刷新中...');
const commandRow: Record<string, any> = ref({}); const commandRow: Record<string, any> = ref({});
@ -1640,6 +1642,7 @@ const [BatchAddModal, batchAddModalApi] = useVbenModal({
}, },
}); });
// OneNET
// //
const [BatchUpgradeForm, batchUpgradeFormApi] = useVbenForm({ const [BatchUpgradeForm, batchUpgradeFormApi] = useVbenForm({
collapsed: false, 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 = () => { const openBatchAddModal = () => {
console.log('打开批量添加模态框'); console.log('打开批量添加模态框');
@ -2906,6 +2999,16 @@ const toolbarActions = computed(() => [
onClick: openBatchAddModal.bind(null), onClick: openBatchAddModal.bind(null),
auth: ['AbpIdentity.Users.Create'], 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: '批量绑定设备端物模型', label: '批量绑定设备端物模型',
type: 'default', type: 'default',

View File

@ -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'] => [ export const tableSchema: any = computed((): VxeGridProps['columns'] => [