From a230fc6aaa97a268e7fb53dba318d80d78eac09d Mon Sep 17 00:00:00 2001 From: Ran_Chen <1908198662@qq.com> Date: Thu, 3 Apr 2025 18:00:23 +0800 Subject: [PATCH] =?UTF-8?q?ota=E6=8E=A5=E5=8F=A3=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=BC=96=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/manager-web/src/apis/module/ota.js | 54 +++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 main/manager-web/src/apis/module/ota.js diff --git a/main/manager-web/src/apis/module/ota.js b/main/manager-web/src/apis/module/ota.js new file mode 100644 index 00000000..fbc76421 --- /dev/null +++ b/main/manager-web/src/apis/module/ota.js @@ -0,0 +1,54 @@ +import RequestService from '../httpRequest' +import {getServiceUrl} from '../api' + +export default { + /** + * 设备激活接口 + * @param {string} code 激活码 + * @param {function} callback 回调函数 + */ + activateDevice(code, callback) { + RequestService.sendRequest() + .url(`${getServiceUrl()}/api/v1/ota/activation`) + .method('GET') + .query({code}) + .success((res) => { + RequestService.clearRequestTime() + callback(res) + }) + .fail((err) => { + console.error('设备激活失败:', err) + RequestService.reAjaxFun(() => { + this.activateDevice(code, callback) + }) + }).send() + }, + + /** + * 检查OTA版本和设备激活状态 + * @param {object} deviceInfo 设备信息对象 + * @param {string} deviceId 设备唯一标识 + * @param {string} clientId 客户端标识 + * @param {function} callback 回调函数 + */ + checkOtaVersion(deviceInfo, deviceId, clientId, callback) { + RequestService.sendRequest() + .url(`${getServiceUrl()}/api/v1/ota`) + .method('POST') + .header({ + 'Device-Id': deviceId, + 'Client-Id': clientId + }) + .data(deviceInfo) + .success((res) => { + RequestService.clearRequestTime() + callback(res) + }) + .fail((err) => { + console.error('检查OTA版本失败:', err) + RequestService.reAjaxFun(() => { + this.checkOtaVersion(deviceInfo, deviceId, clientId, callback) + }) + }).send() + } +} \ No newline at end of file