Browse Source

完成点击头像 添加好友和发送信息弹窗屏蔽

客服端不要游客头像
master
[yxf] 4 weeks ago
parent
commit
358d7c81cd
  1. 87
      im-uniapp/App.vue
  2. 31
      im-uniapp/store/chatStore.js
  3. 4
      im-web/src/api/date.js
  4. 10
      im-web/src/components/chat/ChatBox.vue
  5. 5
      im-web/src/components/chat/ChatMessageItem.vue

87
im-uniapp/App.vue

@ -79,6 +79,67 @@ export default {
this.configStore.setAppInit(false);
}
})
wsApi.onMessage((cmd, msgInfo) => {
if (cmd == 2) {
//
this.exit();
} else if (cmd == 3) {
//
this.handlePrivateMessage(msgInfo);
} else if (cmd == 4) {
//
this.handleGroupMessage(msgInfo);
} else if (cmd == 5) {
//
this.handleSystemMessage(msgInfo);
} else if (cmd == 6) {
//
this.handleCustomerChanged(msgInfo);
}
});
},
//
handleCustomerChanged(msgInfo) {
console.log('客服已变更,刷新聊天记录:', msgInfo);
//
this.friendStore.loadFriend().then(() => {
//
this.chatStore.refreshChats();
//
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
if (currentPage.route === 'pages/chat/chat-box') {
//
const targetId = currentPage.options.targetId;
this.reloadChatMessages(targetId);
}
});
},
//
reloadChatMessages(targetId) {
//
const chat = this.chatStore.chats.find(c =>
c.targetId == targetId && c.type === 'PRIVATE'
);
if (chat) {
//
chat.messages = [];
//
this.$http({
url: `/message/private/history/${targetId}?full=true`,
method: 'GET'
}).then(messages => {
messages.forEach(msg => {
this.chatStore.insertMessage(msg, chat);
});
});
}
},
loadStore() {
return this.userStore.loadUser().then(() => {
@ -144,6 +205,32 @@ export default {
msg.selfSend = msg.sendId == this.userStore.userInfo.id;
// id
let friendId = msg.selfSend ? msg.recvId : msg.sendId;
//
let existingFriend = this.friendStore.findFriend(friendId);
if (!existingFriend && !msg.selfSend) {
console.log("收到未知用户消息,刷新应用:", friendId);
//
this.loadStore().then(() => {
//
// #ifdef H5
window.location.reload();
// #endif
// #ifdef APP-PLUS
plus.runtime.restart();
// #endif
// #ifdef MP-WEIXIN
//
uni.reLaunch({
url: '/pages/chat/chat'
});
// #endif
});
return;
}
//
let chatInfo = {
type: 'PRIVATE',

31
im-uniapp/store/chatStore.js

@ -30,6 +30,37 @@ export default defineStore('chatStore', {
this.privateMsgMaxId = chatsData.privateMsgMaxId || 0;
this.groupMsgMaxId = chatsData.groupMsgMaxId || 0;
},
// 客服转接:合并旧客服会话到新客服(你要的功能)
mergeOldCustomerToNew(oldKfId, newKfId) {
const oldChat = this.findChatByFriend(oldKfId);
const newChat = this.findChatByFriend(newKfId);
if (!oldChat || !newChat) return;
newChat.messages = [...oldChat.messages, ...newChat.messages];
newChat.unreadCount += oldChat.unreadCount;
newChat.lastContent = oldChat.lastContent || newChat.lastContent;
newChat.lastSendTime = Math.max(oldChat.lastSendTime || 0, newChat.lastSendTime || 0);
newChat.stored = false;
oldChat.stored = false;
this.removePrivateChat(oldKfId);
this.saveToStorage(true);
},
// 强制清理某个用户的本地缓存(清理旧客服)
clearCustomerCache(userId) {
const userStore = useUserStore();
const currentUserId = userStore.userInfo.id;
const key = `chats-app-${currentUserId}-PRIVATE-${userId}`;
uni.removeStorageSync(key);
uni.removeStorageSync(key + '-hot');
},
openChat(chatInfo) {
let chats = this.curChats;
let chat = null;

4
im-web/src/api/date.js

@ -2,9 +2,9 @@ let toTimeText = (timeStamp, simple) => {
var dateTime = new Date(timeStamp)
var currentTime = Date.parse(new Date()); //当前时间
var timeDiff = currentTime - dateTime; //与当前时间误差
var timeText = 'Just now';
var timeText = '';
if (timeDiff <= 60000) { //一分钟内
timeText = '刚刚';
timeText = 'Just now';
} else if (timeDiff > 60000 && timeDiff < 3600000) {
//1小时内
timeText = Math.floor(timeDiff / 60000) + ' minutes ago';

10
im-web/src/components/chat/ChatBox.vue

@ -59,11 +59,11 @@
</el-aside>
<el-aside class="side-box user-info-side" width="320px" v-if="showUserSide">
<div class="user-info-container">
<div class="user-info-header">
<img :src="userInfo.headImage || userInfo.headImageThumb" class="user-avatar-large" />
<h3 class="user-nickname">{{ userInfo.nickName }}</h3>
<p class="user-username">@{{ userInfo.userName }}</p>
</div>
<!-- <div class="user-info-header"> -->
<!-- <img :src="userInfo.headImage || userInfo.headImageThumb" class="user-avatar-large" /> -->
<!-- <h3 class="user-nickname">{{ userInfo.nickName }}</h3>
<p class="user-username">@{{ userInfo.userName }}</p> -->
<!-- </div> -->
<div class="user-info-content">
<div class="info-item">
<div class="info-label">用户IP</div>

5
im-web/src/components/chat/ChatMessageItem.vue

@ -8,7 +8,8 @@
</div>
<div class="message-normal" v-else-if="isNormal" :class="{ 'message-mine': mine }">
<div class="head-image">
<head-image :name="showName" :size="38" :url="headImage" :id="msgInfo.sendId"></head-image>
<!-- <head-image :name="showName" :size="38" :url="headImage" :id="msgInfo.sendId"></head-image> -->
<head-image :name="showName" :size="38" :url="headImage"></head-image>
</div>
<div class="content">
<div v-show="mode == 1 && msgInfo.groupId && !msgInfo.selfSend" class="message-top">
@ -23,7 +24,7 @@
<span class="message-text" v-if="isTextMessage" v-html="htmlText"></span>
<div class="message-image" v-else-if="msgInfo.type == $enums.MESSAGE_TYPE.IMAGE"
@click="showFullImageBox()">
<img :style="imageStyle" :src="contentData.thumbUrl" loading="lazy" />
<img :style="i/mageStyle" :src="contentData.thumbUrl" loading="lazy" />
</div>
<div class="message-file" v-else-if="msgInfo.type == $enums.MESSAGE_TYPE.FILE">
<div class="chat-file-box" v-loading="sending">

Loading…
Cancel
Save