819527061@qq.com
2024-07-30 e52e720168541aa02e0326a505d251f42828aedf
store/index.js
@@ -43,30 +43,34 @@
         text: '我的'
      }
   ],
   three: [{
         pagePath: 'pages/tabbar-page/index-tabbar/index-tabbar',
         iconPath: '../../static/tabBar-icon/home.png',
         selectedIconPath: '../../static/tabBar-icon/homeblue.png',
         text: '首页'
      },
   three: [
      // {
      //    pagePath: 'pages/tabbar-page/index-tabbar/index-tabbar',
      //    iconPath: '../../static/tabBar-icon/home.png',
      //    selectedIconPath: '../../static/tabBar-icon/homeblue.png',
      //    text: '首页'
      // },
      {
         pagePath: 'pages/driver-page/driver-index/bill-of-lading-details/selectOrderPlan/selectOrderPlan',
         iconPath: '../../static/tabBar-icon/checking.png',
         selectedIconPath: '../../static/tabBar-icon/checkingblue.png',
         text: '验质'
      },
      {
      },{
         pagePath: 'pages/customer-page/zhijian-bangfang/zhijian-bangfang',
         iconPath: '../../static/tabBar-icon/bang.png',
         selectedIconPath: '../../static/tabBar-icon/bangblue.png',
         text: '磅房'
      },{
         pagePath: 'pages/customer-page/customer-my/faYunstatistics/faYunstatistics',
         iconPath: '../../static/tabBar-icon/statistics.png',
         selectedIconPath: '../../static/tabBar-icon/statisticsactive.png',
         text: '统计'
      },
      {
      },{
         pagePath: 'pages/tabbar-page/myPage-tabbar/myPage-tabbar',
         iconPath: '../../static/tabBar-icon/Gmine10.png',
         selectedIconPath: '../../static/tabBar-icon/Bmine57.png',
         text: '我的'
      }
      },
   ]
}
const store = new Vuex.Store({
@@ -103,6 +107,68 @@
      socketTask: null,
      websocketData: null, // 存放从后端接收到的websocket数据
      globalIntervalId: null,
      is_open_socket: false, //避免重复连接
      connectNum: 1, //重连次数,
      reconnectTimeOut: null,
      // 称重稳定态  0/稳定 1/非稳定  非稳定态不能点称重
      globalWarning: false,
      globalShowWeigh: [],
      isFirstLogin: true,
      driverTourImgList: ['https://mx.jzeg.cn:9095/appimg/image/tour/driver/sj1.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/driver/sj2.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/driver/sj3.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/driver/sj4.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/driver/sj5.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/driver/sj6.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/driver/sj7.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/driver/sj8.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/driver/sj9.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/driver/sj10.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/driver/sj11.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/driver/sj12.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/driver/sj13.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/driver/sj14.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/driver/sj15.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/driver/sj16.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/driver/sj17.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/driver/sj18.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/driver/sj19.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/driver/sj20.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/driver/sj21.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/driver/sj22.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/driver/sj23.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/driver/sj24.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/driver/sj25.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/driver/sj26.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/driver/sj27.jpg',
      ],
      customerTourImgList: ['https://mx.jzeg.cn:9095/appimg/image/tour/quality/quality1.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/quality/quality2.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/quality/quality3.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/quality/quality4.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/quality/quality5.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/quality/quality6.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/quality/quality7.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/quality/quality8.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/quality/quality9.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/quality/quality10.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/quality/quality11.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/quality/quality12.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/quality/quality13.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/quality/quality14.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/quality/quality15.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/quality/quality16.jpg',
         'https://mx.jzeg.cn:9095/appimg/image/tour/quality/quality17.jpg',
      ],
      qualityTourImgList:['https://mx.jzeg.cn:9095/appimg/image/tour/quality/quality1.jpg',
      'https://mx.jzeg.cn:9095/appimg/image/tour/quality/quality2.jpg',
      'https://mx.jzeg.cn:9095/appimg/image/tour/quality/quality3.jpg',
      'https://mx.jzeg.cn:9095/appimg/image/tour/quality/quality4.jpg',
      'https://mx.jzeg.cn:9095/appimg/image/tour/quality/quality5.jpg',
      'https://mx.jzeg.cn:9095/appimg/image/tour/quality/quality6.jpg',
      'https://mx.jzeg.cn:9095/appimg/image/tour/quality/quality7.jpg',
      'https://mx.jzeg.cn:9095/appimg/image/tour/quality/quality8.jpg',
      'https://mx.jzeg.cn:9095/appimg/image/tour/quality/quality9.jpg']
   },
   mutations: {
      lengthchange(state, payload) {
@@ -114,13 +180,14 @@
      // 设置底部栏
      setUserTabbar(state, roleType) {
         state.roleType = roleType
         if (roleType == 1) {
         console.log(roleType,'roledType===')
         if (roleType === 1) {
            state.userTabbar = userRoleTabbar.first
            uni.setStorageSync('userTabbar', state.userTabbar)
         } else if (roleType == 2 || roleType == 3) {
         } else if (roleType === 2 || roleType === 3) {
            state.userTabbar = userRoleTabbar.second
            uni.setStorageSync('userTabbar', state.userTabbar)
         } else if (roleType == 4) {
         } else if (roleType === 4) {
            state.userTabbar = userRoleTabbar.three
            uni.setStorageSync('userTabbar', state.userTabbar)
         }
@@ -157,32 +224,73 @@
         state.globalisLogin = payload
         console.log(state.globalisLogin, '全局登录状态改变了')
      },
      changesocketTask(state, payload) {
         state.socketTask = payload
      },
      setWebsocketData(state, data) {
         state.websocketData = data
      },
      // 改变重连状态
      changereconnectState(state, payload) {
         state.is_open_socket = payload
      },
      // 改变重连次数
      changereconnectNum(state, payload) {
         if (payload.isWeigh) {
            state.connectNum = payload.connectNum
         } else {
            if (state.connectNum < 6) {
               state.connectNum += payload.connectNum
            } else {
               state.connectNum = payload.connectNum
            }
         }
      },
      // 改变稳定态
      changeWarning(state, payload) {
         state.globalWarning = payload
      },
      changeglobalShowWeigh(state, payload) {
         state.globalShowWeigh = payload
      },
      changeisFirstLogin(state, payload) {
         state.isFirstLogin = payload
         console.log(state.isFirstLogin, '第一次登录');
      }
   },
   actions: {
      websocketInit({ state, dispatch, commit }) {
         let wsUrl = `${webSocketUrl}?access_token=${uni.getStorageSync('token')}`
         state.socketTast = uni.connectSocket({
         // let wsUrl = `${webSocketUrl}?UUID=boyingtest`
         state.socketTask = uni.connectSocket({
            url: wsUrl,
            header: { CLIENT_TOC: 'Y' },
            complete: res => {
               console.log(res, 'socket结果')
            success: res => {
               console.log(res, 'socketSuccess')
               if (res.errMsg === 'connectSocket:ok') {
                  commit('changeisconnect', true)
                  commit('changereconnectState', true)
               }
            },
            fail: res => {
               console.log(res, 'socketFail')
               console.log('ws失败');
               commit('changereconnectState', false)
               dispatch('reconnect')
            }
         })
         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'))
         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('onOpen')
         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, '发送心跳成功')
@@ -190,21 +298,77 @@
            })
         }, 30000)
      },
      websocketOnClose({ state, commit }) {
         if (!state.socketTast) return
         state.socketTast.close(e => {
      websocketOnClose({ state, commit, dispatch }, e) {
         if (!state.socketTask) return
         console.log('ws关闭', e)
         state.socketTask.close(e => {
            commit('changeisconnect', false)
         })
         console.log('ws关闭')
         clearInterval(state.globalIntervalId)
         clearInterval(state.reconnectTimeOut)
         state.socketTask = null
         commit('changereconnectState', false)
         if ((state.connectNum < 6 || state.connectNum.connectNum < 6) && state.globalisLogin) {
            // uni.showToast({
            //    title: '连接失败,正在尝试重新连接',
            //    icon: 'none'
            // })
            commit('changereconnectNum', { connectNum: 1, isWeigh: false })
            dispatch('reconnect')
         } else if (state.connectNum >= 6 && state.globalisLogin) {
            commit('changereconnectNum', { connectNum: 1, isWeigh: false })
            uni.showToast({
               title: '网络异常,请稍后重试',
               icon: 'none'
            })
         } else {
            return
         }
      },
      websocketOnError(e) {
         console.log('socket报错', e)
      websocketOnError({ state, commit, dispatch }, e) {
         // 如果重连状态为false则不进行重连,为true才会
         console.log('ws报错', e)
         clearInterval(state.globalIntervalId)
         clearInterval(state.reconnectTimeOut)
         state.socketTask = null
         commit('changereconnectState', false)
         if (state.connectNum < 6 || state.connectNum.connectNum < 6 && state.globalisLogin) {
            // uni.showToast({
            //    title: '连接失败,正在尝试重新连接',
            //    icon: 'none'
            // })
            commit('changereconnectNum', { connectNum: 1, isWeigh: false })
            dispatch('reconnect')
         } else if (state.connectNum > 6 && state.globalisLogin) {
            commit('changereconnectNum', { connectNum: 1, isWeigh: false })
            uni.showToast({
               title: '网络异常,请稍后重试',
               icon: 'none'
            })
         } else {
            return
         }
      },
      // 接收数据
      websocketOnMessage({ state, commit }, result) {
         commit('setWebsocketData', result)
      },
      // 重新连接
      reconnect({ state, commit, dispatch }) {
         console.log(state.is_open_socket, '重新连接socket状态');
         clearInterval(state.globalIntervalId)
         if (!state.is_open_socket && state.globalisLogin) {
            state.reconnectTimeOut = setInterval(() => {
               dispatch('websocketInit')
            }, 5000)
         }
      }
   },
   getters: {
      websocketData:(state) => state.websocketData,
      globalweigh:(state) => state.globalweigh,
      userTabbar: (state) => state.userTabbar,
   }
})
export default store
export default store