|
|
|
@ -18,7 +18,15 @@ const chat = { |
|
|
|
// 清空聊天列表
|
|
|
|
CLEAN_CHAT_LIST: (state) => { |
|
|
|
state.chatList = new Array(); |
|
|
|
storage.set(constant.chatList, state.chatList) |
|
|
|
storage.set(constant.chatList, new Array()); |
|
|
|
state.friendList = new Array(); |
|
|
|
storage.set(constant.friendList, new Array()); |
|
|
|
state.groupList = new Array(); |
|
|
|
storage.set(constant.groupList, new Array()); |
|
|
|
state.userObject = {}; |
|
|
|
storage.set(constant.userObject, {}); |
|
|
|
state.groupObject = {}; |
|
|
|
storage.set(constant.groupObject, {}); |
|
|
|
}, |
|
|
|
// 存储好友聊天列表
|
|
|
|
SET_CHAT_FRIEND_LIST: (state, data) => { |
|
|
|
@ -59,12 +67,12 @@ const chat = { |
|
|
|
// 存储用户对象,方便寻找用户名,头像等
|
|
|
|
SET_USER_OBJECT: (state, userObject) => { |
|
|
|
state.userObject[userObject.userId] = userObject; |
|
|
|
storage.set(constant.userObject, state.userObject) |
|
|
|
storage.set(constant.userObject, state.userObject); |
|
|
|
}, |
|
|
|
// 存储群组对象,方便寻找群组名,头像等
|
|
|
|
SET_GROUP_OBJECT: (state, groupObject) => { |
|
|
|
state.groupObject[groupObject.id] = groupObject; |
|
|
|
storage.set(constant.groupObject, state.groupObject) |
|
|
|
storage.set(constant.groupObject, state.groupObject); |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
@ -75,28 +83,46 @@ const chat = { |
|
|
|
commit('CLEAN_CHAT_LIST'); |
|
|
|
// 查询好友
|
|
|
|
getUserAllFriend().then(res => { |
|
|
|
let list = [] |
|
|
|
for(let item of res.data){ |
|
|
|
list.push({type: 0, ...item, userId: params.userId}) |
|
|
|
commit('SET_USER_OBJECT', item) |
|
|
|
let listFriend = [] |
|
|
|
for(let itemFriend of res.data){ |
|
|
|
delete itemFriend["createBy"] |
|
|
|
delete itemFriend["updateBy"] |
|
|
|
delete itemFriend["createTime"] |
|
|
|
delete itemFriend["updateTime"] |
|
|
|
listFriend.push({type: 0, ...itemFriend, userId: params.userId}) |
|
|
|
commit('SET_USER_OBJECT', {...itemFriend, userId: itemFriend.friendId}) |
|
|
|
} |
|
|
|
commit('SET_CHAT_FRIEND_LIST', list) |
|
|
|
commit('SET_CHAT_FRIEND_LIST', listFriend) |
|
|
|
|
|
|
|
// 查询群组
|
|
|
|
getUserAllGroup().then(res1 => { |
|
|
|
let list = [] |
|
|
|
for(let item1 of res1.data){ |
|
|
|
list.push({type: 1, ...item1, userId: params.userId}) |
|
|
|
let listGroup = [] |
|
|
|
for(let itemGroup of res1.data){ |
|
|
|
delete itemGroup["createBy"] |
|
|
|
delete itemGroup["updateBy"] |
|
|
|
delete itemGroup["createTime"] |
|
|
|
delete itemGroup["updateTime"] |
|
|
|
listGroup.push({type: 1, ...itemGroup, userId: params.userId}) |
|
|
|
// 查询群组人员
|
|
|
|
getGroupUser(item1.id).then(res2 => { |
|
|
|
for(let user of res2.data){ |
|
|
|
commit('SET_USER_OBJECT', user) |
|
|
|
getGroupUser(itemGroup.id).then(res2 => { |
|
|
|
for(let itemGroupUser of res2.data){ |
|
|
|
delete itemGroupUser["createBy"] |
|
|
|
delete itemGroupUser["updateBy"] |
|
|
|
delete itemGroupUser["createTime"] |
|
|
|
delete itemGroupUser["updateTime"] |
|
|
|
delete itemGroupUser["groupId"] |
|
|
|
delete itemGroupUser["groupName"] |
|
|
|
commit('SET_USER_OBJECT', itemGroupUser) |
|
|
|
} |
|
|
|
resolve(res2) |
|
|
|
}); |
|
|
|
commit('SET_GROUP_OBJECT', item1) |
|
|
|
delete itemGroup["createBy"] |
|
|
|
delete itemGroup["updateBy"] |
|
|
|
delete itemGroup["createTime"] |
|
|
|
delete itemGroup["updateTime"] |
|
|
|
commit('SET_GROUP_OBJECT', itemGroup) |
|
|
|
} |
|
|
|
commit('SET_CHAT_GROUP_LIST', list) |
|
|
|
commit('SET_CHAT_GROUP_LIST', listGroup) |
|
|
|
}).catch(error => { |
|
|
|
reject(error) |
|
|
|
}) |
|
|
|
|