增加网络波动加载中,增加会员信息扫码充值
This commit is contained in:
@@ -94,12 +94,13 @@ const useWebSocket = (options = {}) => {
|
||||
socketTask.value.onMessage((res) => {
|
||||
receivedMessages.value = JSON.parse(res.data)
|
||||
// receivedMessages.value.push(list);
|
||||
if (receivedMessages.value == 'ok') {
|
||||
console.log('心跳响应正常');
|
||||
// 心跳正常,重置重连尝试次数
|
||||
reconnectAttempts.value = 0;
|
||||
if (receivedMessages.value == 'ok' || receivedMessages.value.operate_type == 'init') {
|
||||
console.log('初始化正常,心跳响应正常');
|
||||
// 清除重连定时器
|
||||
clearTimeout(reconnectTimer.value);
|
||||
reconnectTimer.value = null;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
socketTask.value.onClose((res) => {
|
||||
@@ -109,13 +110,13 @@ const useWebSocket = (options = {}) => {
|
||||
clearTimeout(reconnectTimer.value); // 清除重连定时器
|
||||
if (res.code == '1006') {
|
||||
uni.showToast({
|
||||
title: '操作异常,请重新扫码',
|
||||
title: '网络异常,请重新扫码',
|
||||
icon: 'none'
|
||||
});
|
||||
autoReconnect.value = false;
|
||||
setTimeout(() => {
|
||||
uni.pro.switchTab('index/index');
|
||||
}, 1500)
|
||||
}, 1000)
|
||||
return false;
|
||||
}
|
||||
if (autoReconnect.value && !isManuallyClosed.value) {
|
||||
@@ -179,7 +180,9 @@ const useWebSocket = (options = {}) => {
|
||||
const handlePong = (res) => {
|
||||
try {
|
||||
let data = JSON.parse(res.data);
|
||||
if (data.msg === 'ok' && data.msg_id == 'ping_interval') {
|
||||
if (data.operate_type == "init" || (data.msg === 'ok' &&
|
||||
data.msg_id ==
|
||||
'ping_interval')) {
|
||||
isPongReceived.value = true;
|
||||
console.log('收到心跳响应,清除超时定时器');
|
||||
clearTimeout(pongTimer);
|
||||
@@ -252,9 +255,7 @@ const useWebSocket = (options = {}) => {
|
||||
mask: true
|
||||
})
|
||||
console.log(`尝试第 ${reconnectAttempts.value} 次重连,重连间隔: ${randomizedInterval}ms...`);
|
||||
setTimeout(() => {
|
||||
uni.hideLoading();
|
||||
}, 1000)
|
||||
|
||||
reconnectTimer.value = setTimeout(() => {
|
||||
connect();
|
||||
}, randomizedInterval);
|
||||
@@ -266,7 +267,10 @@ const useWebSocket = (options = {}) => {
|
||||
});
|
||||
clearInterval(heartbeatTimer.value);
|
||||
autoReconnect.value = false;
|
||||
uni.pro.switchTab('index/index');
|
||||
setTimeout(() => {
|
||||
uni.hideLoading();
|
||||
uni.pro.switchTab('index/index');
|
||||
}, 1000)
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user