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

View file

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

View file

@ -51,7 +51,8 @@ export default {
this.loading = true; this.loading = true;
Api.device.bindDevice( Api.device.bindDevice(
this.agentId, this.agentId,
this.deviceCode, ({ data }) => { this.deviceCode,
({ data }) => {
this.loading = false; this.loading = false;
if (data.code === 0) { if (data.code === 0) {
this.$emit('refresh'); this.$emit('refresh');
@ -66,8 +67,16 @@ export default {
showClose: true 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() { closeDialog() {
this.loading = false; this.loading = false;