| | |
| | | /** |
| | | * 跳转后台配置的微赞直播 H5 页面。 |
| | | */ |
| | | const goWeiZanLive = async () => { |
| | | const goWeiZanLive = () => { |
| | | if (!weiZanLiveH5Url.value.trim()) { |
| | | uni.showToast({ title: '直播间地址暂未配置', icon: 'none' }); |
| | | return; |
| | |
| | | return; |
| | | } |
| | | weiZanLiveOpening.value = true; |
| | | uni.showLoading({ title: '正在进入直播间', mask: true }); |
| | | try { |
| | | const cachedUser = uni.getStorageSync('appUserInfo'); |
| | | const userId = cachedUser?.id; |
| | | if (!userId) { |
| | | uni.showToast({ title: '请先登录', icon: 'none' }); |
| | | return; |
| | | } |
| | | const res = await createLiveRoomEntry(userId); |
| | | const targetUrl = res?.data?.url?.trim(); |
| | | if (res?.code !== 0 || !targetUrl || !isValidLiveRoomUrl(targetUrl)) { |
| | | uni.showToast({ title: res?.msg || '获取直播间地址失败', icon: 'none' }); |
| | | return; |
| | | } |
| | | uni.navigateTo({ |
| | | url: `/pages/webview/webview?url=${encodeURIComponent(targetUrl)}&title=${encodeURIComponent('微赞直播')}` |
| | | url: `/pages/webview/webview?url=${encodeURIComponent(weiZanLiveH5Url.value)}&title=${encodeURIComponent('微赞直播')}` |
| | | }); |
| | | } catch { |
| | | uni.showToast({ title: '获取直播间地址失败', icon: 'none' }); |
| | | } finally { |
| | | uni.hideLoading(); |
| | | weiZanLiveOpening.value = false; |
| | | } |
| | | }; |
| | | |
| | | const isValidLiveRoomUrl = (targetUrl : string) => { |
| | | try { |
| | | const parsedUrl = new URL(targetUrl); |
| | | return parsedUrl.protocol === 'https:'; |
| | | } catch { |
| | | return false; |
| | | } |
| | | }; |
| | | |