From 7a7412ed5212deb588fc0ec7c26d2378fc8f7561 Mon Sep 17 00:00:00 2001
From: xsx <825657193@qq.com>
Date: Fri, 6 Oct 2023 02:06:20 +0800
Subject: [PATCH] =?UTF-8?q?uniapp=20=20=E5=BC=80=E5=8F=91=E7=BE=A4?=
=?UTF-8?q?=E8=81=8A=E5=8A=9F=E8=83=BD=EF=BC=88=E6=9C=AA=E5=AE=8C=E6=88=90?=
=?UTF-8?q?=EF=BC=89?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../components/friend-item/friend-item.vue | 10 +--
im-uniapp/pages.json | 2 +
im-uniapp/pages/chat/chat-box.vue | 44 ++++++++++--
im-uniapp/pages/common/user-info.vue | 2 +-
im-uniapp/pages/friend/friend.vue | 10 +--
im-uniapp/pages/group/group.vue | 63 +++++++++++++++--
im-uniapp/store/chatStore.js | 7 +-
im-uniapp/store/index.js | 4 +-
im-uniapp/store/uiStore.js | 68 -------------------
9 files changed, 109 insertions(+), 101 deletions(-)
delete mode 100644 im-uniapp/store/uiStore.js
diff --git a/im-uniapp/components/friend-item/friend-item.vue b/im-uniapp/components/friend-item/friend-item.vue
index c3d1956..54e52bc 100644
--- a/im-uniapp/components/friend-item/friend-item.vue
+++ b/im-uniapp/components/friend-item/friend-item.vue
@@ -5,7 +5,7 @@
{{ friend.nickName}}
- {{ online?"[在线]":"[离线]"}}
+ {{ friend.online?"[在线]":"[离线]"}}
@@ -26,14 +26,6 @@
props: {
friend: {
type: Object
- },
- index: {
- type: Number
- }
- },
- computed: {
- online() {
- return this.$store.state.friendStore.friends[this.index].online;
}
}
}
diff --git a/im-uniapp/pages.json b/im-uniapp/pages.json
index bc2ea1c..bb8422d 100644
--- a/im-uniapp/pages.json
+++ b/im-uniapp/pages.json
@@ -36,6 +36,8 @@
"path": "pages/chat/chat-box"
}, {
"path": "pages/friend/friend-add"
+ }, {
+ "path": "pages/group/group-info"
}],
"globalStyle": {
"navigationBarTextStyle": "black",
diff --git a/im-uniapp/pages/chat/chat-box.vue b/im-uniapp/pages/chat/chat-box.vue
index 6420e99..712a8da 100644
--- a/im-uniapp/pages/chat/chat-box.vue
+++ b/im-uniapp/pages/chat/chat-box.vue
@@ -226,7 +226,36 @@
}
- }
+ },
+ loadGroup(groupId) {
+ this.$http({
+ url: `/group/find/${groupId}`,
+ method: 'GET'
+ }).then((group) => {
+ this.group = group;
+ this.$store.commit("updateChatFromGroup", group);
+ this.$store.commit("updateGroup", group);
+
+ });
+
+ this.$http({
+ url: `/group/members/${groupId}`,
+ method: 'get'
+ }).then((groupMembers) => {
+ this.groupMembers = groupMembers;
+ });
+ },
+ loadFriend(friendId) {
+ // 获取对方最新信息
+ this.$http({
+ url: `/user/find/${friendId}`,
+ method: 'GET'
+ }).then((friend) => {
+ this.friend = friend;
+ this.$store.commit("updateChatFromFriend", friend);
+ this.$store.commit("updateFriend", friend);
+ })
+ },
},
computed: {
mine() {
@@ -248,13 +277,18 @@
}
},
onLoad(options) {
- console.log("onLoad")
- let chatIdx = options.chatIdx;
- this.chat = this.$store.state.chatStore.chats[chatIdx];
+ // 聊天数据
+ this.chat = this.$store.state.chatStore.chats[options.chatIdx];
// 激活当前会话
- this.$store.commit("activeChat", chatIdx);
+ this.$store.commit("activeChat", options.chatIdx);
// 页面滚到底部
this.scrollToBottom();
+ // 加载好友或群聊信息
+ if (this.chat.type == "GROUP") {
+ this.loadGroup(this.chat.targetId);
+ } else {
+ this.loadFriend(this.chat.targetId);
+ }
},
onUnload() {
console.log("onShow")
diff --git a/im-uniapp/pages/common/user-info.vue b/im-uniapp/pages/common/user-info.vue
index 929be5f..d6c1605 100644
--- a/im-uniapp/pages/common/user-info.vue
+++ b/im-uniapp/pages/common/user-info.vue
@@ -17,7 +17,7 @@
昵称 :{{userInfo.nickName}}
-
+
签名 :{{userInfo.signature}}
diff --git a/im-uniapp/pages/friend/friend.vue b/im-uniapp/pages/friend/friend.vue
index e063b25..726d9e7 100644
--- a/im-uniapp/pages/friend/friend.vue
+++ b/im-uniapp/pages/friend/friend.vue
@@ -11,7 +11,7 @@
-
+
@@ -36,14 +36,8 @@
url: "/pages/friend/friend-add"
})
}
- },
- onNavigationBarButtonTap(e) {
- if (e.index == 1) {
- uni.navigateTo({
- url: "/pages/friend/friend-search"
- })
- }
}
+
}
diff --git a/im-uniapp/pages/group/group.vue b/im-uniapp/pages/group/group.vue
index 4535a81..7702cf0 100644
--- a/im-uniapp/pages/group/group.vue
+++ b/im-uniapp/pages/group/group.vue
@@ -1,6 +1,20 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -8,15 +22,52 @@
export default {
data() {
return {
-
+
}
},
methods: {
-
+ onFocusSearch() {},
+ onCreateNewGroup() {
+
+ }
}
+
}
-
+ .nav-add {
+ line-height: 56px;
+ cursor: pointer;
+ }
+ }
+
+ .group-items {
+ flex: 1;
+ padding: 0;
+ border: #dddddd solid 1px;
+ overflow: hidden;
+ position: relative;
+
+ .scroll-bar {
+ height: 100%;
+ }
+ }
+ }
+
\ No newline at end of file
diff --git a/im-uniapp/store/chatStore.js b/im-uniapp/store/chatStore.js
index 70eb19f..9d953d9 100644
--- a/im-uniapp/store/chatStore.js
+++ b/im-uniapp/store/chatStore.js
@@ -67,10 +67,12 @@ export default {
let type = msgInfo.groupId ? 'GROUP' : 'PRIVATE';
let targetId = msgInfo.groupId ? msgInfo.groupId : msgInfo.selfSend ? msgInfo.recvId : msgInfo.sendId;
let chat = null;
+ let chatIdx = -1;
for (let idx in state.chats) {
if (state.chats[idx].type == type &&
state.chats[idx].targetId === targetId) {
chat = state.chats[idx];
+ chatIdx = idx;
break;
}
}
@@ -86,7 +88,10 @@ export default {
}
chat.lastSendTime = msgInfo.sendTime;
// 如果不是当前会话,未读加1
- chat.unreadCount++;
+ if(chatIdx != state.activeIndex){
+ chat.unreadCount++;
+ }
+ // 自己回复了消息,说明消息已读
if(msgInfo.selfSend){
chat.unreadCount=0;
}
diff --git a/im-uniapp/store/index.js b/im-uniapp/store/index.js
index 445e1e2..7496fc6 100644
--- a/im-uniapp/store/index.js
+++ b/im-uniapp/store/index.js
@@ -2,15 +2,13 @@ import chatStore from './chatStore.js';
import friendStore from './friendStore.js';
import userStore from './userStore.js';
import groupStore from './groupStore.js';
-import uiStore from './uiStore.js';
import {createStore} from 'vuex';
const store = createStore({
modules: {
chatStore,
friendStore,
userStore,
- groupStore,
- uiStore
+ groupStore
},
state: {},
actions: {
diff --git a/im-uniapp/store/uiStore.js b/im-uniapp/store/uiStore.js
deleted file mode 100644
index 1fd5d5a..0000000
--- a/im-uniapp/store/uiStore.js
+++ /dev/null
@@ -1,68 +0,0 @@
-export default {
- state: {
- userInfo: { // 用户信息窗口
- show: false,
- user: {},
- pos:{
- x:0,
- y:0
- }
- },
- fullImage: { // 全屏大图
- show: false,
- url: ""
- },
- chatPrivateVideo:{ // 私人视频聊天
- show: false,
- master: false, // 是否房主
- friend:{},
- offer:{} // 对方发起带过过来的sdp信息
- },
- videoAcceptor:{ // 视频呼叫选择
- show: false,
-
- friend:{}
- }
-
- },
- mutations: {
- showUserInfoBox(state,user){
- state.userInfo.show = true;
- state.userInfo.user = user;
-
- },
- setUserInfoBoxPos(state,pos){
- let w = document.documentElement.clientWidth;
- let h = document.documentElement.clientHeight;
- state.userInfo.pos.x = Math.min(pos.x,w-350);
- state.userInfo.pos.y = Math.min(pos.y,h-200);
- },
- closeUserInfoBox(state){
- state.userInfo.show = false;
- },
- showFullImageBox(state,url){
- state.fullImage.show = true;
- state.fullImage.url = url;
- },
- closeFullImageBox(state){
- state.fullImage.show = false;
- },
- showChatPrivateVideoBox(state,info){
- state.chatPrivateVideo.show = true;
- state.chatPrivateVideo.friend = info.friend;
- state.chatPrivateVideo.master = info.master;
- state.chatPrivateVideo.offer = info.offer;
- },
- closeChatPrivateVideoBox(state){
- state.chatPrivateVideo.show = false;
- },
- showVideoAcceptorBox(state,friend){
- state.videoAcceptor.show = true;
- state.videoAcceptor.friend = friend;
-
- },
- closeVideoAcceptorBox(state){
- state.videoAcceptor.show = false;
- }
- }
-}
\ No newline at end of file