| | |
| | | import Vue from 'vue' |
| | | import Vuex from 'vuex' |
| | | import { webSocketUrl } from '@/api/request.js' |
| | | Vue.use(Vuex) |
| | | |
| | | // 动态底部tabbar |
| | | const userRoleTabbar = { |
| | | first: [{ |
| | | pagePath: "pages/tabbar-page/index-tabbar/index-tabbar", |
| | | iconPath: "../../static/tabBar-icon/Gfayun.png", |
| | | selectedIconPath: "../../static/tabBar-icon/Bfayun1.png", |
| | | text: "首页" |
| | | pagePath: 'pages/tabbar-page/index-tabbar/index-tabbar', |
| | | iconPath: '../../static/tabBar-icon/home.png', |
| | | selectedIconPath: '../../static/tabBar-icon/homeblue.png', |
| | | text: '首页' |
| | | }, |
| | | { |
| | | pagePath: "pages/tabbar-page/myPage-tabbar/myPage-tabbar", |
| | | iconPath: "../../static/tabBar-icon/Gmine10.png", |
| | | selectedIconPath: "../../static/tabBar-icon/Bmine57.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: '我的' |
| | | } |
| | | ], |
| | | second: [{ |
| | | pagePath: "pages/tabbar-page/index-tabbar/index-tabbar", |
| | | iconPath: "../../static/tabBar-icon/Ghome.png", |
| | | selectedIconPath: "../../static/tabBar-icon/Bhome.png", |
| | | text: "首页" |
| | | pagePath: 'pages/tabbar-page/index-tabbar/index-tabbar', |
| | | iconPath: '../../static/tabBar-icon/home.png', |
| | | selectedIconPath: '../../static/tabBar-icon/homeblue.png', |
| | | text: '首页' |
| | | }, |
| | | { |
| | | pagePath: "pages/tabbar-page/myPage-tabbar/myPage-tabbar", |
| | | iconPath: "../../static/tabBar-icon/Gmine10.png", |
| | | selectedIconPath: "../../static/tabBar-icon/Bmine57.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: '我的' |
| | | } |
| | | ] |
| | | } |
| | |
| | | userInfo: {}, |
| | | roleType: null, // 1客户,2货代,3司机 |
| | | userTabbar: [], // 用户所在角色底部菜单, |
| | | fleetDriverDataLength: 0 |
| | | // 称重时的重量 |
| | | globalweigh: 0, |
| | | // 消息推送 |
| | | globalmessage: '', |
| | | // 全局weihousecode |
| | | globalweighHouseCode: '', |
| | | // 全局红外状态 |
| | | globalinfraredStatus: false, |
| | | // 司机修改个人信息 |
| | | globaluserInfo: { |
| | | phone: '', |
| | | name: '', |
| | | username: '', |
| | | type: 3, |
| | | idCard: '', |
| | | carNo: '', |
| | | carImg: '', |
| | | drivingImg: '', |
| | | axleNum: '', |
| | | weight: '', |
| | | userId: '' |
| | | }, |
| | | globalisconnect: true, |
| | | globalisUploadimg: false, |
| | | globalisLogin: false, |
| | | socketTask: null, |
| | | websocketData: null, // 存放从后端接收到的websocket数据 |
| | | globalIntervalId: null, |
| | | }, |
| | | mutations: { |
| | | lengthchange(state, payload) { |
| | |
| | | state.userTabbar = userRoleTabbar.second |
| | | uni.setStorageSync('userTabbar', state.userTabbar) |
| | | } |
| | | |
| | | |
| | | }, |
| | | // 改变重量 |
| | | changeWeigh(state, payload) { |
| | | state.globalweigh = payload |
| | | console.log(state.globalweigh, '全局重量改变了') |
| | | }, |
| | | // 消息推送 |
| | | pushMessage(state, payload) { |
| | | state.globalmessage = payload |
| | | }, |
| | | // 改变weighHouseCode |
| | | changeweighHouseCode(state, payload) { |
| | | state.globalweighHouseCode = payload |
| | | console.log(state.globalweighHouseCode, 'globalweighHouseCode改变了') |
| | | }, |
| | | // 改变红外状态 |
| | | changeinfraredStatus(state, payload) { |
| | | state.globalinfraredStatus = payload |
| | | }, |
| | | changeuserInfo(state, payload) { |
| | | state.globaluserInfo = payload |
| | | }, |
| | | // 改版全局websocket状态 |
| | | changeisconnect(state, payload) { |
| | | state.globalisconnect = payload |
| | | }, |
| | | changeisUploadimg(state, payload) { |
| | | state.globalisUploadimg = payload |
| | | }, |
| | | changeisLogin(state, payload) { |
| | | state.globalisLogin = payload |
| | | console.log(state.globalisLogin, '全局登录状态改变了') |
| | | }, |
| | | setWebsocketData(state, data) { |
| | | state.websocketData = data |
| | | } |
| | | }, |
| | | actions: { |
| | | websocketInit({ state, dispatch, commit }) { |
| | | let wsUrl = `${webSocketUrl}?access_token=${uni.getStorageSync('token')}` |
| | | state.socketTast = uni.connectSocket({ |
| | | url: wsUrl, |
| | | header: { CLIENT_TOC: 'Y' }, |
| | | complete: res => { |
| | | console.log(res, 'socket结果') |
| | | if (res.errMsg === 'connectSocket:ok') { |
| | | commit('changeisconnect', true) |
| | | } |
| | | } |
| | | }) |
| | | 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')) |
| | | }, |
| | | websocketOnOpen({ state, commit }) { |
| | | console.log('onOpen') |
| | | state.globalIntervalId = setInterval(() => { |
| | | state.socketTast.send({ |
| | | data: JSON.stringify({ type: 'ping' }), |
| | | success(e) { |
| | | console.log(e, '发送心跳成功') |
| | | } |
| | | }) |
| | | }, 30000) |
| | | }, |
| | | websocketOnClose({ state, commit }) { |
| | | if (!state.socketTast) return |
| | | state.socketTast.close(e => { |
| | | commit('changeisconnect', false) |
| | | }) |
| | | console.log('ws关闭') |
| | | }, |
| | | websocketOnError(e) { |
| | | console.log('socket报错', e) |
| | | }, |
| | | // 接收数据 |
| | | websocketOnMessage({ state, commit }, result) { |
| | | commit('setWebsocketData', result) |
| | | } |
| | | } |
| | | }) |
| | | |
| | | export default store |
| | | export default store |