|
@@ -5,7 +5,6 @@ import { login, logout, getInfo } from '@/api/login'
|
|
|
import { getToken, setToken, removeToken } from '@/utils/auth'
|
|
|
import { UserState, UserForm } from '@/types/store'
|
|
|
import { Module } from 'vuex'
|
|
|
-import WebSocketManager from '@/utils/WebSocketManager.js';
|
|
|
const baseUrl = config.baseUrl
|
|
|
|
|
|
const user: Module<UserState, UserState> = {
|
|
@@ -99,6 +98,7 @@ const user: Module<UserState, UserState> = {
|
|
|
login(username, password, code, uuid, referrerType, referrerId, latitude, longitude).then((res: any) => {
|
|
|
setToken(res.token)
|
|
|
commit('SET_TOKEN', res.token)
|
|
|
+
|
|
|
resolve(res)
|
|
|
}).catch(error => {
|
|
|
reject(error)
|
|
@@ -131,26 +131,9 @@ const user: Module<UserState, UserState> = {
|
|
|
commit('SET_NICKNAME', res.user.nickName)
|
|
|
commit('SET_USERID', res.user.userId)
|
|
|
|
|
|
+ uni.setStorageSync('userType', res.user.userId)
|
|
|
|
|
|
-
|
|
|
- if (this.wsManager) {
|
|
|
- this.wsManager.closeConnection();
|
|
|
- } else {
|
|
|
- //获取账户时,连接soket
|
|
|
- const ms = new WebSocketManager(res.user.userId);
|
|
|
- // 设置消息回调
|
|
|
- ms.onMessage(data => {
|
|
|
- console.log("处理消息逻辑", data.data)
|
|
|
- // 处理消息逻辑
|
|
|
- if (data.type === 'msgUnreadCount') {
|
|
|
- commit('SET_MESSAGECOUNT', data.data);
|
|
|
- }
|
|
|
- });
|
|
|
- // 建立连接
|
|
|
- ms.connect();
|
|
|
- commit('SET_MESSAGE', ms)
|
|
|
-
|
|
|
- }
|
|
|
+ uni.$u.connectSoket(res.user.userId);
|
|
|
|
|
|
|
|
|
resolve(res)
|
|
@@ -169,6 +152,8 @@ const user: Module<UserState, UserState> = {
|
|
|
commit('SET_PERMISSIONS', [])
|
|
|
removeToken()
|
|
|
|
|
|
+ //清除soket
|
|
|
+ uni.$u.closeSoket();
|
|
|
uni.setStorageSync('userType', 1)
|
|
|
// uni.setStorageSync('userId', null)
|
|
|
uni.removeStorageSync('userId')
|
|
@@ -182,6 +167,9 @@ const user: Module<UserState, UserState> = {
|
|
|
handleMessageCount({ commit, state }, count) {
|
|
|
commit('SET_MESSAGECOUNT', count);
|
|
|
},
|
|
|
+ handleSoket({ commit, state }, ms) {
|
|
|
+ commit('SET_MESSAGE', ms);
|
|
|
+ },
|
|
|
handlerAddress({ commit, state }, address) {
|
|
|
commit('SET_ADDRESSINFO', address);
|
|
|
},
|
|
@@ -194,6 +182,7 @@ const user: Module<UserState, UserState> = {
|
|
|
commit('SET_ROLES', [])
|
|
|
commit('SET_PERMISSIONS', [])
|
|
|
removeToken()
|
|
|
+ uni.$u.closeSoket();
|
|
|
uni.removeStorageSync('userId')
|
|
|
storage.clean()
|
|
|
})
|