霸王餐更改
This commit is contained in:
@@ -90,7 +90,6 @@ const useWebSocket = (options = {}) => {
|
||||
socketTask.value.onOpen(() => {
|
||||
// 初始化 初始购物车
|
||||
sendMessage(initMessage)
|
||||
uni.hideLoading();
|
||||
});
|
||||
socketTask.value.onMessage((res) => {
|
||||
receivedMessages.value = JSON.parse(res.data)
|
||||
@@ -113,11 +112,10 @@ const useWebSocket = (options = {}) => {
|
||||
title: '操作异常,请重新扫码',
|
||||
icon: 'none'
|
||||
});
|
||||
console.log('服务器正常关闭,停止重连');
|
||||
autoReconnect.value = false;
|
||||
setTimeout(() => {
|
||||
uni.pro.switchTab('index/index');
|
||||
}, 1000)
|
||||
}, 1500)
|
||||
return false;
|
||||
}
|
||||
if (autoReconnect.value && !isManuallyClosed.value) {
|
||||
@@ -157,7 +155,8 @@ const useWebSocket = (options = {}) => {
|
||||
isPongReceived.value = false; // 每次发送心跳消息前重置标记
|
||||
socketTask.value.send({
|
||||
data: JSON.stringify({
|
||||
type: 'ping_interval'
|
||||
type: 'ping_interval',
|
||||
set: 'shopping'
|
||||
}),
|
||||
success: () => {
|
||||
console.log('心跳消息发送成功');
|
||||
@@ -180,8 +179,7 @@ const useWebSocket = (options = {}) => {
|
||||
const handlePong = (res) => {
|
||||
try {
|
||||
let data = JSON.parse(res.data);
|
||||
if (data.msg === 'ok' && data.msg_id ==
|
||||
'ping_interval') {
|
||||
if (data.msg === 'ok' && data.msg_id == 'ping_interval') {
|
||||
isPongReceived.value = true;
|
||||
console.log('收到心跳响应,清除超时定时器');
|
||||
clearTimeout(pongTimer);
|
||||
@@ -250,10 +248,13 @@ const useWebSocket = (options = {}) => {
|
||||
const reconnectInterval = initialReconnectInterval * Math.pow(2, reconnectAttempts.value - 1);
|
||||
const randomizedInterval = reconnectInterval + Math.floor(Math.random() * 1000);
|
||||
uni.showLoading({
|
||||
title: `尝试第 ${reconnectAttempts.value} 次重连`,
|
||||
title: `正在努力连接..`,
|
||||
mask: true
|
||||
})
|
||||
console.log(`尝试第 ${reconnectAttempts.value} 次重连,重连间隔: ${randomizedInterval}ms...`);
|
||||
setTimeout(() => {
|
||||
uni.hideLoading();
|
||||
}, 1000)
|
||||
reconnectTimer.value = setTimeout(() => {
|
||||
connect();
|
||||
}, randomizedInterval);
|
||||
|
||||
Reference in New Issue
Block a user