Procházet zdrojové kódy

直播添加删除消息事件

yuhongqi před 1 měsícem
rodič
revize
14c16fc7f7
1 změnil soubory, kde provedl 31 přidání a 28 odebrání
  1. 31 28
      pages_course/living.vue

+ 31 - 28
pages_course/living.vue

@@ -3694,6 +3694,8 @@
 
 				// 给消息添加唯一ID
 				message.uniqueId = ++this.messageIdCounter;
+				let msgdata = JSON.parse(message.data);
+				message.msgId = msgdata.msgId;
 				this.talklist.push(message);
 
 				// 当消息超过限制时,批量删除旧消息
@@ -3904,7 +3906,10 @@
 								status: true
 							};
 						} else if (socketMessage.cmd == 'deleteMsg') {
-
+							const index = this.talklist.findIndex(item => item.msgId == socketMessage.msg);
+							if (index !== -1) {
+							  this.talklist.splice(index, 1);
+							}
 						}else if (socketMessage.cmd == 'LotteryDetail') {
 							try {
 								this.prizeInfo = Array.isArray(JSON.parse(socketMessage.data || '[]')) ? JSON.parse(
@@ -3984,34 +3989,32 @@
 				};
 				// 发送socket消息
 				try {
-					if (this.myselfFlag) {
-						this.addToTalkList(data);
-					} else {
-						this.socket.send({
-							data: JSON.stringify(data),
-							success: () => {
-								this.value = '';
-								// 发送成功后强制滚动到底部,无论当前滚动位置如何
-								this.forceScrollToBottomOnSend();
-							},
-							fail: (err) => {
-								console.error('消息发送失败:', err);
-								if (retries > 0) {
-									uni.showToast({
-										title: `发送失败,正在重试(${retries}次)`,
-										icon: 'none'
-									});
-									setTimeout(() => this.sendMsg(retries - 1), 500);
-								} else {
-									uni.showToast({
-										title: '发送失败,请稍后再试',
-										icon: 'none'
-									});
-									this.value = text; // 恢复输入框内容
-								}
+
+					this.socket.send({
+						data: JSON.stringify(data),
+						success: () => {
+							this.value = '';
+							// 发送成功后强制滚动到底部,无论当前滚动位置如何
+							this.forceScrollToBottomOnSend();
+						},
+						fail: (err) => {
+							console.error('消息发送失败:', err);
+							if (retries > 0) {
+								uni.showToast({
+									title: `发送失败,正在重试(${retries}次)`,
+									icon: 'none'
+								});
+								setTimeout(() => this.sendMsg(retries - 1), 500);
+							} else {
+								uni.showToast({
+									title: '发送失败,请稍后再试',
+									icon: 'none'
+								});
+								this.value = text; // 恢复输入框内容
 							}
-						});
-					}
+						}
+					});
+
 
 				} catch (err) {
 					console.error('发送消息异常:', err);