瀏覽代碼

聊天列表增加好友在线状态

xsx 7 月之前
父節點
當前提交
c5826f41f1
共有 2 個文件被更改,包括 19 次插入4 次删除
  1. 9 2
      im-uniapp/components/chat-item/chat-item.vue
  2. 10 2
      im-web/src/components/chat/ChatItem.vue

+ 9 - 2
im-uniapp/components/chat-item/chat-item.vue

@@ -3,7 +3,7 @@
 		<!--rich-text中的表情包会屏蔽事件,所以这里用一个遮罩层捕获点击事件 -->
 		<view class="mask" @tap="showChatBox()"></view>
 		<view class="left">
-			<head-image :url="chat.headImage" :name="chat.showName"></head-image>
+			<head-image :url="chat.headImage" :name="chat.showName" :online="online"></head-image>
 		</view>
 		<view class="chat-right">
 			<view class="chat-name">
@@ -45,7 +45,7 @@ export default {
 	methods: {
 		showChatBox() {
 			// 初始化期间进入会话会导致消息不刷新
-			if (!getApp().$vm.isInit || this.chatStore.isLoading()) {
+			if (!this.configStore.appInit || this.chatStore.isLoading()) {
 				uni.showToast({
 					title: "正在初始化页面,请稍后...",
 					icon: 'none'
@@ -86,6 +86,13 @@ export default {
 		nodesText() {
 			let text = this.$str.html2Escape(this.chat.lastContent);
 			return this.$emo.transform(text, 'emoji-small')
+		},
+		online() {
+			if (this.chat.type == 'PRIVATE') {
+				let friend = this.friendStore.findFriend(this.chat.targetId);
+				return friend && friend.online;
+			}
+			return false;
 		}
 	}
 }

+ 10 - 2
im-web/src/components/chat/ChatItem.vue

@@ -2,7 +2,7 @@
 	<div class="chat-item" :class="active ? 'active' : ''" @contextmenu.prevent="showRightMenu($event)">
 		<div class="chat-left">
 			<head-image :url="chat.headImage" :name="chat.showName" :size="42"
-				:id="chat.type == 'PRIVATE' ? chat.targetId : 0" :isShowUserInfo="false"></head-image>
+				:id="chat.type == 'PRIVATE' ? chat.targetId : 0" :isShowUserInfo="false" :online="online"></head-image>
 			<div v-show="!chat.isDnd && chat.unreadCount > 0" class="unread-text">{{ chat.unreadCount }}</div>
 		</div>
 		<div class="chat-right">
@@ -16,7 +16,8 @@
 			<div class="chat-content">
 				<div class="chat-at-text">{{ atText }}</div>
 				<div class="chat-send-name" v-show="isShowSendName">{{ chat.sendNickName + ':&nbsp;' }}</div>
-				<div class="chat-content-text" v-html="$emo.transform($str.html2Escape(chat.lastContent), 'emoji-small')"></div>
+				<div class="chat-content-text"
+					v-html="$emo.transform($str.html2Escape(chat.lastContent), 'emoji-small')"></div>
 				<div class="icon iconfont icon-dnd" v-if="chat.isDnd"></div>
 			</div>
 		</div>
@@ -102,6 +103,13 @@ export default {
 				color: '#F56C6C'
 			})
 			return items;
+		},
+		online() {
+			if (this.chat.type == 'PRIVATE') {
+				let friend = this.friendStore.findFriend(this.chat.targetId);
+				return friend && friend.online;
+			}
+			return false;
 		}
 	}
 }