Browse Source

清理无效的臃肿代码

master
xsx 2 years ago
parent
commit
e749ae18f1
  1. 5
      im-uniapp/pages/chat/chat-box.vue
  2. 26
      im-uniapp/pages/chat/chat.vue
  3. 2
      im-uniapp/pages/common/user-info.vue
  4. 2
      im-uniapp/pages/friend/friend-add.vue
  5. 3
      im-uniapp/pages/friend/friend.vue
  6. 3
      im-uniapp/pages/group/group-invite.vue
  7. 28
      im-uniapp/store/chatStore.js
  8. 19
      im-uniapp/store/friendStore.js

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

@ -9,7 +9,7 @@
<scroll-view class="scroll-box" scroll-y="true" upper-threshold="200" @scrolltoupper="onScrollToTop" <scroll-view class="scroll-box" scroll-y="true" upper-threshold="200" @scrolltoupper="onScrollToTop"
:scroll-into-view="'chat-item-'+scrollMsgIdx"> :scroll-into-view="'chat-item-'+scrollMsgIdx">
<view v-if="chat" v-for="(msgInfo,idx) in chat.messages" :key="idx"> <view v-if="chat" v-for="(msgInfo,idx) in chat.messages" :key="idx">
<chat-message-item v-if="idx>=showMinIdx&&!msgInfo.delete" :headImage="headImage(msgInfo)" <chat-message-item v-if="idx>=showMinIdx" :headImage="headImage(msgInfo)"
@call="onRtCall(msgInfo)" :showName="showName(msgInfo)" @recall="onRecallMessage" @call="onRtCall(msgInfo)" :showName="showName(msgInfo)" @recall="onRecallMessage"
@delete="onDeleteMessage" @longPressHead="onLongPressHead(msgInfo)" @download="onDownloadFile" @delete="onDeleteMessage" @longPressHead="onLongPressHead(msgInfo)" @download="onDownloadFile"
:id="'chat-item-'+idx" :msgInfo="msgInfo" :groupMembers="groupMembers"> :id="'chat-item-'+idx" :msgInfo="msgInfo" :groupMembers="groupMembers">
@ -749,9 +749,6 @@
// //
this.isReceipt = false; this.isReceipt = false;
}, },
onUnload() {
this.chatStore.activeChat(-1);
},
onShow(){ onShow(){
if(this.needScrollToBottom){ if(this.needScrollToBottom){
// //

26
im-uniapp/pages/chat/chat.vue

@ -14,11 +14,11 @@
温馨提示您现在还没有任何聊天消息快跟您的好友发起聊天吧~ 温馨提示您现在还没有任何聊天消息快跟您的好友发起聊天吧~
</view> </view>
<scroll-view class="scroll-bar" v-else scroll-with-animation="true" scroll-y="true"> <scroll-view class="scroll-bar" v-else scroll-with-animation="true" scroll-y="true">
<view v-for="(chatPos,i) in chatsPos" :key="i"> <view v-for="(chat,index) in chatStore.chats" :key="index">
<pop-menu v-if="isShowChat(chatStore.chats[chatPos.idx])" :items="menu.items" <pop-menu v-if="isShowChat(chat)" :items="menu.items"
@select="onSelectMenu($event,chatPos.idx)"> @select="onSelectMenu($event,index)">
<chat-item :chat="chatStore.chats[chatPos.idx]" <chat-item :chat="chat" :index="index"
:active="menu.chatIdx==chatPos.idx" :index="chatPos.idx"></chat-item> :active="menu.chatIdx==index"></chat-item>
</pop-menu> </pop-menu>
</view> </view>
</scroll-view> </scroll-view>
@ -90,26 +90,10 @@
index: 0, index: 0,
complete: () => {} complete: () => {}
}) })
} }
} }
}, },
computed: { computed: {
chatsPos() {
//
let chatsPos = [];
let chats = this.chatStore.chats;
chats.forEach((chat, idx) => {
chatsPos.push({
idx: idx,
sendTime: chat.lastSendTime
})
})
chatsPos.sort((chatPos1, chatPos2) => {
return chatPos2.sendTime - chatPos1.sendTime;
});
return chatsPos;
},
unreadCount() { unreadCount() {
let count = 0; let count = 0;
this.chatStore.chats.forEach(chat => { this.chatStore.chats.forEach(chat => {

2
im-uniapp/pages/common/user-info.vue

@ -134,7 +134,7 @@
}, },
computed: { computed: {
isFriend() { isFriend() {
return this.friendInfo&&!this.friendInfo.delete; return !!this.friendInfo;
}, },
friendInfo(){ friendInfo(){
let friends = this.friendStore.friends; let friends = this.friendStore.friends;

2
im-uniapp/pages/friend/friend-add.vue

@ -72,7 +72,7 @@
isFriend(userId) { isFriend(userId) {
let friends = this.friendStore.friends; let friends = this.friendStore.friends;
let friend = friends.find((f) => f.id == userId); let friend = friends.find((f) => f.id == userId);
return friend&&!friend.delete; return !!friend;
} }
} }
} }

3
im-uniapp/pages/friend/friend.vue

@ -65,9 +65,6 @@
// //
let groupMap = new Map(); let groupMap = new Map();
this.friends.forEach((f) => { this.friends.forEach((f) => {
if (f.delete) {
return;
}
if(this.searchText && !f.nickName.includes(this.searchText)){ if(this.searchText && !f.nickName.includes(this.searchText)){
return; return;
} }

3
im-uniapp/pages/group/group-invite.vue

@ -83,9 +83,6 @@
this.friendItems = []; this.friendItems = [];
let friends = this.friendStore.friends; let friends = this.friendStore.friends;
friends.forEach((f => { friends.forEach((f => {
if(f.delete){
return
}
let item = { let item = {
id: f.id, id: f.id,
headImage: f.headImage, headImage: f.headImage,

28
im-uniapp/store/chatStore.js

@ -18,10 +18,6 @@ export default defineStore('chatStore', {
cacheChats = []; cacheChats = [];
this.chats = []; this.chats = [];
for (let chat of chatsData.chats) { for (let chat of chatsData.chats) {
// 已删除的会话直接丢弃
if (chat.delete) {
continue;
}
// 暂存至缓冲区 // 暂存至缓冲区
cacheChats.push(JSON.parse(JSON.stringify(chat))); cacheChats.push(JSON.parse(JSON.stringify(chat)));
// 加载期间显示只前15个会话做做样子,一切都为了加快初始化时间 // 加载期间显示只前15个会话做做样子,一切都为了加快初始化时间
@ -69,8 +65,8 @@ export default defineStore('chatStore', {
atAll: false, atAll: false,
delete: false delete: false
}; };
chats.push(chat); chats.unshift(chat);
this.moveTop(chats.length - 1) this.saveToStorage();
} }
}, },
activeChat(idx) { activeChat(idx) {
@ -111,7 +107,7 @@ export default defineStore('chatStore', {
}, },
removeChat(idx) { removeChat(idx) {
let chats = this.curChats; let chats = this.curChats;
chats[idx].delete = true; chats.splice(idx, 1);
this.saveToStorage(); this.saveToStorage();
}, },
removePrivateChat(userId) { removePrivateChat(userId) {
@ -134,11 +130,17 @@ export default defineStore('chatStore', {
}, },
moveTop(idx) { moveTop(idx) {
console.log("moveTop") console.log("moveTop")
if (this.isLoading()) {
return;
}
let chats = this.curChats; let chats = this.curChats;
let chat = chats[idx]; if (idx > 0) {
// 最新的时间会显示在顶部 let chat = chats[idx];
chat.lastSendTime = new Date().getTime(); chats.splice(idx, 1);
this.saveToStorage(); chats.unshift(chat);
this.saveToStorage();
}
}, },
insertMessage(msgInfo) { insertMessage(msgInfo) {
// 获取对方id或群id // 获取对方id或群id
@ -239,13 +241,13 @@ export default defineStore('chatStore', {
for (let idx in chat.messages) { for (let idx in chat.messages) {
// 已经发送成功的,根据id删除 // 已经发送成功的,根据id删除
if (chat.messages[idx].id && chat.messages[idx].id == msgInfo.id) { if (chat.messages[idx].id && chat.messages[idx].id == msgInfo.id) {
chat.messages[idx].delete = true; chat.messages.splice(idx, 1);
break; break;
} }
// 正在发送中的消息可能没有id,根据发送时间删除 // 正在发送中的消息可能没有id,根据发送时间删除
if (msgInfo.selfSend && chat.messages[idx].selfSend && if (msgInfo.selfSend && chat.messages[idx].selfSend &&
chat.messages[idx].sendTime == msgInfo.sendTime) { chat.messages[idx].sendTime == msgInfo.sendTime) {
chat.messages[idx].delete = true; chat.messages.splice(idx, 1);
break; break;
} }
} }

19
im-uniapp/store/friendStore.js

@ -20,7 +20,7 @@ export default defineStore('friendStore', {
}, },
updateFriend(friend) { updateFriend(friend) {
this.friends.forEach((f, index) => { this.friends.forEach((f, index) => {
if (!f.delete && f.id == friend.id) { if (f.id == friend.id) {
// 拷贝属性 // 拷贝属性
let online = this.friends[index].online; let online = this.friends[index].online;
Object.assign(this.friends[index], friend); Object.assign(this.friends[index], friend);
@ -29,19 +29,14 @@ export default defineStore('friendStore', {
}) })
}, },
removeFriend(id) { removeFriend(id) {
let friend = this.findFriend(id); this.friends.forEach((f, idx) => {
if (friend) { if (f.id == id) {
friend.delete = true; this.friends.splice(idx, 1)
} }
})
}, },
addFriend(friend) { addFriend(friend) {
let f = this.findFriend(friend.id); this.friends.push(friend);
if (f) {
Object.assign(f, friend);
f.delete = false;
} else {
this.friends.push(friend);
}
}, },
setOnlineStatus(onlineTerminals) { setOnlineStatus(onlineTerminals) {
this.friends.forEach((f) => { this.friends.forEach((f) => {

Loading…
Cancel
Save