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