| | |
| | | clearInterval(state.reconnectTimeOut) |
| | | state.socketTast = null |
| | | commit('changereconnectState', false) |
| | | if (state.connectNum < 6) { |
| | | dispatch('reconnect') |
| | | } else { |
| | | if (state.connectNum < 6 && state.globalisLogin) { |
| | | uni.showToast({ |
| | | title: `连接失败,正在尝试第${state.connectNum}次连接`, |
| | | icon: 'none' |
| | | }) |
| | | commit('changereconnectNum', 1) |
| | | dispatch('reconnect') |
| | | } else if (state.connectNum > 6 && state.globalisLogin) { |
| | | commit('changereconnectNum', 1) |
| | | uni.showToast({ |
| | | title: '网络异常,请稍后重试', |
| | | icon: 'none' |
| | | }) |
| | | } else { |
| | | return |
| | | } |
| | | |
| | | }, |
| | | websocketOnError({ state, commit, dispatch }, e) { |
| | | // 如果重连状态为false则不进行重连,为true才会 |
| | |
| | | clearInterval(state.reconnectTimeOut) |
| | | state.socketTast = null |
| | | commit('changereconnectState', false) |
| | | if (state.connectNum < 6) { |
| | | if (state.connectNum < 6 && state.globalisLogin) { |
| | | uni.showToast({ |
| | | title: `连接失败,正在尝试第${state.connectNum}次连接`, |
| | | icon: 'none' |
| | | }) |
| | | commit('changereconnectNum', 1) |
| | | dispatch('reconnect') |
| | | } else { |
| | | } else if (state.connectNum > 6 && state.globalisLogin) { |
| | | commit('changereconnectNum', 1) |
| | | uni.showToast({ |
| | | title: '网络异常,请稍后重试', |
| | | icon: 'none' |
| | | }) |
| | | } else { |
| | | return |
| | | } |
| | | }, |
| | | // 接收数据 |
| | |
| | | reconnect({ state, commit, dispatch }) { |
| | | console.log(state.is_open_socket, '重新连接socket状态'); |
| | | clearInterval(state.globalIntervalId) |
| | | if (!state.is_open_socket) { |
| | | if (!state.is_open_socket && state.globalisLogin) { |
| | | state.reconnectTimeOut = setInterval(() => { |
| | | dispatch('websocketInit') |
| | | }, 5000) |