diff --git a/src/permission.js b/src/permission.js index 2934632..75f7cd7 100644 --- a/src/permission.js +++ b/src/permission.js @@ -21,8 +21,6 @@ router.beforeEach((to, from, next) => { // 拉取用户信息 let menus = res.data.menus; let username = res.data.username; - let userId = res.data.userId; - localStorage.setItem('userId', userId); next({ ...to, replace: true }); // store.dispatch('GenerateRoutes', { menus, username }).then(() => { // // 生成可访问的路由表 diff --git a/src/store/modules/user.js b/src/store/modules/user.js index 585d918..bc82909 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -5,6 +5,7 @@ const user = { state: { token: getToken(), name: '', + userId: '', avatar: '', roles: [], permissions: [] @@ -17,6 +18,10 @@ const user = { SET_NAME: (state, name) => { state.name = name; }, + SET_USER_ID: (state, userId) => { + state.userId = userId; + localStorage.setItem('userId', userId); + }, SET_AVATAR: (state, avatar) => { state.avatar = avatar; }, @@ -81,6 +86,7 @@ const user = { commit('SET_ROLES', ['ROLE_DEFAULT']); } commit('SET_NAME', user.username); + commit('SET_USER_ID', user.userId); commit('SET_AVATAR', avatar); resolve(res); }) diff --git a/src/views/customerService.vue b/src/views/customerService.vue index 8bceec5..52e875c 100644 --- a/src/views/customerService.vue +++ b/src/views/customerService.vue @@ -97,8 +97,7 @@ import { send } from '@/api/service'; export default { data() { return { - path: - 'ws://192.168.0.125:1919/webStock/' + localStorage.getItem('userId'), + path: 'ws://192.168.0.125:1919/webStock/' + this.$store.state.user.userId, socket: '', userid: '23941', // 待发送信息