From 8c4dd05b10fcaeb94c09613699aab923318a1c6d Mon Sep 17 00:00:00 2001 From: qingyiay <2386314947@qq.com> Date: 星期日, 02 七月 2023 18:13:27 +0800 Subject: [PATCH] 称重逻辑简化,提高可读性 --- store/index.js | 90 +++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 87 insertions(+), 3 deletions(-) diff --git a/store/index.js b/store/index.js index 72a6b9c..5b11172 100644 --- a/store/index.js +++ b/store/index.js @@ -1,5 +1,6 @@ import Vue from 'vue' import Vuex from 'vuex' +import { webSocketUrl } from '@/api/request.js' Vue.use(Vuex) // 鍔ㄦ�佸簳閮╰abbar @@ -28,6 +29,31 @@ iconPath: '../../static/tabBar-icon/home.png', selectedIconPath: '../../static/tabBar-icon/homeblue.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: '鎴戠殑' + } + ], + 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/customer-my/faYunstatistics/faYunstatistics', @@ -71,8 +97,12 @@ weight: '', userId: '' }, - globalisconnect: false, - globalisUploadimg: false + globalisconnect: true, + globalisUploadimg: false, + globalisLogin: false, + socketTask: null, + websocketData: null, // 瀛樻斁浠庡悗绔帴鏀跺埌鐨剋ebsocket鏁版嵁 + globalIntervalId: null, }, mutations: { lengthchange(state, payload) { @@ -89,6 +119,9 @@ uni.setStorageSync('userTabbar', state.userTabbar) } else if (roleType == 2 || roleType == 3) { state.userTabbar = userRoleTabbar.second + uni.setStorageSync('userTabbar', state.userTabbar) + } else if (roleType == 4) { + state.userTabbar = userRoleTabbar.three uni.setStorageSync('userTabbar', state.userTabbar) } }, @@ -119,8 +152,59 @@ }, 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 \ No newline at end of file -- Gitblit v1.9.1