Browse Source

群聊@的功能

master
xsx 2 years ago
parent
commit
096f20975d
  1. 1
      im-platform/src/main/java/com/bx/implatform/service/impl/GroupServiceImpl.java
  2. 1
      im-ui/src/components/chat/ChatItem.vue
  3. 2
      im-ui/src/components/chat/ChatMessageItem.vue
  4. 1
      im-ui/src/store/chatStore.js
  5. 11
      im-ui/src/view/Group.vue
  6. 1
      im-uniapp/App.vue
  7. 63
      im-uniapp/components/chat-item/chat-item.vue
  8. 10
      im-uniapp/components/chat-message-item/chat-message-item.vue
  9. 8
      im-uniapp/components/friend-item/friend-item.vue
  10. 8
      im-uniapp/components/group-item/group-item.vue
  11. 4
      im-uniapp/pages/chat/chat-box.vue
  12. 23
      im-uniapp/store/chatStore.js

1
im-platform/src/main/java/com/bx/implatform/service/impl/GroupServiceImpl.java

@ -76,7 +76,6 @@ public class GroupServiceImpl extends ServiceImpl<GroupMapper, Group> implements
groupMember.setUserId(user.getId()); groupMember.setUserId(user.getId());
groupMember.setAliasName(StringUtils.isEmpty(vo.getAliasName())?session.getNickName():vo.getAliasName()); groupMember.setAliasName(StringUtils.isEmpty(vo.getAliasName())?session.getNickName():vo.getAliasName());
groupMember.setRemark(StringUtils.isEmpty(vo.getRemark())?group.getName():vo.getRemark()); groupMember.setRemark(StringUtils.isEmpty(vo.getRemark())?group.getName():vo.getRemark());
groupMember.setHeadImage(user.getHeadImageThumb());
groupMemberService.save(groupMember); groupMemberService.save(groupMember);
vo.setId(group.getId()); vo.setId(group.getId());

1
im-ui/src/components/chat/ChatItem.vue

@ -80,7 +80,6 @@
return this.$date.toTimeText(this.chat.lastSendTime, true) return this.$date.toTimeText(this.chat.lastSendTime, true)
}, },
atText() { atText() {
console.log(this.chat.atMe)
if (this.chat.atMe) { if (this.chat.atMe) {
return "[有人@我]" return "[有人@我]"
} else if (this.chat.atAll) { } else if (this.chat.atAll) {

2
im-ui/src/components/chat/ChatMessageItem.vue

@ -251,7 +251,7 @@
width: 0; width: 0;
height: 0; height: 0;
border-style: solid dashed dashed; border-style: solid dashed dashed;
border-color: rgb(235, 235, 245) transparent transparent; border-color: white transparent transparent;
overflow: hidden; overflow: hidden;
border-width: 10px; border-width: 10px;
} }

1
im-ui/src/store/chatStore.js

@ -123,7 +123,6 @@ export default {
} }
}, },
insertMessage(state, msgInfo) { insertMessage(state, msgInfo) {
// 获取对方id或群id // 获取对方id或群id
let type = msgInfo.groupId ? 'GROUP' : 'PRIVATE'; let type = msgInfo.groupId ? 'GROUP' : 'PRIVATE';
let targetId = msgInfo.groupId ? msgInfo.groupId : msgInfo.selfSend ? msgInfo.recvId : msgInfo.sendId; let targetId = msgInfo.groupId ? msgInfo.groupId : msgInfo.selfSend ? msgInfo.recvId : msgInfo.sendId;

11
im-ui/src/view/Group.vue

@ -36,7 +36,7 @@
:url="activeGroup.headImage" :url="activeGroup.headImage"
:name="activeGroup.remark"> :name="activeGroup.remark">
</head-image> </head-image>
<el-button class="send-btn" icon="el-icon-chat-dot-round" type="primary" @click="onSendMessage()">发消息</el-button> <el-button class="send-btn" icon="el-icon-chat-dot-round" type="primary" @click="onSendMessage()">消息</el-button>
</div> </div>
<el-form class="group-form" label-width="130px" :model="activeGroup" :rules="rules" <el-form class="group-form" label-width="130px" :model="activeGroup" :rules="rules"
ref="groupForm"> ref="groupForm">
@ -65,7 +65,7 @@
</el-form> </el-form>
</div> </div>
<el-divider content-position="center"></el-divider> <el-divider content-position="center"></el-divider>
<el-scrollbar style="height:400px;"> <el-scrollbar style="height:200px;">
<div class="group-member-list"> <div class="group-member-list">
<div v-for="(member) in groupMembers" :key="member.id"> <div v-for="(member) in groupMembers" :key="member.id">
<group-member v-show="!member.quit" class="group-member" :member="member" <group-member v-show="!member.quit" class="group-member" :member="member"
@ -134,8 +134,6 @@
name: o.value, name: o.value,
remark: o.value, remark: o.value,
aliasName: userInfo.name, aliasName: userInfo.name,
headImage: userInfo.headImage,
headImageThumb: userInfo.headImageThumb,
ownerId: userInfo.id ownerId: userInfo.id
} }
this.$http({ this.$http({
@ -328,8 +326,7 @@
} }
.group-container { .group-container {
padding: 50px; padding: 20px;
.group-info { .group-info {
display: flex; display: flex;
padding: 5px 20px; padding: 5px 20px;
@ -337,7 +334,7 @@
.group-form { .group-form {
flex: 1; flex: 1;
padding-left: 40px; padding-left: 40px;
max-width: 800px; max-width: 700px;
} }
.avatar-uploader { .avatar-uploader {

1
im-uniapp/App.vue

@ -249,7 +249,6 @@
} }
}, },
onLaunch() { onLaunch() {
// //
if (uni.getStorageSync("loginInfo")) { if (uni.getStorageSync("loginInfo")) {
// //

63
im-uniapp/components/chat-item/chat-item.vue

@ -1,16 +1,18 @@
<template> <template>
<view class="chat-item" @click="showChatBox()"> <view class="chat-item" @click="showChatBox()">
<view class="left"> <view class="left">
<head-image :url="chat.headImage" :name="chat.showName" :size="100"></head-image> <head-image :url="chat.headImage" :name="chat.showName" :size="90"></head-image>
<view v-if="chat.unreadCount>0" class="unread-text">{{chat.unreadCount}}</view> <view v-if="chat.unreadCount>0" class="unread-text">{{chat.unreadCount}}</view>
</view> </view>
<view class="chat-right"> <view class="chat-right">
<view class="chat-name"> <view class="chat-name">
{{ chat.showName}} <view class="chat-name-text">{{chat.showName}}</view>
<view class="chat-time">{{$date.toTimeText(chat.lastSendTime)}}</view>
</view> </view>
<view class="chat-content"> <view class="chat-content">
<view class="chat-at-text">{{atText}}</view>
<view class="chat-send-name" v-show="chat.sendNickName">{{chat.sendNickName+':&nbsp;'}}</view>
<rich-text class="chat-content-text" :nodes="$emo.transform(chat.lastContent)"></rich-text> <rich-text class="chat-content-text" :nodes="$emo.transform(chat.lastContent)"></rich-text>
<view class="chat-time">{{$date.toTimeText(chat.lastSendTime)}}</view>
</view> </view>
</view> </view>
</view> </view>
@ -36,19 +38,29 @@
url: "/pages/chat/chat-box?chatIdx=" + this.index url: "/pages/chat/chat-box?chatIdx=" + this.index
}) })
} }
},
computed: {
atText() {
if (this.chat.atMe) {
return "[有人@我]"
} else if (this.chat.atAll) {
return "[@全体成员]"
}
return "";
}
} }
} }
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
.chat-item { .chat-item {
height: 120rpx; height: 100rpx;
display: flex; display: flex;
margin-bottom: 2rpx; margin-bottom: 2rpx;
position: relative; position: relative;
padding-left: 30rpx; padding: 10rpx;
padding-left: 20rpx;
align-items: center; align-items: center;
padding-right: 10rpx;
background-color: white; background-color: white;
white-space: nowrap; white-space: nowrap;
@ -87,23 +99,16 @@
overflow: hidden; overflow: hidden;
.chat-name { .chat-name {
font-size: 30rpx;
font-weight: 600;
line-height: 60rpx;
white-space: nowrap;
overflow: hidden;
}
.chat-content {
display: flex; display: flex;
line-height: 50rpx;
height: 50rpx;
.chat-content-text { .chat-name-text {
flex: 1; flex: 1;
font-size: 28rpx; font-size: 30rpx;
font-weight: 600;
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;
line-height: 50rpx;
text-overflow: ellipsis;
} }
.chat-time { .chat-time {
@ -114,6 +119,28 @@
overflow: hidden; overflow: hidden;
} }
} }
.chat-content {
display: flex;
line-height: 44rpx;
.chat-at-text {
color: #c70b0b;
font-size: 24rpx;
}
.chat-send-name {
font-size: 26rpx;
}
.chat-content-text {
flex: 1;
font-size: 28rpx;
white-space: nowrap;
overflow: hidden;
line-height: 50rpx;
text-overflow: ellipsis;
}
}
} }
} }
</style> </style>

10
im-uniapp/components/chat-message-item/chat-message-item.vue

@ -231,7 +231,7 @@
line-height: 60rpx; line-height: 60rpx;
margin-top: 10rpx; margin-top: 10rpx;
padding: 10rpx 20rpx; padding: 10rpx 20rpx;
background-color: #ebebf5; background-color: white;
border-radius: 10rpx; border-radius: 10rpx;
color: #333; color: #333;
font-size: 30rpx; font-size: 30rpx;
@ -239,17 +239,17 @@
display: block; display: block;
word-break: break-all; word-break: break-all;
white-space: pre-line; white-space: pre-line;
box-shadow: 2px 2px 2px #c0c0f0; box-shadow: 1px 1px 1px #c0c0f0;
&:after { &:after {
content: ""; content: "";
position: absolute; position: absolute;
left: -20rpx; left: -20rpx;
top: 26rpx; top: 26rpx;
width: 0; width: 6rpx;
height: 0; height: 6rpx;
border-style: solid dashed dashed; border-style: solid dashed dashed;
border-color: #ebebf5 transparent transparent; border-color: white transparent transparent;
overflow: hidden; overflow: hidden;
border-width: 18rpx; border-width: 18rpx;
} }

8
im-uniapp/components/friend-item/friend-item.vue

@ -1,7 +1,7 @@
<template> <template>
<view class="friend-item" @click="showFriendInfo()"> <view class="friend-item" @click="showFriendInfo()">
<head-image :name="friend.nickName" :online="friend.online" :url="friend.headImage" <head-image :name="friend.nickName" :online="friend.online" :url="friend.headImage"
:size="100"></head-image> :size="90"></head-image>
<view class="friend-info"> <view class="friend-info">
<view class="friend-name">{{ friend.nickName}}</view> <view class="friend-name">{{ friend.nickName}}</view>
<view class="friend-online"> <view class="friend-online">
@ -37,13 +37,13 @@
<style scope lang="scss"> <style scope lang="scss">
.friend-item { .friend-item {
height: 120rpx; height: 100rpx;
display: flex; display: flex;
margin-bottom: 1rpx; margin-bottom: 1rpx;
position: relative; position: relative;
padding-left: 30rpx; padding: 10rpx;
padding-left: 20rpx;
align-items: center; align-items: center;
padding-right: 10rpx;
background-color: white; background-color: white;
white-space: nowrap; white-space: nowrap;

8
im-uniapp/components/group-item/group-item.vue

@ -1,7 +1,7 @@
<template> <template>
<view class="group-item" @click="showGroupInfo()"> <view class="group-item" @click="showGroupInfo()">
<head-image :name="group.remark" <head-image :name="group.remark"
:url="group.headImage" :size="100"></head-image> :url="group.headImage" :size="90"></head-image>
<view class="group-name"> <view class="group-name">
<view>{{ group.remark}}</view> <view>{{ group.remark}}</view>
</view> </view>
@ -31,13 +31,13 @@
<style scope lang="scss"> <style scope lang="scss">
.group-item { .group-item {
height: 120rpx; height: 100rpx;
display: flex; display: flex;
margin-bottom: 1rpx; margin-bottom: 1rpx;
position: relative; position: relative;
padding-left: 30rpx; padding: 10rpx;
padding-left: 20rpx;
align-items: center; align-items: center;
padding-right: 10rpx;
background-color: white; background-color: white;
white-space: nowrap; white-space: nowrap;
&:hover { &:hover {

4
im-uniapp/pages/chat/chat-box.vue

@ -527,8 +527,6 @@
right: 30rpx; right: 30rpx;
} }
} }
} }
@ -538,7 +536,7 @@
border: #dddddd solid 1px; border: #dddddd solid 1px;
overflow: hidden; overflow: hidden;
position: relative; position: relative;
background-color: white; background-color: #f8f8f8;
.scroll-box { .scroll-box {
height: 100%; height: 100%;

23
im-uniapp/store/chatStore.js

@ -70,6 +70,8 @@ export default {
if (state.chats[idx].type == chatInfo.type && if (state.chats[idx].type == chatInfo.type &&
state.chats[idx].targetId == chatInfo.targetId) { state.chats[idx].targetId == chatInfo.targetId) {
state.chats[idx].unreadCount = 0; state.chats[idx].unreadCount = 0;
state.chats[idx].atMe = false;
state.chats[idx].atAll = false;
} }
} }
this.commit("saveToStorage"); this.commit("saveToStorage");
@ -127,7 +129,6 @@ export default {
break; break;
} }
} }
// 会话列表内容 // 会话列表内容
if(!state.loadingPrivateMsg && !state.loadingPrivateMsg){ if(!state.loadingPrivateMsg && !state.loadingPrivateMsg){
if (msgInfo.type == MESSAGE_TYPE.IMAGE) { if (msgInfo.type == MESSAGE_TYPE.IMAGE) {
@ -140,11 +141,23 @@ export default {
chat.lastContent = msgInfo.content; chat.lastContent = msgInfo.content;
} }
chat.lastSendTime = msgInfo.sendTime; chat.lastSendTime = msgInfo.sendTime;
chat.sendNickName = msgInfo.sendNickName;
} }
// 未读加1 // 未读加1
if (!msgInfo.selfSend && msgInfo.status != MESSAGE_STATUS.READED) { if (!msgInfo.selfSend && msgInfo.status != MESSAGE_STATUS.READED) {
chat.unreadCount++; chat.unreadCount++;
} }
// 是否有人@我
if(!msgInfo.selfSend && chat.type=="GROUP" && msgInfo.atUserIds){
let userId = userStore.state.userInfo.id;
if(msgInfo.atUserIds.indexOf(userId)>=0){
chat.atMe = true;
}
if(msgInfo.atUserIds.indexOf(-1)>=0){
chat.atAll = true;
}
}
// 记录消息的最大id // 记录消息的最大id
if (msgInfo.id && type == "PRIVATE" && msgInfo.id > state.privateMsgMaxId) { if (msgInfo.id && type == "PRIVATE" && msgInfo.id > state.privateMsgMaxId) {
state.privateMsgMaxId = msgInfo.id; state.privateMsgMaxId = msgInfo.id;
@ -267,10 +280,10 @@ export default {
groupMsgMaxId: state.groupMsgMaxId, groupMsgMaxId: state.groupMsgMaxId,
chats: state.chats chats: state.chats
} }
// uni.setStorage({ uni.setStorage({
// key: key, key: key,
// data: chatsData data: chatsData
// }) })
}, },
clear(state) { clear(state) {
state.chats = []; state.chats = [];

Loading…
Cancel
Save