微信小程序兼容修改

This commit is contained in:
冯辉
2025-11-04 21:12:12 +08:00
parent 81aae7a9ad
commit 349d17b5c4
10 changed files with 528 additions and 186 deletions

View File

@@ -701,9 +701,43 @@ const handleServiceClick = (serviceType) => {
}
};
// 处理直播按钮点击
// 处理直播按钮点击 - 跳转微信视频号
const handleLiveClick = () => {
$api.msg('该功能正在开发中');
// #ifdef MP-WEIXIN
const feedId = 'sphKH1AEeLfTJJE';
// 使用微信原生 API 打开视频号直播
if (typeof wx !== 'undefined' && wx.openChannelsUserProfile) {
wx.openChannelsUserProfile({
// feedId: feedId,
finderUserName: feedId, // 视频号 finderUserName如果feedId足够可以留空
success: (res) => {
console.log('打开视频号成功', res);
},
fail: (err) => {
console.error('打开视频号失败', err);
$api.msg(err.errMsg || '无法打开直播,请稍后重试');
}
});
} else {
// 如果 API 不存在,尝试使用 uni API
uni.openChannelsLive({
feedId: feedId,
success: (res) => {
console.log('打开视频号成功', res);
},
fail: (err) => {
console.error('打开视频号失败', err);
$api.msg('无法打开直播,请检查微信版本或稍后重试');
}
});
}
// #endif
// #ifndef MP-WEIXIN
// 非微信小程序环境提示
$api.msg('该功能仅在微信小程序中可用');
// #endif
};
// 跳转到测试页面