即时通信嵌入测试

This commit is contained in:
2024-10-21 16:54:36 +08:00
parent 2d5e601636
commit b9045d5d4c
30 changed files with 1224 additions and 21 deletions

View File

@@ -1,6 +1,6 @@
import { login, logout, getInfo } from '@/api/login'
import { getToken, setToken, removeToken } from '@/utils/auth'
import newVue from '@/main'
const user = {
state: {
token: getToken(),
@@ -25,7 +25,10 @@ const user = {
},
SET_PERMISSIONS: (state, permissions) => {
state.permissions = permissions
}
},
SET_ID: (state, id) => {
state.id = id
},
},
actions: {
@@ -51,6 +54,7 @@ const user = {
return new Promise((resolve, reject) => {
getInfo().then(res => {
const user = res.data.user
console.log(user)
const avatar = (user.avatar == "" || user.avatar == null) ? require("@/assets/images/profile.jpg") : user.avatar;
if (res.data.roles && res.data.roles.length > 0) { // 验证返回的roles是否是一个非空数组
commit('SET_ROLES', res.data.roles)
@@ -58,8 +62,11 @@ const user = {
} else {
commit('SET_ROLES', ['ROLE_DEFAULT'])
}
commit('SET_ID',user.userId)
commit('SET_NAME', user.userName)
commit('SET_AVATAR', avatar)
// TODO 获取用户信息时检查socket连接状态并进行连接
newVue.$webSocket.initWebSocket()
resolve(res)
}).catch(error => {
reject(error)
@@ -75,6 +82,8 @@ const user = {
commit('SET_ROLES', [])
commit('SET_PERMISSIONS', [])
removeToken()
// TODO 用户推出登陆后 关闭socket连接
newVue.$webSocket.close()
resolve()
}).catch(error => {
reject(error)