设备升级操作
This commit is contained in:
parent
50d40b27d3
commit
1aabdbcc86
@ -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
|
||||
|
||||
@ -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 = {
|
||||
|
||||
@ -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,
|
||||
// },
|
||||
// });
|
||||
// 调用实际的升级接口,使用body参数(JSON格式)
|
||||
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,
|
||||
},
|
||||
});
|
||||
|
||||
// 模拟接口调用
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
|
||||
Message.success('设备升级任务已提交');
|
||||
upgradeModalApi.close();
|
||||
upgradeRow.value = {};
|
||||
upgradeFormApi.resetForm();
|
||||
gridApi.reload();
|
||||
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: '',
|
||||
});
|
||||
|
||||
@ -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(values: any) {
|
||||
if (values.ioTPlatformProductId) {
|
||||
return 'required';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
triggerFields: ['ioTPlatformProductId'],
|
||||
},
|
||||
rules: z.string().min(1, {
|
||||
message: '请选择目标版本',
|
||||
}),
|
||||
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',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user