封装实时接口,请求,共多个页面调用
This commit is contained in:
@ -49,7 +49,8 @@
|
|||||||
<script>
|
<script>
|
||||||
import CustomPopup from '@/components/CustomPopup/CustomPopup.vue'
|
import CustomPopup from '@/components/CustomPopup/CustomPopup.vue'
|
||||||
import {
|
import {
|
||||||
generateShortId
|
generateShortId,
|
||||||
|
getdeviceSTatus
|
||||||
} from '@/utils/function.js';
|
} from '@/utils/function.js';
|
||||||
import {
|
import {
|
||||||
deviceInfo,
|
deviceInfo,
|
||||||
@ -89,44 +90,6 @@ export default {
|
|||||||
this.deviceList[index].checked = !this.deviceList[index].checked
|
this.deviceList[index].checked = !this.deviceList[index].checked
|
||||||
this.$forceUpdate()
|
this.$forceUpdate()
|
||||||
},
|
},
|
||||||
/**
|
|
||||||
* 获取设备状态(带自动轮询)
|
|
||||||
* @param {number} val - 功能模式
|
|
||||||
* @param {string} batchId - 批次ID
|
|
||||||
* @param {number} [interval=1000] - 轮询间隔(毫秒)
|
|
||||||
*/
|
|
||||||
async getdeviceSTatus(val, batchId, interval =500) {
|
|
||||||
const checkStatus = async () => {
|
|
||||||
try {
|
|
||||||
const data = {
|
|
||||||
functionMode: val,
|
|
||||||
batchId: batchId,
|
|
||||||
typeName: this.sendInfo.typeName,
|
|
||||||
deviceImei: this.sendInfo.deviceImei
|
|
||||||
};
|
|
||||||
const res = await deviceRealTimeStatus(data);
|
|
||||||
if (res.code !== 200) {
|
|
||||||
throw new Error(res.msg || '请求失败');
|
|
||||||
}
|
|
||||||
switch (res.data.functionAccess) {
|
|
||||||
case 'OK':
|
|
||||||
return res; // 成功完成
|
|
||||||
case 'ACTIVE':
|
|
||||||
await new Promise(r => setTimeout(r, interval));
|
|
||||||
return checkStatus(); // 继续轮询
|
|
||||||
case 'FAILED':
|
|
||||||
throw new Error('设备操作失败');
|
|
||||||
case 'TIMEOUT':
|
|
||||||
throw new Error('设备响应超时');
|
|
||||||
default:
|
|
||||||
throw new Error('未知状态');
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return checkStatus();
|
|
||||||
},
|
|
||||||
// 全选/取消全选
|
// 全选/取消全选
|
||||||
selectAll() {
|
selectAll() {
|
||||||
console.log('123');
|
console.log('123');
|
||||||
@ -220,7 +183,17 @@ export default {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 4. 获取设备状态
|
// 4. 获取设备状态
|
||||||
const statusRes = await this.getdeviceSTatus(2, batchId);
|
let deviceImei = this.sendInfo.deviceImei
|
||||||
|
let typeName = this.sendInfo.typeName
|
||||||
|
const statusRes = await getdeviceSTatus({
|
||||||
|
functionMode: 2,
|
||||||
|
batchId,
|
||||||
|
typeName,
|
||||||
|
deviceImei,
|
||||||
|
interval: 500
|
||||||
|
},
|
||||||
|
deviceRealTimeStatus
|
||||||
|
);
|
||||||
if (statusRes.data.functionAccess === 'OK') {
|
if (statusRes.data.functionAccess === 'OK') {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: statusRes.msg,
|
title: statusRes.msg,
|
||||||
|
@ -271,7 +271,8 @@
|
|||||||
<script>
|
<script>
|
||||||
import MqttClient from '@/utils/mqtt.js';
|
import MqttClient from '@/utils/mqtt.js';
|
||||||
import {
|
import {
|
||||||
generateShortId
|
generateShortId,
|
||||||
|
getdeviceSTatus
|
||||||
} from '@/utils/function.js';
|
} from '@/utils/function.js';
|
||||||
import {
|
import {
|
||||||
deviceDetail,
|
deviceDetail,
|
||||||
@ -334,7 +335,9 @@
|
|||||||
popupType: 'person', //弹框类型
|
popupType: 'person', //弹框类型
|
||||||
isLaserOn: false,
|
isLaserOn: false,
|
||||||
isSending: false,
|
isSending: false,
|
||||||
isProcessing: false
|
isProcessing: false,
|
||||||
|
isLoading: false, // 主加载状态
|
||||||
|
isPolling: false // 轮询状态
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -346,44 +349,6 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
/**
|
|
||||||
* 获取设备状态(带自动轮询)
|
|
||||||
* @param {number} val - 功能模式
|
|
||||||
* @param {string} batchId - 批次ID
|
|
||||||
* @param {number} [interval=800] - 轮询间隔(毫秒)
|
|
||||||
*/
|
|
||||||
async getdeviceSTatus(val, batchId, interval = 800) {
|
|
||||||
const checkStatus = async () => {
|
|
||||||
try {
|
|
||||||
const data = {
|
|
||||||
functionMode: val,
|
|
||||||
batchId: batchId,
|
|
||||||
typeName: this.itemInfo.typeName,
|
|
||||||
deviceImei: this.itemInfo.deviceImei
|
|
||||||
};
|
|
||||||
const res = await deviceRealTimeStatus(data);
|
|
||||||
if (res.code !== 200) {
|
|
||||||
throw new Error(res.msg || '请求失败');
|
|
||||||
}
|
|
||||||
switch (res.data.functionAccess) {
|
|
||||||
case 'OK':
|
|
||||||
return res; // 成功完成
|
|
||||||
case 'ACTIVE':
|
|
||||||
await new Promise(r => setTimeout(r, interval));
|
|
||||||
return checkStatus(); // 继续轮询
|
|
||||||
case 'FAILED':
|
|
||||||
throw new Error('设备操作失败');
|
|
||||||
case 'TIMEOUT':
|
|
||||||
throw new Error('设备响应超时');
|
|
||||||
default:
|
|
||||||
throw new Error('未知状态');
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return checkStatus();
|
|
||||||
},
|
|
||||||
// 点击弹框外的区域关闭
|
// 点击弹框外的区域关闭
|
||||||
closePopup() {
|
closePopup() {
|
||||||
this.lightModeA = false;
|
this.lightModeA = false;
|
||||||
@ -554,22 +519,6 @@
|
|||||||
toggleForm() {
|
toggleForm() {
|
||||||
this.isFormExpanded = !this.isFormExpanded;
|
this.isFormExpanded = !this.isFormExpanded;
|
||||||
},
|
},
|
||||||
// onItemClick(index) {
|
|
||||||
// const selectedItem = this.items[index];
|
|
||||||
// if (selectedItem.text === '激光') {
|
|
||||||
// this.lightModeC = true;
|
|
||||||
// } else {
|
|
||||||
// // 更新选中状态
|
|
||||||
// this.items = this.items.map((item, i) => ({
|
|
||||||
// ...item,
|
|
||||||
// selected: i === index
|
|
||||||
// }));
|
|
||||||
// this.currentMainMode = selectedItem.text;
|
|
||||||
// this.selectedItemIndex = index;
|
|
||||||
// // 强制更新视图(如果需要)
|
|
||||||
// this.$forceUpdate();
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
onItemClick(index) {
|
onItemClick(index) {
|
||||||
const item = this.items[index];
|
const item = this.items[index];
|
||||||
// 激光模式特殊处理
|
// 激光模式特殊处理
|
||||||
@ -749,6 +698,7 @@
|
|||||||
mask: true
|
mask: true
|
||||||
});
|
});
|
||||||
loadingShown = true;
|
loadingShown = true;
|
||||||
|
this.isPolling = true; // 标记开始轮询
|
||||||
uni.uploadFile({
|
uni.uploadFile({
|
||||||
url: baseURL + '/app/bjq/device/uploadLogo',
|
url: baseURL + '/app/bjq/device/uploadLogo',
|
||||||
filePath: this.selectedImage,
|
filePath: this.selectedImage,
|
||||||
@ -773,7 +723,19 @@
|
|||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
// 获取设备状态
|
// 获取设备状态
|
||||||
const statusRes = await this.getdeviceSTatus(1);
|
// 4. 获取设备状态
|
||||||
|
let deviceImei = this.itemInfo.deviceImei
|
||||||
|
let typeName = this.itemInfo.typeName
|
||||||
|
let batchId = ''
|
||||||
|
const statusRes = await getdeviceSTatus({
|
||||||
|
functionMode: 1,
|
||||||
|
batchId,
|
||||||
|
typeName,
|
||||||
|
deviceImei,
|
||||||
|
interval: 800
|
||||||
|
},
|
||||||
|
deviceRealTimeStatus
|
||||||
|
);
|
||||||
if (statusRes.data.functionAccess === 'OK') {
|
if (statusRes.data.functionAccess === 'OK') {
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
this.selectedImage = '';
|
this.selectedImage = '';
|
||||||
@ -784,6 +746,7 @@
|
|||||||
this.lightModeB = false;
|
this.lightModeB = false;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
this.isPolling = false; // 标记轮询结束
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: error.message,
|
title: error.message,
|
||||||
@ -791,6 +754,7 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
this.isPolling = false; // 标记轮询结束
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: responseData.msg,
|
title: responseData.msg,
|
||||||
@ -798,6 +762,7 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
this.isPolling = false; // 标记轮询结束
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: e.message,
|
title: e.message,
|
||||||
@ -918,6 +883,7 @@
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this.isPolling = true; // 标记开始轮询
|
||||||
try {
|
try {
|
||||||
uni.showLoading({
|
uni.showLoading({
|
||||||
title: '解除告警中...',
|
title: '解除告警中...',
|
||||||
@ -942,7 +908,17 @@
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 4. 获取设备状态
|
// 4. 获取设备状态
|
||||||
const statusRes = await this.getdeviceSTatus(2, batchId);
|
let deviceImei = this.itemInfo.deviceImei
|
||||||
|
let typeName = this.itemInfo.typeName
|
||||||
|
const statusRes = await getdeviceSTatus({
|
||||||
|
functionMode: 2,
|
||||||
|
batchId,
|
||||||
|
typeName,
|
||||||
|
deviceImei,
|
||||||
|
interval: 500
|
||||||
|
},
|
||||||
|
deviceRealTimeStatus
|
||||||
|
);
|
||||||
if (statusRes.data.functionAccess === 'OK') {
|
if (statusRes.data.functionAccess === 'OK') {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: statusRes.msg,
|
title: statusRes.msg,
|
||||||
@ -964,6 +940,7 @@
|
|||||||
icon: 'none'
|
icon: 'none'
|
||||||
});
|
});
|
||||||
} finally {
|
} finally {
|
||||||
|
this.isPolling = false; // 标记开始轮询
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -987,6 +964,7 @@
|
|||||||
}
|
}
|
||||||
this.isSending = true;
|
this.isSending = true;
|
||||||
let loadingShown = false;
|
let loadingShown = false;
|
||||||
|
this.isPolling = true; // 标记开始轮询
|
||||||
try {
|
try {
|
||||||
uni.showLoading({
|
uni.showLoading({
|
||||||
title: '正在发送...',
|
title: '正在发送...',
|
||||||
@ -1011,8 +989,18 @@
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 轮询获取状态(重要:这里必须await)
|
// 4. 获取设备状态
|
||||||
const statusRes = await this.getdeviceSTatus(2, batchId);
|
let deviceImei = this.itemInfo.deviceImei
|
||||||
|
let typeName = this.itemInfo.typeName
|
||||||
|
const statusRes = await getdeviceSTatus({
|
||||||
|
functionMode: 2,
|
||||||
|
batchId,
|
||||||
|
typeName,
|
||||||
|
deviceImei,
|
||||||
|
interval: 500
|
||||||
|
},
|
||||||
|
deviceRealTimeStatus
|
||||||
|
);
|
||||||
// 只有当状态为'OK'时才显示成功弹窗
|
// 只有当状态为'OK'时才显示成功弹窗
|
||||||
if (statusRes.data.functionAccess === 'OK') {
|
if (statusRes.data.functionAccess === 'OK') {
|
||||||
this.popupType = 'person';
|
this.popupType = 'person';
|
||||||
@ -1025,7 +1013,7 @@
|
|||||||
icon: 'none'
|
icon: 'none'
|
||||||
});
|
});
|
||||||
} finally {
|
} finally {
|
||||||
console.log('失败还是成功了');
|
this.isPolling = false; // 标记轮询结束
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
this.isSending = false;
|
this.isSending = false;
|
||||||
}
|
}
|
||||||
@ -1062,9 +1050,16 @@
|
|||||||
this.isSharedDevice = false;
|
this.isSharedDevice = false;
|
||||||
this.activePermissions = []; // 非分享设备清空权限
|
this.activePermissions = []; // 非分享设备清空权限
|
||||||
}
|
}
|
||||||
if (!isUpdate) {
|
// 只有不是轮询状态时才关闭loading
|
||||||
// 关闭加载中
|
if (!this.isPolling) {
|
||||||
uni.hideLoading()
|
this.pageLoading = false;
|
||||||
|
uni.hideLoading(); // 确保关闭
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 只有不是轮询状态时才关闭loading
|
||||||
|
if (!this.isPolling) {
|
||||||
|
this.pageLoading = false;
|
||||||
|
uni.hideLoading(); // 确保关闭
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -1081,25 +1076,15 @@
|
|||||||
try {
|
try {
|
||||||
const res = await deviceDetail(id)
|
const res = await deviceDetail(id)
|
||||||
if (res.code == 200) {
|
if (res.code == 200) {
|
||||||
this.handleDeviceData(res, false, isUpdate)
|
this.handleDeviceData(res, false, isUpdate, true)
|
||||||
} else {
|
|
||||||
uni.showToast({
|
|
||||||
title: res.msg,
|
|
||||||
icon: 'none'
|
|
||||||
})
|
|
||||||
if (!isUpdate) {
|
|
||||||
uni.hideLoading()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (!isUpdate) {
|
// 只有不是轮询状态时才关闭loading
|
||||||
uni.hideLoading()
|
if (!this.isPolling) {
|
||||||
|
this.pageLoading = false;
|
||||||
|
uni.hideLoading(); // 确保关闭
|
||||||
}
|
}
|
||||||
// uni.showToast({
|
|
||||||
// title: error.msg,
|
|
||||||
// icon: 'none'
|
|
||||||
// })
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 获取分享设备详情
|
// 获取分享设备详情
|
||||||
@ -1107,20 +1092,13 @@
|
|||||||
try {
|
try {
|
||||||
const res = await deviceShareId(id)
|
const res = await deviceShareId(id)
|
||||||
if (res.code == 200) {
|
if (res.code == 200) {
|
||||||
this.handleDeviceData(res, true)
|
this.handleDeviceData(res, false, false, true)
|
||||||
} else {
|
|
||||||
uni.showToast({
|
|
||||||
title: res.msg,
|
|
||||||
icon: 'none'
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
uni.showToast({
|
if (!this.isPolling) {
|
||||||
title: error.msg,
|
this.pageLoading = false;
|
||||||
icon: 'none'
|
uni.hideLoading(); // 确保关闭
|
||||||
})
|
}
|
||||||
uni.hideLoading()
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 操作说明
|
// 操作说明
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
<view class="container">
|
<view class="container">
|
||||||
<!-- 设备列表 -->
|
<!-- 设备列表 -->
|
||||||
<scroll-view class="device-list" scroll-y>
|
<scroll-view class="device-list" scroll-y>
|
||||||
<view class="device-card" v-for="(item, index) in deviceList" :key="index" @click="item.onlineStatus === 1 ? toggleSelect(index) : null">
|
<view class="device-card" v-for="(item, index) in deviceList" :key="index"
|
||||||
|
@click="item.onlineStatus === 1 ? toggleSelect(index) : null">
|
||||||
<!-- 复选框 -->
|
<!-- 复选框 -->
|
||||||
<view class="checkbox" :class="{ checked: item.checked, disabled: item.onlineStatus !== 1 }">
|
<view class="checkbox" :class="{ checked: item.checked, disabled: item.onlineStatus !== 1 }">
|
||||||
<uni-icons v-if="item.checked" type="checkmarkempty" size="18" color="rgb(0, 0, 0)"></uni-icons>
|
<uni-icons v-if="item.checked" type="checkmarkempty" size="18" color="rgb(0, 0, 0)"></uni-icons>
|
||||||
@ -52,7 +53,8 @@
|
|||||||
deviceRealTimeStatus //设备状态
|
deviceRealTimeStatus //设备状态
|
||||||
} from '@/api/6170/deviceControl.js'
|
} from '@/api/6170/deviceControl.js'
|
||||||
import {
|
import {
|
||||||
generateShortId
|
generateShortId,
|
||||||
|
getdeviceSTatus
|
||||||
} from '@/utils/function.js';
|
} from '@/utils/function.js';
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
@ -75,45 +77,6 @@
|
|||||||
// 执行下拉刷新时的操作,比如重新获取数据
|
// 执行下拉刷新时的操作,比如重新获取数据
|
||||||
this.getData();
|
this.getData();
|
||||||
},
|
},
|
||||||
/**
|
|
||||||
* 获取设备状态(带自动轮询)
|
|
||||||
* @param {number} val - 功能模式
|
|
||||||
* @param {string} batchId - 批次ID
|
|
||||||
* @param {number} [interval=1000] - 轮询间隔(毫秒)
|
|
||||||
*/
|
|
||||||
async getdeviceSTatus(val, batchId, interval = 800) {
|
|
||||||
const checkStatus = async () => {
|
|
||||||
try {
|
|
||||||
const data = {
|
|
||||||
functionMode: val,
|
|
||||||
batchId: batchId,
|
|
||||||
typeName: this.sendInfo.typeName,
|
|
||||||
deviceImei: this.sendInfo.deviceImei
|
|
||||||
};
|
|
||||||
const res = await deviceRealTimeStatus(data);
|
|
||||||
if (res.code !== 200) {
|
|
||||||
throw new Error(res.msg || '请求失败');
|
|
||||||
}
|
|
||||||
switch (res.data.functionAccess) {
|
|
||||||
case 'OK':
|
|
||||||
return res; // 成功完成
|
|
||||||
case 'ACTIVE':
|
|
||||||
await new Promise(r => setTimeout(r, interval));
|
|
||||||
return checkStatus(); // 继续轮询
|
|
||||||
case 'FAILED':
|
|
||||||
throw new Error('设备操作失败');
|
|
||||||
case 'TIMEOUT':
|
|
||||||
throw new Error('设备响应超时');
|
|
||||||
default:
|
|
||||||
throw new Error('未知状态');
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return checkStatus();
|
|
||||||
},
|
|
||||||
|
|
||||||
toggleSelect(index) {
|
toggleSelect(index) {
|
||||||
this.deviceList[index].checked = !this.deviceList[index].checked
|
this.deviceList[index].checked = !this.deviceList[index].checked
|
||||||
this.$forceUpdate()
|
this.$forceUpdate()
|
||||||
@ -189,7 +152,17 @@
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 4. 获取设备状态
|
// 4. 获取设备状态
|
||||||
const statusRes = await this.getdeviceSTatus(2, batchId);
|
let deviceImei = this.sendInfo.deviceImei
|
||||||
|
let typeName = this.sendInfo.typeName
|
||||||
|
const statusRes = await getdeviceSTatus({
|
||||||
|
functionMode: 2,
|
||||||
|
batchId,
|
||||||
|
typeName,
|
||||||
|
deviceImei,
|
||||||
|
interval: 500
|
||||||
|
},
|
||||||
|
deviceRealTimeStatus
|
||||||
|
);
|
||||||
if (statusRes.data.functionAccess === 'OK') {
|
if (statusRes.data.functionAccess === 'OK') {
|
||||||
// 5. 显示成功弹窗
|
// 5. 显示成功弹窗
|
||||||
this.showPopupFlag = true
|
this.showPopupFlag = true
|
||||||
@ -422,12 +395,15 @@
|
|||||||
border-radius: 50rpx;
|
border-radius: 50rpx;
|
||||||
width: 90%;
|
width: 90%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.checkbox.disabled {
|
.checkbox.disabled {
|
||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
background-color: rgba(255, 255, 255, 0.1) !important;
|
background-color: rgba(255, 255, 255, 0.1) !important;
|
||||||
border-color: rgba(255, 255, 255, 0.2) !important;
|
border-color: rgba(255, 255, 255, 0.2) !important;
|
||||||
pointer-events: none; /* 阻止点击事件 */
|
pointer-events: none;
|
||||||
|
/* 阻止点击事件 */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 可选:离线设备的卡片整体置灰 */
|
/* 可选:离线设备的卡片整体置灰 */
|
||||||
.device-card[data-offline="true"] {
|
.device-card[data-offline="true"] {
|
||||||
opacity: 0.6;
|
opacity: 0.6;
|
||||||
|
@ -14,3 +14,55 @@ export const generateShortId = () => {
|
|||||||
return Date.now().toString(36) + Math.random().toString(36).substr(2, 8);
|
return Date.now().toString(36) + Math.random().toString(36).substr(2, 8);
|
||||||
};
|
};
|
||||||
export default generateShortId;
|
export default generateShortId;
|
||||||
|
|
||||||
|
// 获取设备实时状态的
|
||||||
|
/**
|
||||||
|
* 获取设备状态(带自动轮询)
|
||||||
|
* @param {Object} options - 配置对象
|
||||||
|
* @param {number} options.functionMode - 功能模式
|
||||||
|
* @param {string} options.batchId - 批次ID
|
||||||
|
* @param {Object} options.sendInfo - 设备信息
|
||||||
|
* @param {string} options.sendInfo.typeName - 类型名称
|
||||||
|
* @param {string} options.sendInfo.deviceImei - 设备IMEI
|
||||||
|
* @param {number} [options.interval=500] - 轮询间隔(毫秒)
|
||||||
|
* @param {Function} apiClient - 接口调用函数
|
||||||
|
*/
|
||||||
|
export async function getdeviceSTatus({
|
||||||
|
functionMode,
|
||||||
|
batchId,
|
||||||
|
typeName,
|
||||||
|
deviceImei,
|
||||||
|
interval
|
||||||
|
}, apiClient) {
|
||||||
|
const checkStatus = async () => {
|
||||||
|
try {
|
||||||
|
const res = await apiClient({
|
||||||
|
functionMode,
|
||||||
|
batchId,
|
||||||
|
typeName,
|
||||||
|
deviceImei
|
||||||
|
});
|
||||||
|
if (res.code !== 200) {
|
||||||
|
throw new Error(res.msg || '请求失败');
|
||||||
|
}
|
||||||
|
switch (res.data.functionAccess) {
|
||||||
|
case 'OK':
|
||||||
|
return res;
|
||||||
|
case 'ACTIVE':
|
||||||
|
await new Promise(r => setTimeout(r, interval));
|
||||||
|
return checkStatus();
|
||||||
|
case 'FAILED':
|
||||||
|
throw new Error('设备操作失败');
|
||||||
|
case 'TIMEOUT':
|
||||||
|
throw new Error('设备响应超时');
|
||||||
|
default:
|
||||||
|
throw new Error('未知状态');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('设备状态轮询错误:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return checkStatus();
|
||||||
|
}
|
Reference in New Issue
Block a user