update:统一接口读取方式

This commit is contained in:
hrz
2025-04-05 21:03:46 +08:00
parent 03441c8582
commit fe86e1fb0f
15 changed files with 304 additions and 461 deletions
+9
View File
@@ -1,5 +1,10 @@
// 引入各个模块的请求
import admin from './module/admin.js'
import agent from './module/agent.js'
import device from './module/device.js'
import model from './module/model.js'
import user from './module/user.js'
/**
* 接口地址
* 开发时自动读取使用.env.development文件
@@ -20,4 +25,8 @@ export function getServiceUrl() {
export default {
getServiceUrl,
user,
admin,
agent,
device,
model,
}
-2
View File
@@ -100,7 +100,6 @@ function sendRequest() {
*/
// 在错误处理函数中添加日志
function httpHandlerError(info, callBack) {
console.log('httpHandlerError', info)
/** 请求成功,退出该函数 可以根据项目需求来判断是否请求成功。这里判断的是status为200的时候是成功 */
let networkError = false
@@ -108,7 +107,6 @@ function httpHandlerError(info, callBack) {
if (info.data.code === 'success' || info.data.code === 0 || info.data.code === undefined) {
return networkError
} else if (info.data.code === 401) {
console.log('触发 401,清除 Token 并跳转登录页');
store.commit('clearAuth');
goToPage(Constant.PAGE.LOGIN, true);
return true
-54
View File
@@ -1,54 +0,0 @@
import { getServiceUrl } from '../api'
import RequestService from '../httpRequest'
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()
}
}