直播更新

This commit is contained in:
陈誉午
2026-08-03 11:05:19 +08:00
parent 994b267f5c
commit d0776f9676
12 changed files with 288 additions and 177 deletions
+62 -29
View File
@@ -49,7 +49,12 @@ Page({
}
this.cacheRedirectPath(options);
this.setData({ activityId, inviterToken: options.inviterToken, userId: options.userId, isLandscape: String(options.isLandscape) === "true", });
this.setData({
activityId,
inviterToken: options.inviterToken,
userId: options.userId,
isLandscape: String(options.isLandscape) === "true",
});
const app = getApp<IAppOption>();
this.setLoading("正在校验登录状态...");
const isLogin = app.checkLoginState();
@@ -57,22 +62,18 @@ Page({
wx.reLaunch({ url: `/package-live/login/login?userId=${options?.userId}&activityId=${activityId}` });
return;
};
},
onReady() {
// onReady在页面生命周期中只执行一次,将初始化放在此处避免
// onHide销毁SDK后onShow重复初始化导致声音重复播放
this.initSdk(this.data.activityId, pageOptionsCache);
},
onShow() {
if (!this.data.sdk && this.data.activityId) {
this.initSdk(this.data.activityId, pageOptionsCache);
}
},
await this.initSdk(activityId, options);
},
onHide() {
// 不销毁SDK,避免接电话返回后重复初始化导致声音重叠
},
async initSdk(
activityId: number,
options?: Record<string, string | undefined>,
) {
if (this.data.sdk) return; // 防止重复实例化SDK
try {
this.clearError();
this.setLoading("正在获取直播凭证...");
@@ -85,7 +86,6 @@ Page({
throw new Error("未获取到直播凭证,请稍后重试");
}
this.destroySdk();
this.setLoading("正在进入直播间...");
const sdk = VolcMiniSdk({
@@ -103,28 +103,29 @@ Page({
});
const debugInfo = sdk.getDebugInfo()
console.log('debugInfo:', debugInfo)
sdk.on(EVENTS.card.click, (payload: any) => {
wx.navigateTo({
url: payload?.url
})
});
// 监听浮窗商品卡片点击事件。
sdk.on('floatingCard.click', (payload: any) => {
wx.navigateTo({
url: payload?.url
})
})
//商品卡片,浮动卡片
sdk.on('floatingCard.click', this.handleFloatingCardClick);
//商品卡片,购物车
sdk.on(EVENTS.card.click, (payload: any) => {
console.log('card.click', payload)
});
// 按钮红包功能
sdk.on(EVENTS.feature.click, (payload: any) => {
console.log('feature.click', payload)
})
});
sdk.on(EVENTS.luckymoney.withdrawal, (payload: any) => {
this.handleReceive(payload);
});
sdk.on(EVENTS.activity.status, (status: 1 | 2 | 3 | 4 | 5) => {
if (status === 4) {
wx.switchTab({
url: `/pages/tab-bar/profile/index`
})
}
});
this.setData({
sdk,
loading: false,
@@ -171,7 +172,40 @@ Page({
data?.signToken || ""
);
},
handleReceive: lockPromise(async function(data: any) {
handleFloatingCardClick: lockPromise(async function (payload: any) {
if (!payload?.RedirectUrl) return;
try {
const res = await request({
options: {
url: payload.RedirectUrl,
method: 'POST',
},
});
if (res.code !== 200) {
wx.showToast({ title: res.msg || '请求失败', icon: 'none' });
return;
}
const payParams = res.data;
wx.requestPayment({
timeStamp: payParams.timeStamp,
nonceStr: payParams.nonceStr,
package: payParams.packageVal,
signType: payParams.signType || 'RSA',
paySign: payParams.paySign,
success() {
wx.showToast({ title: '支付成功', icon: 'success' });
console.log('支付成功:');
},
fail(err) {
wx.showToast({ title: '支付取消', icon: 'none' });
console.error('支付失败:', err);
},
});
} catch (err) {
console.error('floatingCard请求失败:', err);
}
}),
handleReceive: lockPromise(async function (data: any) {
const params = {
appId: appId,
outRewardsId: data.redPacketId,
@@ -274,7 +308,6 @@ Page({
});
}
},
commentCheck() { },
onUnload() {
this.destroySdk();