From 1f3ced9780b0f26ba7b985dc89e96c2dd19c3ad1 Mon Sep 17 00:00:00 2001 From: "xie.bx" Date: Mon, 31 Oct 2022 23:23:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81=E9=A3=8E?= =?UTF-8?q?=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- im-ui/src/components/friend/AddFriend.vue | 117 +++++++++++++ im-ui/src/components/friend/FriendItem.vue | 114 +++++++++++++ im-ui/src/components/group/CreateGroup.vue | 8 + im-ui/src/store/friendStore.js | 88 ++++++++++ im-ui/src/store/groupStore.js | 19 +++ im-ui/src/view/Friend.vue | 184 +++++++++++++++++++++ im-ui/src/view/Group.vue | 70 ++++++++ 7 files changed, 600 insertions(+) create mode 100644 im-ui/src/components/friend/AddFriend.vue create mode 100644 im-ui/src/components/friend/FriendItem.vue create mode 100644 im-ui/src/components/group/CreateGroup.vue create mode 100644 im-ui/src/store/friendStore.js create mode 100644 im-ui/src/store/groupStore.js create mode 100644 im-ui/src/view/Friend.vue create mode 100644 im-ui/src/view/Group.vue diff --git a/im-ui/src/components/friend/AddFriend.vue b/im-ui/src/components/friend/AddFriend.vue new file mode 100644 index 0000000..21dd0ff --- /dev/null +++ b/im-ui/src/components/friend/AddFriend.vue @@ -0,0 +1,117 @@ + + + + + diff --git a/im-ui/src/components/friend/FriendItem.vue b/im-ui/src/components/friend/FriendItem.vue new file mode 100644 index 0000000..4717b19 --- /dev/null +++ b/im-ui/src/components/friend/FriendItem.vue @@ -0,0 +1,114 @@ + + + + + diff --git a/im-ui/src/components/group/CreateGroup.vue b/im-ui/src/components/group/CreateGroup.vue new file mode 100644 index 0000000..48d48ea --- /dev/null +++ b/im-ui/src/components/group/CreateGroup.vue @@ -0,0 +1,8 @@ + + + + + diff --git a/im-ui/src/store/friendStore.js b/im-ui/src/store/friendStore.js new file mode 100644 index 0000000..0de5c47 --- /dev/null +++ b/im-ui/src/store/friendStore.js @@ -0,0 +1,88 @@ +import httpRequest from '../api/httpRequest.js' + +export default { + + state: { + friends: [], + activeIndex: -1, + timer: null + }, + mutations: { + initFriendStore(state) { + httpRequest({ + url: '/api/friend/list', + method: 'get' + }).then((friends) => { + this.commit("setFriends",friends); + this.commit("refreshOnlineStatus"); + }) + }, + + setFriends(state, friends) { + state.friends = friends; + }, + updateFriend(state,friendInfo){ + state.friends.forEach((f,index)=>{ + if(f.friendId==friendInfo.friendId){ + state.friends[index] = friendInfo; + } + }) + }, + activeFriend(state, index) { + state.activeIndex = index; + }, + removeFriend(state, index) { + state.friends.splice(index, 1); + }, + addFriend(state, friendInfo) { + state.friends.push(friendInfo); + }, + refreshOnlineStatus(state){ + let userIds = []; + if(state.friends.length ==0){ + return; + } + state.friends.forEach((f)=>{userIds.push(f.friendId)}); + httpRequest({ + url: '/api/user/online', + method: 'get', + params: {userIds: userIds.join(',')} + }).then((onlineIds) => { + this.commit("setOnlineStatus",onlineIds); + }) + + // 30s后重新拉取 + clearTimeout(state.timer); + state.timer = setTimeout(()=>{ + this.commit("refreshOnlineStatus"); + },30000) + }, + setOnlineStatus(state,onlineIds){ + state.friends.forEach((f)=>{ + let onlineFriend = onlineIds.find((id)=> f.friendId==id); + f.online = onlineFriend != undefined; + }); + + let activeFriend = state.friends[state.activeIndex]; + state.friends.sort((f1,f2)=>{ + if(f1.online&&!f2.online){ + return -1; + } + if(f2.online&&!f1.online){ + return 1; + } + return 0; + }); + + // 重新排序后,activeIndex指向的好友可能会变化,需要重新指定 + if(state.activeIndex >=0){ + state.friends.forEach((f,i)=>{ + if(f.friendId == activeFriend.friendId){ + state.activeIndex = i; + } + }) + } + } + + } +} diff --git a/im-ui/src/store/groupStore.js b/im-ui/src/store/groupStore.js new file mode 100644 index 0000000..f6c4f04 --- /dev/null +++ b/im-ui/src/store/groupStore.js @@ -0,0 +1,19 @@ +import httpRequest from '../api/httpRequest.js' + +export default { + + state: { + groups: [], + activeIndex: -1, + }, + mutations: { + initGroupStore(state, userInfo) { + httpRequest({ + url: '/api/friends/list', + method: 'get' + }).then((friendsList) => { + this.commit("setFriendsList",friendsList); + this.commit("refreshOnlineStatus"); + }) + }, +} \ No newline at end of file diff --git a/im-ui/src/view/Friend.vue b/im-ui/src/view/Friend.vue new file mode 100644 index 0000000..8eb31eb --- /dev/null +++ b/im-ui/src/view/Friend.vue @@ -0,0 +1,184 @@ + + + + + diff --git a/im-ui/src/view/Group.vue b/im-ui/src/view/Group.vue new file mode 100644 index 0000000..9603f13 --- /dev/null +++ b/im-ui/src/view/Group.vue @@ -0,0 +1,70 @@ + + + + +