设备升级操作

This commit is contained in:
ChenYi 2025-12-31 16:31:54 +08:00
parent 50d40b27d3
commit 1aabdbcc86
4 changed files with 143 additions and 27 deletions

View File

@ -3519,6 +3519,11 @@ export const DeviceUpgradeForApiInputSchema = {
type: 'string',
description: '固件版本信息',
format: 'uuid'
},
upgradeDescription: {
type: 'string',
description: '升级描述',
nullable: true
}
},
additionalProperties: false,
@ -3665,6 +3670,11 @@ export const DeviceUpgradeRecordDtoSchema = {
description: '升级结果',
nullable: true,
readOnly: true
},
upgradeDescription: {
type: 'string',
description: '升级描述',
nullable: true
}
},
additionalProperties: false

View File

@ -2057,6 +2057,10 @@ export type DeviceUpgradeForApiInput = {
*
*/
nowFirmwareVersionDataId: string;
/**
*
*/
upgradeDescription?: (string) | null;
};
export type DeviceUpgradeRecordDto = {
@ -2141,6 +2145,10 @@ export type DeviceUpgradeRecordDto = {
*
*/
readonly upgradeResultName?: (string) | null;
/**
*
*/
upgradeDescription?: (string) | null;
};
export type DeviceUpgradeRecordDtoPagedResultDto = {

View File

@ -25,11 +25,13 @@ import {
postAggregationDeviceCreateAsync,
postAggregationDeviceDeleteAsync,
postAggregationDeviceDeviceCommandForApiAsync,
postAggregationDeviceDeviceUpgradeForApiAsync,
postAggregationDeviceGetDevicePropertyValueForApiAsync,
postAggregationDeviceRepushDeviceInfoToIoTplatform,
postDeviceInfoBindingDeviceThingModel,
postDeviceInfoCacheDeviceDataToRedis,
postDeviceInfoPage,
postFirmwareInfoFindByDeviceProductIdAsync,
postIoTplatformThingModelInfoPageAsync,
} from '#/api-client';
import { Icon } from '#/components/icon';
@ -777,6 +779,16 @@ const [UpgradeForm, upgradeFormApi] = useVbenForm({
showCollapseButton: false,
showDefaultActions: false,
wrapperClass: 'grid-cols-1',
handleValuesChange: async (values, changedFields) => {
// ID
if (changedFields.includes('ioTPlatformProductId')) {
await nextTick();
//
if (upgradeFormApi) {
await upgradeFormApi.setFieldValue('targetVersionId', undefined);
}
}
},
});
//
@ -786,26 +798,54 @@ const submitDeviceUpgrade = async () => {
const formValues = await upgradeFormApi.getValues();
//
if (!upgradeRow.value.id) {
Message.error('设备ID不存在');
return;
}
if (!upgradeRow.value.ioTPlatform) {
Message.error('设备平台类型不存在');
return;
}
if (!upgradeRow.value.ioTPlatformProductId) {
Message.error('设备产品ID不存在');
return;
}
//
if (!formValues.targetVersionId) {
Message.error('请选择目标版本');
return;
}
try {
upgradeModalApi.setState({ loading: true, confirmLoading: true });
// TODO:
// const result = await postDeviceUpgrade({
// body: {
// deviceId: upgradeRow.value.id,
// targetVersionId: formValues.targetVersionId,
// upgradeDescription: formValues.upgradeDescription,
// },
// });
//
await new Promise((resolve) => setTimeout(resolve, 1000));
// 使bodyJSON
const result = await postAggregationDeviceDeviceUpgradeForApiAsync({
body: {
id: upgradeRow.value.id,
ioTPlatform:
typeof upgradeRow.value.ioTPlatform === 'string'
? Number.parseInt(upgradeRow.value.ioTPlatform)
: upgradeRow.value.ioTPlatform,
ioTPlatformProductId: String(upgradeRow.value.ioTPlatformProductId),
nowFirmwareVersionDataId: formValues.targetVersionId,
upgradeDescription: formValues.upgradeDescription || null,
},
});
if (result.data) {
Message.success('设备升级任务已提交');
upgradeModalApi.close();
upgradeRow.value = {};
upgradeFormApi.resetForm();
gridApi.reload();
} else {
Message.error('设备升级失败');
}
} catch (error) {
console.error('设备升级失败:', error);
Message.error('设备升级失败');
@ -821,9 +861,11 @@ const openUpgradeModal = (row: Record<string, any>) => {
//
nextTick(() => {
upgradeFormApi.setValues({
deviceId: row.id,
deviceAddress: row.deviceAddress,
deviceName: row.deviceName || row.deviceAddress,
currentVersion: row.firmwareVersion || '未知',
ioTPlatform: row.ioTPlatform,
ioTPlatformProductId: row.ioTPlatformProductId,
targetVersionId: undefined,
upgradeDescription: '',
});

View File

@ -11,6 +11,7 @@ import {
postAggregationIoTplatformGetIoTplatformAccountInfoAsync,
postAggregationIoTplatformGetIoTplatformProductInfoAsync,
postDeviceThingModelManagementFindByPlatformProductIdAsync,
postFirmwareInfoFindByDeviceProductIdAsync,
} from '#/api-client';
import { $t } from '#/locales';
@ -647,8 +648,8 @@ export const commandFormSchema: any = computed(() => [
export const deviceUpgradeFormSchema: any = computed(() => [
{
component: 'Input',
fieldName: 'deviceId',
label: '设备ID',
fieldName: 'deviceAddress',
label: '设备地址',
componentProps: {
disabled: true,
},
@ -669,19 +670,74 @@ export const deviceUpgradeFormSchema: any = computed(() => [
disabled: true,
},
},
{
component: 'Input',
fieldName: 'ioTPlatform',
label: '',
componentProps: {
type: 'hidden',
},
},
{
component: 'Input',
fieldName: 'ioTPlatformProductId',
label: '',
componentProps: {
type: 'hidden',
},
},
{
component: 'ApiSelect',
fieldName: 'targetVersionId',
label: '目标版本',
componentProps: {
// TODO: 待接口实现后,替换为实际的版本列表接口
api: null,
placeholder: '请选择目标版本',
allowClear: true,
dependencies: {
show(values: any) {
return !!values.ioTPlatformProductId;
},
rules: z.string().min(1, {
message: '请选择目标版本',
}),
rules(values: any) {
if (values.ioTPlatformProductId) {
return 'required';
}
return null;
},
triggerFields: ['ioTPlatformProductId'],
},
componentProps: (formValues: any) => {
const productId = formValues?.ioTPlatformProductId;
return {
api: productId ? postFirmwareInfoFindByDeviceProductIdAsync : null,
params: productId
? {
query: {
id: String(productId),
},
}
: {},
labelField: 'firmwareVersion',
valueField: 'id',
optionsPropName: 'options',
immediate: false,
allowClear: true,
placeholder: '请选择目标版本',
afterFetch: (res: any) => {
// 过滤出已启用的固件版本
let firmwareList: any[] = [];
if (Array.isArray(res)) {
firmwareList = res;
} else if (res && Array.isArray(res.items)) {
firmwareList = res.items;
} else if (res && Array.isArray(res.data)) {
firmwareList = res.data;
} else if (res && res.data && Array.isArray(res.data.items)) {
firmwareList = res.data.items;
}
// 只返回已启用的固件版本
return firmwareList.filter((item: any) => item.isEnable === true);
},
};
},
rules: z.string().optional(),
},
{
component: 'Textarea',