设备 API 错误回调参数补全

device.js 六个方法加 failCallback 参数;user.js login 网络重试补 failCallback;AddDeviceDialog 改四参数签名。
This commit is contained in:
hrz 2026-10-07 07:20:53 +08:00
parent a89943469b
commit e6585cfbd9
3 changed files with 63 additions and 23 deletions

View file

@ -3,24 +3,30 @@ import RequestService from '../httpRequest';
export default {
// 已绑设备
getAgentBindDevices(agentId, callback) {
return RequestService.sendRequest()
getAgentBindDevices(agentId, callback, failCallback) {
RequestService.sendRequest()
.url(`${getServiceUrl()}/device/bind/${agentId}`)
.method('GET')
.success((res) => {
RequestService.clearRequestTime();
callback(res);
})
.fail((err) => {
RequestService.clearRequestTime();
if (failCallback) {
failCallback(err);
}
})
.networkFail((err) => {
console.error('获取设备列表失败:', err);
RequestService.reAjaxFun(() => {
this.getAgentBindDevices(agentId, callback);
this.getAgentBindDevices(agentId, callback, failCallback);
});
}).send();
},
// 解绑设备
unbindDevice(device_id, callback) {
return RequestService.sendRequest()
unbindDevice(device_id, callback, failCallback) {
RequestService.sendRequest()
.url(`${getServiceUrl()}/device/unbind`)
.method('POST')
.data({ deviceId: device_id })
@ -28,31 +34,43 @@ export default {
RequestService.clearRequestTime();
callback(res);
})
.fail((err) => {
RequestService.clearRequestTime();
if (failCallback) {
failCallback(err);
}
})
.networkFail((err) => {
console.error('解绑设备失败:', err);
RequestService.reAjaxFun(() => {
this.unbindDevice(device_id, callback);
this.unbindDevice(device_id, callback, failCallback);
});
}).send();
},
// 绑定设备
bindDevice(agentId, deviceCode, callback) {
return RequestService.sendRequest()
bindDevice(agentId, deviceCode, callback, failCallback) {
RequestService.sendRequest()
.url(`${getServiceUrl()}/device/bind/${agentId}/${deviceCode}`)
.method('POST')
.success((res) => {
RequestService.clearRequestTime();
callback(res);
})
.fail((err) => {
RequestService.clearRequestTime();
if (failCallback) {
failCallback(err);
}
})
.networkFail((err) => {
console.error('绑定设备失败:', err);
RequestService.reAjaxFun(() => {
this.bindDevice(agentId, deviceCode, callback);
this.bindDevice(agentId, deviceCode, callback, failCallback);
});
}).send();
},
updateDeviceInfo(id, payload, callback) {
return RequestService.sendRequest()
updateDeviceInfo(id, payload, callback, failCallback) {
RequestService.sendRequest()
.url(`${getServiceUrl()}/device/update/${id}`)
.method('PUT')
.data(payload)
@ -60,17 +78,23 @@ export default {
RequestService.clearRequestTime()
callback(res)
})
.fail((err) => {
RequestService.clearRequestTime();
if (failCallback) {
failCallback(err);
}
})
.networkFail((err) => {
console.error('更新OTA状态失败:', err)
this.$message.error(err.msg || '更新OTA状态失败')
RequestService.reAjaxFun(() => {
this.updateDeviceInfo(id, payload, callback)
this.updateDeviceInfo(id, payload, callback, failCallback)
})
}).send()
},
// 手动添加设备
manualAddDevice(params, callback) {
return RequestService.sendRequest()
manualAddDevice(params, callback, failCallback) {
RequestService.sendRequest()
.url(`${getServiceUrl()}/device/manual-add`)
.method('POST')
.data(params)
@ -78,16 +102,22 @@ export default {
RequestService.clearRequestTime();
callback(res);
})
.fail((err) => {
RequestService.clearRequestTime();
if (failCallback) {
failCallback(err);
}
})
.networkFail((err) => {
console.error('手动添加设备失败:', err);
RequestService.reAjaxFun(() => {
this.manualAddDevice(params, callback);
this.manualAddDevice(params, callback, failCallback);
});
}).send();
},
// 获取设备状态
getDeviceStatus(agentId, callback) {
return RequestService.sendRequest()
getDeviceStatus(agentId, callback, failCallback) {
RequestService.sendRequest()
.url(`${getServiceUrl()}/device/bind/${agentId}`)
.method('POST')
.data({}) // 发送空对象作为请求体
@ -95,14 +125,15 @@ export default {
RequestService.clearRequestTime();
callback(res);
})
.fail((res) => {
.fail((err) => {
RequestService.clearRequestTime();
callback(res);
})
.networkFail((err) => {
console.error('获取设备状态失败:', err);
RequestService.reAjaxFun(() => {
this.getDeviceStatus(agentId, callback);
this.getDeviceStatus(agentId, callback, failCallback);
});
}).send();
},
}
}

View file

@ -19,7 +19,7 @@ export default {
})
.networkFail(() => {
RequestService.reAjaxFun(() => {
this.login(loginForm, callback)
this.login(loginForm, callback, failCallback)
})
}).send()
},

View file

@ -51,7 +51,8 @@ export default {
this.loading = true;
Api.device.bindDevice(
this.agentId,
this.deviceCode, ({ data }) => {
this.deviceCode,
({ data }) => {
this.loading = false;
if (data.code === 0) {
this.$emit('refresh');
@ -66,8 +67,16 @@ export default {
showClose: true
});
}
},
(err) => {
this.loading = false;
const msg = err && err.data && err.data.msg;
this.$message.error({
message: msg || this.$t('device.bindFailed'),
showClose: true
});
}
).fail(() => { this.loading = false; });
);
},
closeDialog() {
this.loading = false;