优化实时获取设备,前端取消掉超时状态,根据服务的超时来判断

This commit is contained in:
fengerli
2025-08-14 14:39:10 +08:00
parent e56bbfe674
commit a773823c3f
3 changed files with 15 additions and 25 deletions

View File

@ -86,10 +86,9 @@
* 获取设备状态(带自动轮询)
* @param {number} val - 功能模式
* @param {string} batchId - 批次ID
* @param {number} [maxRetries=30] - 最大重试次数约30秒
* @param {number} [interval=1000] - 轮询间隔(毫秒)
*/
async getdeviceSTatus(val, batchId, maxRetries = 30, interval =2000) {
async getdeviceSTatus(val, batchId, interval =800) {
let retries = 0;
const checkStatus = async () => {
try {
@ -107,9 +106,6 @@
case 'OK':
return res; // 成功完成
case 'ACTIVE':
if (++retries >= maxRetries) {
throw new Error('操作超时');
}
await new Promise(r => setTimeout(r, interval));
return checkStatus(); // 继续轮询
case 'FAILED':

View File

@ -355,10 +355,9 @@
* 获取设备状态(带自动轮询)
* @param {number} val - 功能模式
* @param {string} batchId - 批次ID
* @param {number} [maxRetries=30] - 最大重试次数约30秒
* @param {number} [interval=1000] - 轮询间隔(毫秒)
*/
async getdeviceSTatus(val, batchId, maxRetries = 30, interval = 2000) {
async getdeviceSTatus(val, batchId, interval = 800) {
let retries = 0;
const checkStatus = async () => {
try {
@ -376,9 +375,6 @@
case 'OK':
return res; // 成功完成
case 'ACTIVE':
if (++retries >= maxRetries) {
throw new Error('操作超时');
}
await new Promise(r => setTimeout(r, interval));
return checkStatus(); // 继续轮询
case 'FAILED':
@ -392,7 +388,6 @@
throw error;
}
};
return checkStatus();
},
filterChinese(e) {
@ -767,36 +762,39 @@
// 获取设备状态
const statusRes = await this.getdeviceSTatus(1);
if (statusRes.data.functionAccess === 'OK') {
// 两个操作都成功,重置状态并显示成功提示
uni.hideLoading(); // ✅ 只有成功才关闭
this.selectedImage = '';
this.file = null;
this.lightModeB = false;
uni.showToast({
title: responseData.msg,
icon: 'success',
});
this.popupType = 'logo';
this.showPopupFlag = true;
this.popupMessage = '上传成功';
this.lightModeB = false
}
} catch (error) {
uni.hideLoading();
uni.showToast({
title: error.message,
icon: 'none'
});
}
} else {
uni.hideLoading();
uni.showToast({
title: responseData.msg,
icon: 'none'
});
}
} catch (e) {
uni.hideLoading();
uni.showToast({
title: error.message,
title: e.message,
icon: 'none'
});
} finally {
uni.hideLoading();
}
// finally {
// uni.hideLoading();
// }
}
})
},

View File

@ -75,10 +75,9 @@
* 获取设备状态(带自动轮询)
* @param {number} val - 功能模式
* @param {string} batchId - 批次ID
* @param {number} [maxRetries=30] - 最大重试次数约30秒
* @param {number} [interval=1000] - 轮询间隔(毫秒)
*/
async getdeviceSTatus(val, batchId, maxRetries = 30, interval = 2000) {
async getdeviceSTatus(val, batchId, interval = 800) {
let retries = 0;
const checkStatus = async () => {
try {
@ -96,9 +95,6 @@
case 'OK':
return res; // 成功完成
case 'ACTIVE':
if (++retries >= maxRetries) {
throw new Error('操作超时');
}
await new Promise(r => setTimeout(r, interval));
return checkStatus(); // 继续轮询
case 'FAILED':