| | |
| | | globalIntervalId: null, |
| | | is_open_socket: false, //避免重复连接 |
| | | connectNum: 1, //重连次数, |
| | | reconnectTimeOut: null, |
| | | // 打印出入门证 一次就可以有打印入门证, 两次可以有入门证 出门证 0次一张都没有 |
| | | reconnectTimeOut: null, //重新链接的定时器 |
| | | // 打印出入门证 一次就可以有打印入门证, 两次可以有入门证 出门证 0次一张都没有 |
| | | ablePrintInduction: false, //入门证 |
| | | ablePrintOut: false, //出门证 |
| | | driverTourImgList: ['https://mx.jzeg.cn:9096/appimg/image/tour/driver/sj1.png', |
| | |
| | | '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: '', |
| | | // 称重稳定态 0/稳定 1/非稳定 非稳定态不能点称重 |
| | | globalWarning: false, |
| | | }, |
| | | mutations: { |
| | | lengthchange(state, payload) { |
| | | state.fleetDriverDataLength = payload |
| | | }, |
| | | setUserInfo(state, identity) { |
| | | state.userInfo = userObj[identity] |
| | | }, |
| | |
| | | changeuserInfo(state, payload) { |
| | | state.globaluserInfo = payload |
| | | }, |
| | | // 改版全局websocket状态 |
| | | 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 |
| | | } |
| | | }, |
| | | 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 |
| | | }, |
| | | // 改变稳定态 |
| | | changeWarning(state, payload) { |
| | | state.globalWarning = 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' }, |
| | | header: { |
| | | clientToc: 'Y' , |
| | | 'CLIENT_TOC': 'Y', |
| | | }, |
| | | success: res => { |
| | | console.log(res, 'socketSuccess') |
| | | if (res.errMsg === 'connectSocket:ok') { |
| | |
| | | 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) |
| | | 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) { |
| | | 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' |
| | |
| | | } |
| | | }) |
| | | |
| | | export default store |
| | | export default store |