|
|
@@ -314,7 +314,6 @@
|
|
|
preloadCount: 5, // 预加载直播间数量
|
|
|
list: [], // 直播间列表
|
|
|
preloading: false, // 预加载状态
|
|
|
- socketInstances: {},
|
|
|
|
|
|
|
|
|
liveUserTotal: null,
|
|
|
@@ -393,10 +392,10 @@
|
|
|
if (options.liveId) {
|
|
|
this.liveId = options.liveId; // 仅当 liveId 变化时更新
|
|
|
}
|
|
|
- this.userinfo = JSON.parse(uni.getStorageSync("userInfo"))
|
|
|
+ this.userinfo = JSON.parse(uni.getStorageSync("userInfo"))
|
|
|
// 初始化直播间列表
|
|
|
this.initLiveList(options);
|
|
|
-
|
|
|
+
|
|
|
const platform = uni.getSystemInfoSync().platform;
|
|
|
if (['mp-weixin', 'mp-alipay', 'mp-baidu', 'mp-toutiao'].includes(platform)) {
|
|
|
// 确保 API 存在再调用
|
|
|
@@ -728,51 +727,6 @@
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
- // 预加载相邻直播间
|
|
|
- async preloadNearbyLives() {
|
|
|
- this.preloading = true;
|
|
|
- const currentIndex = this.currentSwiperIndex;
|
|
|
- const preloadIndexes = [];
|
|
|
- if (currentIndex > 0) preloadIndexes.push(currentIndex - 1);
|
|
|
- if (currentIndex < this.list.length - 1) preloadIndexes.push(currentIndex + 1);
|
|
|
-
|
|
|
- for (const index of preloadIndexes) {
|
|
|
- const liveItem = this.list[index];
|
|
|
- if (!liveItem || liveItem.loaded || liveItem.loading) continue;
|
|
|
-
|
|
|
- liveItem.loading = true; // 标记为加载中
|
|
|
- try {
|
|
|
- // 等待视频源加载完成
|
|
|
- await this.getliving(liveItem);
|
|
|
- // 确保其他必要数据加载
|
|
|
- await Promise.all([
|
|
|
- this.getLiveMsg(liveItem),
|
|
|
- this.getliveViewData(liveItem)
|
|
|
- ]);
|
|
|
- liveItem.loaded = true; // 所有数据加载完成才标记为“已加载”
|
|
|
- } catch (error) {
|
|
|
- console.error(`预加载直播间 ${index} 失败:`, error);
|
|
|
- liveItem.loaded = false; // 加载失败则不标记为已加载
|
|
|
- } finally {
|
|
|
- liveItem.loading = false;
|
|
|
- }
|
|
|
- }
|
|
|
- this.preloading = false;
|
|
|
- },
|
|
|
-
|
|
|
-
|
|
|
- openViews() {
|
|
|
- // 计算scroll-view高度
|
|
|
- this.$nextTick(() => {
|
|
|
- const query = uni.createSelectorQuery().in(this);
|
|
|
- query.select('.view-box').boundingClientRect(data => {
|
|
|
- if (data) {
|
|
|
- // 减去标题和底部固定区域的高度
|
|
|
- this.scrollHeight = data.height - 80 - 120; // 80是标题高度,120是底部高度
|
|
|
- }
|
|
|
- }).exec();
|
|
|
- });
|
|
|
- },
|
|
|
|
|
|
// 重置直播间数据
|
|
|
resetLiveData() {
|
|
|
@@ -1076,7 +1030,7 @@
|
|
|
if (currentLive) {
|
|
|
this.pauseVideo(currentLive);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 关闭所有WebSocket连接
|
|
|
this.closeWebSocket();
|
|
|
|
|
|
@@ -1411,7 +1365,7 @@
|
|
|
console.log(`不初始化非当前直播间 ${liveId} 的WebSocket`);
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
// 关闭之前的连接(如果存在)
|
|
|
if (this.socketInstances[liveId]) {
|
|
|
@@ -1469,7 +1423,7 @@
|
|
|
handleSocketMessage(message, liveItem) {
|
|
|
console.log("开始监听处理消息")
|
|
|
if(message.cmd == 'sendMsg'){
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
else if (message.cmd == 'red') {
|
|
|
// 领红包
|
|
|
@@ -2112,4 +2066,4 @@
|
|
|
:deep(.u-safe-area-inset-bottom) {
|
|
|
padding-bottom: 0
|
|
|
}
|
|
|
-</style>
|
|
|
+</style>
|