liujiaxin 1 개월 전
부모
커밋
a4f7399be4

+ 321 - 418
pages/home/living.vue

@@ -248,44 +248,8 @@
 						</view>
 					</u-popup>
 				</view>
-<<<<<<< HEAD
 			</swiper-item>
 		</swiper>
-		<!-- 预加载指示器 -->
-		<view v-if="preloading" class="preload-indicator">
-			<u-loading mode="circle" color="#ffffff" size="28"></u-loading>
-=======
-
-				<view class="justify-between p24">
-					<view class="u-flex-y-center"
-						style="background:rgba(157, 157, 157, 0.8);padding:18rpx 14rpx 18rpx 32rpx;width: 526rpx;box-sizing:border-box;border-radius:36rpx;">
-						<u-input :placeholder="placeholderText" border="none" customStyle='font-size:24rpx;'
-							v-model="value" shape='circle' color='#fff' placeholderStyle='color:#e7e7e7' class="ml20"
-							@keydown.enter="sendMsg">
-						</u-input>
-						<!-- <image @click="sendMsg" class="w44 h44" src="@/static/images/live/like.png"></image> -->
-					</view>
-					<!-- :disabled='talkdisabled' ></u-input> -->
-					<!-- <view @click="sendMsg" class="colorf center ml10 fs24">发送</view> -->
-					<view class="justify-between mr30  align-center">
-						<!-- <view class="icon-bg ml20" @click="answerbtn=!answerbtn">
-							<image src="/static/images/redbag.png" class="w40 h40"></image>
-						</view> -->
-						<view class="icon-bg ml20" @click="shopping=!shopping">
-							<image src="/static/images/shopping.png" class="w48 h48"></image>
-						</view>
-						<view class="icon-bg ml20" @click="showziliao=!showziliao">
-							<image src="/static/images/more-icon.png" class="w48 h48"></image>
-						</view>
-						<!-- <view class="icon-bg ml20" :class="{ 'zoom-button-active': isZoom }"
-							@touchstart="handleTouchStart" @touchend="handleTouchEnd">
-							<image src="/static/images/dianzan.png" class="w40 h40"></image>
-						</view> -->
-					</view>
-				</view>
-			</view>
->>>>>>> 57028795d3bcee2e15cce5538d4362a47313f66a
-		</view>
 	</view>
 </template>
 
@@ -327,15 +291,12 @@
 	} from '@/api/home'
 	// var wsUrl = "ws://192.168.10.166:7114/app/webSocket";
 
-<<<<<<< HEAD
 	// var wsUrl = "ws://192.168.10.166:7114/app/webSocket"; //余红奇
 	// var wsUrl = "ws://192.168.10.125:7114/app/webSocket"; //涂小龙
 	var wsUrl = "wss://live.test.ylrztop.com/ws/live-api/app/webSocket"; //余红奇
-=======
 	var wsUrl = "ws://192.168.10.166:7114/app/webSocket"; //余红奇
 	// var wsUrl = "ws://192.168.10.125:7114/app/webSocket"; //涂小龙
 	// var wsUrl = "ws://live.test.ylrztop.com/prod-api/app/webSocket"; //余红奇
->>>>>>> 57028795d3bcee2e15cce5538d4362a47313f66a
 	// var wsUrl = "ws://nd383294.natappfree.cc/app/webSocket"; //余红奇
 	// var wsUrl = "ws://v56c9b8e.natappfree.cc/app/webSocket"; //余红奇
 	// var wsUrl = "ws://192.168.10.170:7114/app/webSocket"; //陈果
@@ -428,34 +389,31 @@
 
 
 		onLoad(options) {
-			this.userinfo = JSON.parse(uni.getStorageSync("userInfo"))
-<<<<<<< HEAD
-			// 初始化直播间列表
-			this.initLiveList(options);
-=======
+			this.userinfo = JSON.parse(uni.getStorageSync("userInfo")) <<
+				// 初始化直播间列表
+				this.initLiveList(options);
 			if (options.liveId) {
 				this.liveId = options.liveId; // 仅当 liveId 变化时更新
 			}
 			const platform = uni.getSystemInfoSync().platform;
 			if (['mp-weixin', 'mp-alipay', 'mp-baidu', 'mp-toutiao'].includes(platform)) {
-			    // 确保 API 存在再调用
-			    if (uni.showShareMenu) {
-			      uni.showShareMenu({
-			        withShareTicket: true, // 可选参数,根据需求配置
-			        success: () => {
-			          console.log('分享菜单显示成功');
-			        },
-			        fail: (err) => {
-			          console.error('分享菜单显示失败:', err);
-			        }
-			      });
-			    } else {
-			      console.warn('当前平台不支持 uni.showShareMenu');
-			    }
-			  } else {
-			    console.log('当前平台无需显示分享菜单');
-			  }
->>>>>>> 57028795d3bcee2e15cce5538d4362a47313f66a
+				// 确保 API 存在再调用
+				if (uni.showShareMenu) {
+					uni.showShareMenu({
+						withShareTicket: true, // 可选参数,根据需求配置
+						success: () => {
+							console.log('分享菜单显示成功');
+						},
+						fail: (err) => {
+							console.error('分享菜单显示失败:', err);
+						}
+					});
+				} else {
+					console.warn('当前平台不支持 uni.showShareMenu');
+				}
+			} else {
+				console.log('当前平台无需显示分享菜单');
+			}
 		},
 		onShareAppMessage() {
 			return {
@@ -519,20 +477,20 @@
 			clearInterval(this.intervalId); // 页面隐藏时清理
 		},
 		onUnload() {
-		    // 关闭所有WebSocket连接
-		    this.closeAllWebSockets();
-		    
-		    // 移除所有全局事件监听
-		    this.removeAllEventListeners();
-		    
-		    // 清理定时器
-		    this.clearAllTimers();
-		    
-		    // 销毁HLS播放器
-		    if (this.hlsPlayer) {
-		        this.hlsPlayer.destroy();
-		        this.hlsPlayer = null;
-		    }
+			// 关闭所有WebSocket连接
+			this.closeAllWebSockets();
+
+			// 移除所有全局事件监听
+			this.removeAllEventListeners();
+
+			// 清理定时器
+			this.clearAllTimers();
+
+			// 销毁HLS播放器
+			if (this.hlsPlayer) {
+				this.hlsPlayer.destroy();
+				this.hlsPlayer = null;
+			}
 		},
 		watch: {
 			// 监听orderUser.count的变化
@@ -546,65 +504,66 @@
 				immediate: true
 			}
 		},
-		methods: {closeAllWebSockets() {
-    this.isManualClose = true;
-    
-    // 关闭所有连接
-    Object.keys(this.socketInstances).forEach(liveId => {
-        try {
-            if (this.socketInstances[liveId] && this.socketInstances[liveId].instance) {
-                this.socketInstances[liveId].instance.close({
-                    code: 1000,
-                    reason: '页面关闭'
-                });
-                console.log(`直播间 ${liveId} WebSocket 已关闭`);
-            }
-        } catch (e) {
-            console.error(`关闭直播间 ${liveId} WebSocket 时出错:`, e);
-        }
-    });
-    
-    this.socketInstances = {};
-    isSocketOpen = false;
-},// 新增:移除所有全局事件监听器
-removeAllEventListeners() {
-    uni.$off('initSocket');
-    uni.$off('sendMsg');
-    uni.$off('closeWebSocket');
-    uni.$off('refreshOrder');
-    // 可以根据实际情况添加其他需要移除的事件
-},// 新增:清理所有定时器
-clearAllTimers() {
-    if (this.intervalId) {
-        clearInterval(this.intervalId);
-        this.intervalId = null;
-    }
-    
-    if (this.pingpangTimes) {
-        clearInterval(this.pingpangTimes);
-        this.pingpangTimes = null;
-    }
-    
-    if (this.reconnectTimer) {
-        clearTimeout(this.reconnectTimer);
-        this.reconnectTimer = null;
-    }
-    
-    if (this.scrollTimer) {
-        clearTimeout(this.scrollTimer);
-        this.scrollTimer = null;
-    }
-    
-    if (this.searchTimer) {
-        clearTimeout(this.searchTimer);
-        this.searchTimer = null;
-    }
-    
-    if (this.purchasePromptTimer) {
-        clearTimeout(this.purchasePromptTimer);
-        this.purchasePromptTimer = null;
-    }
-},
+		methods: {
+			closeAllWebSockets() {
+				this.isManualClose = true;
+
+				// 关闭所有连接
+				Object.keys(this.socketInstances).forEach(liveId => {
+					try {
+						if (this.socketInstances[liveId] && this.socketInstances[liveId].instance) {
+							this.socketInstances[liveId].instance.close({
+								code: 1000,
+								reason: '页面关闭'
+							});
+							console.log(`直播间 ${liveId} WebSocket 已关闭`);
+						}
+					} catch (e) {
+						console.error(`关闭直播间 ${liveId} WebSocket 时出错:`, e);
+					}
+				});
+
+				this.socketInstances = {};
+				isSocketOpen = false;
+			}, // 新增:移除所有全局事件监听器
+			removeAllEventListeners() {
+				uni.$off('initSocket');
+				uni.$off('sendMsg');
+				uni.$off('closeWebSocket');
+				uni.$off('refreshOrder');
+				// 可以根据实际情况添加其他需要移除的事件
+			}, // 新增:清理所有定时器
+			clearAllTimers() {
+				if (this.intervalId) {
+					clearInterval(this.intervalId);
+					this.intervalId = null;
+				}
+
+				if (this.pingpangTimes) {
+					clearInterval(this.pingpangTimes);
+					this.pingpangTimes = null;
+				}
+
+				if (this.reconnectTimer) {
+					clearTimeout(this.reconnectTimer);
+					this.reconnectTimer = null;
+				}
+
+				if (this.scrollTimer) {
+					clearTimeout(this.scrollTimer);
+					this.scrollTimer = null;
+				}
+
+				if (this.searchTimer) {
+					clearTimeout(this.searchTimer);
+					this.searchTimer = null;
+				}
+
+				if (this.purchasePromptTimer) {
+					clearTimeout(this.purchasePromptTimer);
+					this.purchasePromptTimer = null;
+				}
+			},
 			// 初始化当前直播间数据
 			async initCurrentLiveData() {
 				const currentLive = this.list[this.currentSwiperIndex];
@@ -633,34 +592,34 @@ clearAllTimers() {
 
 			// 初始化直播间列表
 			async initLiveList(options) {
-			    try {
-			        await this.getList(); // 先加载直播间列表
-			        if (this.list.length === 0) {
-			            console.error("直播间列表为空,无法初始化");
-			            return;
-			        }
-			
-			        // 设置初始直播间索引
-			        if (options.liveId) {
-			            const index = this.list.findIndex(item => item.liveId == options.liveId);
-			            this.currentSwiperIndex = index !== -1 ? index : 0;
-			        } else {
-			            this.currentSwiperIndex = 0;
-			        }
-			
-			        // 获取当前直播间的liveItem
-			        const currentLive = this.list[this.currentSwiperIndex];
-			        if (currentLive) {
-			            this.liveId = currentLive.liveId;
-			            // 只初始化当前直播间的WebSocket
-			            await this.getLiveMsg(currentLive);
-			            await this.initCurrentLiveData();
-			            this.preloadNearbyLives();
-			        }
-			
-			    } catch (error) {
-			        console.error("初始化失败:", error);
-			    }
+				try {
+					await this.getList(); // 先加载直播间列表
+					if (this.list.length === 0) {
+						console.error("直播间列表为空,无法初始化");
+						return;
+					}
+
+					// 设置初始直播间索引
+					if (options.liveId) {
+						const index = this.list.findIndex(item => item.liveId == options.liveId);
+						this.currentSwiperIndex = index !== -1 ? index : 0;
+					} else {
+						this.currentSwiperIndex = 0;
+					}
+
+					// 获取当前直播间的liveItem
+					const currentLive = this.list[this.currentSwiperIndex];
+					if (currentLive) {
+						this.liveId = currentLive.liveId;
+						// 只初始化当前直播间的WebSocket
+						await this.getLiveMsg(currentLive);
+						await this.initCurrentLiveData();
+						this.preloadNearbyLives();
+					}
+
+				} catch (error) {
+					console.error("初始化失败:", error);
+				}
 			},
 			// 预加载相邻直播间
 			async preloadNearbyLives() {
@@ -697,47 +656,46 @@ clearAllTimers() {
 			},
 			// Swiper切换事件
 			async onSwiperChange(e) {
-			  const newIndex = e.detail.current;
-			  const oldIndex = this.currentSwiperIndex;
-			
-			  // 1. 关闭旧直播间连接,暂停视频
-			  const oldLive = this.list[oldIndex];
-			  if (oldLive) {
-			    this.closeWebSocket(oldLive.liveId);
-			    this.pauseVideo(oldLive);
-			  }
-			
-			  // 2. 更新当前直播间索引和 liveId
-			  this.currentSwiperIndex = newIndex;
-			  const newLive = this.list[newIndex];
-			  if (!newLive) return;
-			  this.liveId = newLive.liveId;
-			
-			  // 3. 重置全局数据(避免旧数据影响新直播间)
-			  this.liveViewers = []; // 重置观众列表
-			  this.products = []; // 重置商品列表
-			  this.store = {}; // 重置店铺信息
-			  this.orderUser = {}; // 重置正在购买用户
-			  this.viewPageNum = 1; // 重置观众分页
-			  this.viewNoMoreData = false;
-			
-			  // 4. 加载新直播间数据
-			  try {
-			    // 并行加载关键数据(视频、观众、商品等)
-			    await Promise.all([
-			      this.getliving(newLive), // 视频源
-			      this.getLiveMsg(newLive), // 聊天记录
-			      this.getliveViewData(newLive), // 点赞/关注数据
-			      this.getliveUser(), // 观众列表(当前直播间)
-			      this.getliveOrder() // 正在购买用户(当前直播间)
-			    ]);
-			    // 播放新视频
-			    this.$nextTick(() => this.playVideo(newLive));
-			  } catch (error) {
-			    console.error('切换直播间加载数据失败:', error);
-			  }
-			}
-,
+				const newIndex = e.detail.current;
+				const oldIndex = this.currentSwiperIndex;
+
+				// 1. 关闭旧直播间连接,暂停视频
+				const oldLive = this.list[oldIndex];
+				if (oldLive) {
+					this.closeWebSocket(oldLive.liveId);
+					this.pauseVideo(oldLive);
+				}
+
+				// 2. 更新当前直播间索引和 liveId
+				this.currentSwiperIndex = newIndex;
+				const newLive = this.list[newIndex];
+				if (!newLive) return;
+				this.liveId = newLive.liveId;
+
+				// 3. 重置全局数据(避免旧数据影响新直播间)
+				this.liveViewers = []; // 重置观众列表
+				this.products = []; // 重置商品列表
+				this.store = {}; // 重置店铺信息
+				this.orderUser = {}; // 重置正在购买用户
+				this.viewPageNum = 1; // 重置观众分页
+				this.viewNoMoreData = false;
+
+				// 4. 加载新直播间数据
+				try {
+					// 并行加载关键数据(视频、观众、商品等)
+					await Promise.all([
+						this.getliving(newLive), // 视频源
+						this.getLiveMsg(newLive), // 聊天记录
+						this.getliveViewData(newLive), // 点赞/关注数据
+						this.getliveUser(), // 观众列表(当前直播间)
+						this.getliveOrder() // 正在购买用户(当前直播间)
+					]);
+					// 播放新视频
+					this.$nextTick(() => this.playVideo(newLive));
+				} catch (error) {
+					console.error('切换直播间加载数据失败:', error);
+				}
+			},
 
 			// 获取直播间列表
 			async getList() {
@@ -890,35 +848,34 @@ clearAllTimers() {
 
 			// 获取直播间用户
 			async getliveUser(isLoadMore = false) {
-			  // 强制使用当前 liveId,避免使用旧值
-			  const currentLiveId = this.liveId;
-			  if (!currentLiveId) return;
-			
-			  if (this.viewLoading || this.viewNoMoreData) return;
-			  this.viewLoading = true;
-			
-			  try {
-			    const res = await watchUserList(currentLiveId, this.viewPageSize, this.viewPageNum, false);
-			    if (res.code === 200) {
-			      // 若请求期间已切换直播间,忽略旧数据
-			      if (this.liveId !== currentLiveId) return;
-			
-			      this.liveUserTotal = res.total;
-			      if (res.rows.length === 0) {
-			        this.viewNoMoreData = true;
-			        return;
-			      }
-			
-			      this.liveViewers = isLoadMore 
-			        ? [...this.liveViewers, ...res.rows] 
-			        : res.rows; // 首次加载/切换直播间时重置数据
-			      this.viewPageNum++;
-			    }
-			  } catch (error) {
-			    console.error('获取观众列表失败:', error);
-			  } finally {
-			    this.viewLoading = false;
-			  }
+				// 强制使用当前 liveId,避免使用旧值
+				const currentLiveId = this.liveId;
+				if (!currentLiveId) return;
+
+				if (this.viewLoading || this.viewNoMoreData) return;
+				this.viewLoading = true;
+
+				try {
+					const res = await watchUserList(currentLiveId, this.viewPageSize, this.viewPageNum, false);
+					if (res.code === 200) {
+						// 若请求期间已切换直播间,忽略旧数据
+						if (this.liveId !== currentLiveId) return;
+
+						this.liveUserTotal = res.total;
+						if (res.rows.length === 0) {
+							this.viewNoMoreData = true;
+							return;
+						}
+
+						this.liveViewers = isLoadMore ? [...this.liveViewers, ...res.rows] :
+							res.rows; // 首次加载/切换直播间时重置数据
+						this.viewPageNum++;
+					}
+				} catch (error) {
+					console.error('获取观众列表失败:', error);
+				} finally {
+					this.viewLoading = false;
+				}
 			},
 			// 滚动到底部触发
 			handleScrollToLower() {
@@ -1194,22 +1151,22 @@ clearAllTimers() {
 			},
 			//正在购买
 			async getliveOrder() {
-			  const currentLiveId = this.liveId;
-			  if (!currentLiveId) return;
-			
-			  try {
-			    const res = await liveOrderUser(currentLiveId);
-			    if (res.code === 200) {
-			      // 绑定到当前 liveItem
-			      const currentLive = this.list[this.currentSwiperIndex];
-			      if (currentLive) {
-			        this.$set(currentLive, 'orderUser', res);
-			        this.orderUser = res; // 同步全局变量
-			      }
-			    }
-			  } catch (error) {
-			    console.error('获取正在购买用户失败:', error);
-			  }
+				const currentLiveId = this.liveId;
+				if (!currentLiveId) return;
+
+				try {
+					const res = await liveOrderUser(currentLiveId);
+					if (res.code === 200) {
+						// 绑定到当前 liveItem
+						const currentLive = this.list[this.currentSwiperIndex];
+						if (currentLive) {
+							this.$set(currentLive, 'orderUser', res);
+							this.orderUser = res; // 同步全局变量
+						}
+					}
+				} catch (error) {
+					console.error('获取正在购买用户失败:', error);
+				}
 			},
 			// 获取直播间信息接口
 			getLiveinformation() {
@@ -1232,15 +1189,15 @@ clearAllTimers() {
 
 			// 修改点赞方法
 			async onLike(liveItem) {
-			  if (!liveItem || !liveItem.liveId) return;
-			  try {
-			    const res = await liveDataLike(liveItem.liveId);
-			    if (res.code === 200 && liveItem.liveViewData) {
-			      liveItem.liveViewData.like++; // 只更新当前直播间的点赞数
-			    }
-			  } catch (error) {
-			    console.error('点赞失败:', error);
-			  }
+				if (!liveItem || !liveItem.liveId) return;
+				try {
+					const res = await liveDataLike(liveItem.liveId);
+					if (res.code === 200 && liveItem.liveViewData) {
+						liveItem.liveViewData.like++; // 只更新当前直播间的点赞数
+					}
+				} catch (error) {
+					console.error('点赞失败:', error);
+				}
 			},
 			// 去购买,跳商品详情
 			goShop(productId, goodsId) {
@@ -1251,48 +1208,29 @@ clearAllTimers() {
 			},
 
 			// 查询店铺
-<<<<<<< HEAD
 			async queryCollect() {
-				  const currentLive = this.list[this.currentSwiperIndex];
-				  if (!currentLive || !currentLive.liveId) return;
-				  
-				const { storeId } = currentLive;
-				  if (!storeId) return;
-				  
-				  
-				   try {
-				      const res = await store(currentLive.storeId, currentLive.inputInfo);
-				      if (res.code === 200) {
-				        // 数据绑定到当前 liveItem,避免全局污染
-				        this.$set(currentLive, 'products', res.data.goodsList);
-				        this.$set(currentLive, 'store', res.data);
-				        // 同步更新全局变量(供弹窗使用)
-				        this.products = res.data.goodsList;
-				        this.store = res.data;
-				      }
-				    } catch (error) {
-				      console.error('获取小黄车商品失败:', error);
-				    }
-=======
-			queryCollect() {
-				if (!this.storeId) return;
-				if (!this.liveId) return;
-				store(this.storeId, this.inputInfo,this.liveId).then(res => {
-						if (res.code == 200) {
-							console.log("查询店铺>>", res)
-							this.products = res.data.goodsList
-							this.store = res.data
-						} else {
-							uni.showToast({
-								title: res.msg,
-								icon: 'none'
-							});
-						}
-					},
-					rej => {}
-				);
->>>>>>> 57028795d3bcee2e15cce5538d4362a47313f66a
+				const currentLive = this.list[this.currentSwiperIndex];
+				if (!currentLive || !currentLive.liveId) return;
+
+				const {
+					storeId
+				} = currentLive;
+				if (!storeId) return;
+				try {
+					const res = await store(currentLive.storeId, currentLive.inputInfo);
+					if (res.code === 200) {
+						// 数据绑定到当前 liveItem,避免全局污染
+						this.$set(currentLive, 'products', res.data.goodsList);
+						this.$set(currentLive, 'store', res.data);
+						// 同步更新全局变量(供弹窗使用)
+						this.products = res.data.goodsList;
+						this.store = res.data;
+					}
+				} catch (error) {
+					console.error('获取小黄车商品失败:', error);
+				}
 			},
+
 			// 店铺收藏
 			onStoreCollect() {
 				if (!this.storeId) return;
@@ -1418,31 +1356,6 @@ clearAllTimers() {
 			closeRed() {
 				this.showRed = !this.showRed
 			},
-			// longPress() {
-			// 	this.timeout = setTimeout(() => {
-			// 		this.isLongPress = true;
-			// 		// 执行保存图片的操作
-			// 		uni.saveImageToPhotosAlbum({
-			// 			filePath: this.livedata.qwQrCode, // 图片的本地路径或网络路径
-			// 			success: () => {
-			// 				uni.showToast({
-			// 					title: '保存成功'
-			// 				});
-			// 			},
-			// 			fail: () => {
-			// 				uni.showToast({
-			// 					title: '',
-			// 					icon: 'none'
-			// 				});
-			// 			}
-			// 		});
-			// 	}, 500); // 设置长按的阈值时间,这里是500毫秒
-			// },
-			// cancelLongPress() {
-			// 	clearTimeout(this.timeout);
-			// 	this.isLongPress = false;
-			// },
-
 			// 触摸结束
 			handleTouchEnd() {
 				this.isZoom = false; // 恢复原状
@@ -1533,57 +1446,58 @@ clearAllTimers() {
 				}, 30000); // 30秒心跳间隔
 			},
 			initSocket(liveItem) {
-			    // 如果没有指定直播间,不初始化
-			    if (!liveItem || !liveItem.liveId) return;
-			    
-			    const liveId = liveItem.liveId;
-			    
-			    // 检查是否是当前活跃的直播间
-			    if (this.currentSwiperIndex !== this.list.findIndex(item => item.liveId === liveId)) {
-			        console.log(`不初始化非当前直播间 ${liveId} 的WebSocket`);
-			        return;
-			    }
-			
-			    // 关闭之前的连接(如果存在)
-			    if (this.socketInstances[liveId]) {
-			        this.closeWebSocket(liveId);
-			    }
-			
-			    // 防止重复创建
-			    if (this.socketInstances[liveId]?.isOpen || this.reconnectCount >= this.maxReconnectAttempts) {
-			        return;
-			    }
-			
-			    this.isManualClose = false;
-			
-			    // 生成签名
-			    const signature = CryptoJS.HmacSHA256(
-			        `${liveId}${this.userinfo.userId}${this.userType}${this.timestamp}`,
-			        this.timestamp.toString()
-			    ).toString(CryptoJS.enc.Hex);
-			
-			    // 初始化实例状态
-			    this.socketInstances[liveId] = {
-			        instance: null,
-			        isOpen: false
-			    };
-			
-			    try {
-			        const socketTask = uni.connectSocket({
-			            url: `${wsUrl}?userId=${this.userinfo.userId}&liveId=${liveId}&userType=${this.userType}&timestamp=${this.timestamp}&signature=${signature}`,
-			            success: () => {
-			                this.socketInstances[liveId].instance = socketTask;
-			                this.setupSocketListeners(liveId);
-			            },
-			            fail: (err) => {
-			                console.error('WebSocket 连接失败:', err);
-			                this.scheduleReconnect(liveId);
-			            }
-			        });
-			    } catch (e) {
-			        console.error('创建 WebSocket 异常:', e);
-			        this.scheduleReconnect(liveId);
-			    }
+				// 如果没有指定直播间,不初始化
+				if (!liveItem || !liveItem.liveId) return;
+
+				const liveId = liveItem.liveId;
+
+				// 检查是否是当前活跃的直播间
+				if (this.currentSwiperIndex !== this.list.findIndex(item => item.liveId === liveId)) {
+					console.log(`不初始化非当前直播间 ${liveId} 的WebSocket`);
+					return;
+				}
+
+				// 关闭之前的连接(如果存在)
+				if (this.socketInstances[liveId]) {
+					this.closeWebSocket(liveId);
+				}
+
+				// 防止重复创建
+				if (this.socketInstances[liveId]?.isOpen || this.reconnectCount >= this
+					.maxReconnectAttempts) {
+					return;
+				}
+
+				this.isManualClose = false;
+
+				// 生成签名
+				const signature = CryptoJS.HmacSHA256(
+					`${liveId}${this.userinfo.userId}${this.userType}${this.timestamp}`,
+					this.timestamp.toString()
+				).toString(CryptoJS.enc.Hex);
+
+				// 初始化实例状态
+				this.socketInstances[liveId] = {
+					instance: null,
+					isOpen: false
+				};
+
+				try {
+					const socketTask = uni.connectSocket({
+						url: `${wsUrl}?userId=${this.userinfo.userId}&liveId=${liveId}&userType=${this.userType}&timestamp=${this.timestamp}&signature=${signature}`,
+						success: () => {
+							this.socketInstances[liveId].instance = socketTask;
+							this.setupSocketListeners(liveId);
+						},
+						fail: (err) => {
+							console.error('WebSocket 连接失败:', err);
+							this.scheduleReconnect(liveId);
+						}
+					});
+				} catch (e) {
+					console.error('创建 WebSocket 异常:', e);
+					this.scheduleReconnect(liveId);
+				}
 			},
 			// 设置 WebSocket 监听器
 			setupSocketListeners(liveId) {
@@ -1606,32 +1520,26 @@ clearAllTimers() {
 						this.scheduleReconnect(liveId);
 					}
 				});
-
-
 				socketInstance.onMessage((res) => {
 					try {
 						const redata = JSON.parse(res.data);
-<<<<<<< HEAD
 						// 找到对应的直播间并更新数据
 						const targetLive = this.list.find(item => item.liveId === liveId);
 						if (targetLive) {
 							targetLive.talklist.push(redata.data);
 							this.$nextTick(() => {
-								targetLive.scrollIntoView = `list_${targetLive.talklist.length - 1}`;
+								targetLive.scrollIntoView =
+									`list_${targetLive.talklist.length - 1}`;
 							});
-=======
-						
-						if(redata.data.cmd == 'sendMsg'){
-							this.talklist.push(redata.data);
-							this.$nextTick(() => {
-								this.scrollIntoView = `list_${this.talklist.length - 1}`; // 最后一项的id
-							});
-						}
-						else if (redata.data.cmd == 'deleteId') {
-							uni.$emit('deleteId');
-						}
->>>>>>> 57028795d3bcee2e15cce5538d4362a47313f66a
-
+							if (redata.data.cmd == 'sendMsg') {
+								this.talklist.push(redata.data);
+								this.$nextTick(() => {
+									this.scrollIntoView =
+										`list_${this.talklist.length - 1}`; // 最后一项的id
+								});
+							} else if (redata.data.cmd == 'deleteId') {
+								uni.$emit('deleteId');
+							}
 							// 处理各种消息类型
 							this.handleSocketMessage(redata.data, targetLive);
 						}
@@ -1714,37 +1622,32 @@ clearAllTimers() {
 					nickName: this.userinfo.nickName,
 					avatar: this.userinfo.avatar
 				};
-<<<<<<< HEAD
-
 				if (!liveItem.value.trim()) {
-=======
-				console.log(!this.value.trim())
-				if (!this.value.trim()) { // 优化空消息判断
->>>>>>> 57028795d3bcee2e15cce5538d4362a47313f66a
-					uni.showToast({
-						title: "不能发送空消息",
-						icon: 'none'
-					});
-					return;
-				}
-
-				socketItem.instance.send({
-					data: JSON.stringify(data),
-					success: () => {
-						console.log("发送成功");
-						liveItem.value = ''; // 清空当前直播间的输入框
-					},
-					fail: (err) => {
-						console.error("发送失败:", err);
+					console.log(!this.value.trim())
+					if (!this.value.trim()) { // 优化空消息判断
 						uni.showToast({
-							title: "发送失败,请重试",
+							title: "不能发送空消息",
 							icon: 'none'
 						});
-					}
-				});
-			},
-		},
-	};
+						return;
+					}}
+					socketItem.instance.send({
+						data: JSON.stringify(data),
+						success: () => {
+							console.log("发送成功");
+							liveItem.value = ''; // 清空当前直播间的输入框
+						},
+						fail: (err) => {
+							console.error("发送失败:", err);
+							uni.showToast({
+								title: "发送失败,请重试",
+								icon: 'none'
+							});
+						}
+					});
+				},
+			}
+		};
 </script>
 
 <style scoped lang="scss">

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
unpackage/dist/dev/mp-weixin/api/live.js


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
unpackage/dist/dev/mp-weixin/pages/home/living.js


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
unpackage/dist/dev/mp-weixin/pages/home/living.wxml


이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.