Jelajahi Sumber

清理无效的臃肿代码

xsx 1 tahun lalu
induk
melakukan
e749ae18f1

+ 1 - 4
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-into-view="'chat-item-'+scrollMsgIdx">
 				<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"
 						@delete="onDeleteMessage" @longPressHead="onLongPressHead(msgInfo)" @download="onDownloadFile"
 						:id="'chat-item-'+idx" :msgInfo="msgInfo" :groupMembers="groupMembers">
@@ -749,9 +749,6 @@
 			// 复位回执消息
 			this.isReceipt = false;
 		},
-		onUnload() {
-			this.chatStore.activeChat(-1);
-		},
 		onShow(){
 			if(this.needScrollToBottom){
 				// 页面滚到底部

+ 5 - 21
im-uniapp/pages/chat/chat.vue

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

+ 1 - 1
im-uniapp/pages/common/user-info.vue

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

+ 1 - 1
im-uniapp/pages/friend/friend-add.vue

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

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

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

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

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

+ 15 - 13
im-uniapp/store/chatStore.js

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

+ 7 - 12
im-uniapp/store/friendStore.js

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