| | |
| | | 'https://mx.jzeg.cn:9096/appimg/image/tour/driver/sj43.jpg', |
| | | 'https://mx.jzeg.cn:9096/appimg/image/tour/driver/sj44.jpg', |
| | | ], |
| | | wsgVisiable: false, //磅房忙碌弹窗控制 |
| | | wsgContent: '', |
| | | globalIsFirstWeighing: 1, //是否是第一次上磅 |
| | | confirmWeighVisiable: false, //磅房管理确认称重完成提示弹窗 |
| | | confirmWeighContent: '' |
| | | }, |
| | | mutations: { |
| | | lengthchange(state, payload) { |
| | |
| | | changeuserInfo(state, payload) { |
| | | state.globaluserInfo = payload |
| | | }, |
| | | changesocketTask(state, payload) { |
| | | state.socketTask = payload |
| | | }, |
| | | // 改版全局websocket状态 |
| | | changeisconnect(state, payload) { |
| | | state.globalisconnect = payload |
| | |
| | | }, |
| | | // 改变重连次数 |
| | | changereconnectNum(state, payload) { |
| | | if (state.connectNum < 6) { |
| | | state.connectNum += payload |
| | | if (payload.isWeigh) { |
| | | state.connectNum = payload.connectNum |
| | | } else { |
| | | state.connectNum = payload |
| | | if (state.connectNum < 6) { |
| | | state.connectNum += payload.connectNum |
| | | } else { |
| | | state.connectNum = payload.connectNum |
| | | } |
| | | } |
| | | }, |
| | | changeablePrintInduction(state, payload) { |
| | |
| | | }, |
| | | changeablePrintOut(state, payload) { |
| | | state.ablePrintOut = payload |
| | | console.log(state.ablePrintOut, '出门证’'); |
| | | }, |
| | | changewsgVisiable(state, payload) { |
| | | state.wsgVisiable = payload |
| | | }, |
| | | changewsgContent(state, payload) { |
| | | state.wsgContent = payload |
| | | }, |
| | | changeglobalIsFirstWeighing(state, payload) { |
| | | state.globalIsFirstWeighing = payload |
| | | }, |
| | | changeconfirmWeighVisiable(state, payload) { |
| | | state.confirmWeighVisiable = payload |
| | | }, |
| | | changeconfirmWeighContent(state, payload) { |
| | | state.confirmWeighContent = payload |
| | | } |
| | | }, |
| | | actions: { |
| | | websocketInit({ state, dispatch, commit }) { |
| | | let wsUrl = `${webSocketUrl}?access_token=${uni.getStorageSync('token')}` |
| | | state.socketTast = uni.connectSocket({ |
| | | state.socketTask = uni.connectSocket({ |
| | | url: wsUrl, |
| | | header: { CLIENT_TOC: 'Y' }, |
| | | success: res => { |
| | |
| | | console.log('ws失败'); |
| | | commit('changereconnectState', false) |
| | | dispatch('reconnect') |
| | | commit('changeisconnect', false) |
| | | } |
| | | }) |
| | | state.socketTast.onOpen(() => dispatch('websocketOnOpen')) |
| | | state.socketTast.onMessage(result => dispatch('websocketOnMessage', result.data)) |
| | | state.socketTast.onClose(e => dispatch('websocketOnClose', e)) |
| | | state.socketTast.onError(e => dispatch('websocketOnError', e)) |
| | | state.socketTask.onOpen(() => dispatch('websocketOnOpen')) |
| | | state.socketTask.onMessage(result => dispatch('websocketOnMessage', result.data)) |
| | | state.socketTask.onClose(e => dispatch('websocketOnClose', e)) |
| | | state.socketTask.onError(e => dispatch('websocketOnError', e)) |
| | | }, |
| | | websocketOnOpen({ state, commit }) { |
| | | console.log('ws打开') |
| | | clearInterval(state.reconnectTimeOut) |
| | | clearInterval(state.globalIntervalId) |
| | | state.globalIntervalId = setInterval(() => { |
| | | state.socketTast.send({ |
| | | state.socketTask.send({ |
| | | data: JSON.stringify({ type: 'ping' }), |
| | | success(e) { |
| | | console.log(e, '发送心跳成功') |
| | |
| | | }, 30000) |
| | | }, |
| | | websocketOnClose({ state, commit, dispatch }, e) { |
| | | if (!state.socketTast) return |
| | | if (!state.socketTask) return |
| | | console.log('ws关闭', e) |
| | | state.socketTast.close(e => { |
| | | state.socketTask.close(e => { |
| | | commit('changeisconnect', false) |
| | | }) |
| | | clearInterval(state.globalIntervalId) |
| | | clearInterval(state.reconnectTimeOut) |
| | | state.socketTast = null |
| | | state.socketTask = null |
| | | commit('changereconnectState', false) |
| | | if (state.connectNum < 6 && state.globalisLogin) { |
| | | console.log(state.connectNum, state.connectNum.connectNum, '链接数'); |
| | | if (state.connectNum < 6 || state.connectNum.connectNum < 6 && state.globalisLogin) { |
| | | uni.showToast({ |
| | | title: `连接失败,正在尝试第${state.connectNum}次连接`, |
| | | title: '连接失败,正在尝试重新连接', |
| | | icon: 'none' |
| | | }) |
| | | commit('changereconnectNum', 1) |
| | | commit('changereconnectNum', { connectNum: 1, isWeigh: false }) |
| | | dispatch('reconnect') |
| | | } else if (state.connectNum >= 6 && state.globalisLogin) { |
| | | commit('changereconnectNum', 1) |
| | | commit('changereconnectNum', { connectNum: 1, isWeigh: false }) |
| | | uni.showToast({ |
| | | title: '网络异常,请稍后重试', |
| | | icon: 'none' |
| | |
| | | console.log('ws报错', e) |
| | | clearInterval(state.globalIntervalId) |
| | | clearInterval(state.reconnectTimeOut) |
| | | state.socketTast = null |
| | | state.socketTask = null |
| | | commit('changereconnectState', false) |
| | | if (state.connectNum < 6 && state.globalisLogin) { |
| | | if (state.connectNum < 6 || state.connectNum.connectNum < 6 && state.globalisLogin) { |
| | | uni.showToast({ |
| | | title: `连接失败,正在尝试第${state.connectNum}次连接`, |
| | | title: '连接失败,正在尝试重新连接', |
| | | icon: 'none' |
| | | }) |
| | | commit('changereconnectNum', 1) |
| | | commit('changereconnectNum', { connectNum: 1, isWeigh: false }) |
| | | dispatch('reconnect') |
| | | } else if (state.connectNum > 6 && state.globalisLogin) { |
| | | commit('changereconnectNum', 1) |
| | | commit('changereconnectNum', { connectNum: 1, isWeigh: false }) |
| | | uni.showToast({ |
| | | title: '网络异常,请稍后重试', |
| | | icon: 'none' |