|
|
|
@ -1,12 +1,29 @@ |
|
|
|
<!--微信绑定WebView页面--> |
|
|
|
<template> |
|
|
|
<view class="webview-container"> |
|
|
|
<!-- 显示加载状态 --> |
|
|
|
<view v-if="!webviewUrl || isLoading" class="loading-container"> |
|
|
|
<view class="loading-text">正在加载微信授权页面...</view> |
|
|
|
<view class="debug-info" v-if="webviewUrl"> |
|
|
|
<text>URL: {{ webviewUrl }}</text> |
|
|
|
</view> |
|
|
|
</view> |
|
|
|
|
|
|
|
<!-- webview --> |
|
|
|
<web-view |
|
|
|
v-if="webviewUrl" |
|
|
|
:src="webviewUrl" |
|
|
|
@message="onMessage" |
|
|
|
@load="onLoad" |
|
|
|
@load="onWebviewLoad" |
|
|
|
@error="onError"> |
|
|
|
</web-view> |
|
|
|
|
|
|
|
<!-- 错误状态 --> |
|
|
|
<view v-if="hasError" class="error-container"> |
|
|
|
<view class="error-text">页面加载失败</view> |
|
|
|
<view class="error-detail">{{ errorMessage }}</view> |
|
|
|
<button @click="goBack" class="back-btn">返回</button> |
|
|
|
</view> |
|
|
|
</view> |
|
|
|
</template> |
|
|
|
|
|
|
|
@ -14,7 +31,10 @@ |
|
|
|
export default { |
|
|
|
data() { |
|
|
|
return { |
|
|
|
webviewUrl: '' |
|
|
|
webviewUrl: '', |
|
|
|
isLoading: true, |
|
|
|
hasError: false, |
|
|
|
errorMessage: '' |
|
|
|
} |
|
|
|
}, |
|
|
|
onLoad(options) { |
|
|
|
@ -23,14 +43,15 @@ export default { |
|
|
|
if (options.url) { |
|
|
|
this.webviewUrl = decodeURIComponent(options.url) |
|
|
|
console.log('webview URL:', this.webviewUrl) |
|
|
|
} else { |
|
|
|
uni.showToast({ |
|
|
|
title: '参数错误', |
|
|
|
icon: 'none' |
|
|
|
}) |
|
|
|
|
|
|
|
// 3秒后隐藏加载状态(即使webview没有触发load事件) |
|
|
|
setTimeout(() => { |
|
|
|
uni.navigateBack() |
|
|
|
}, 2000) |
|
|
|
this.isLoading = false |
|
|
|
}, 3000) |
|
|
|
} else { |
|
|
|
this.hasError = true |
|
|
|
this.errorMessage = '缺少URL参数' |
|
|
|
console.error('webview页面缺少URL参数') |
|
|
|
} |
|
|
|
}, |
|
|
|
methods: { |
|
|
|
@ -89,21 +110,22 @@ export default { |
|
|
|
}, |
|
|
|
|
|
|
|
// webview加载完成 |
|
|
|
onLoad() { |
|
|
|
console.log('webview加载完成') |
|
|
|
onWebviewLoad(event) { |
|
|
|
console.log('webview加载完成:', event) |
|
|
|
this.isLoading = false |
|
|
|
}, |
|
|
|
|
|
|
|
// webview加载错误 |
|
|
|
onError(error) { |
|
|
|
console.error('webview加载错误:', error) |
|
|
|
uni.showToast({ |
|
|
|
title: '页面加载失败', |
|
|
|
icon: 'none' |
|
|
|
}) |
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
uni.navigateBack() |
|
|
|
}, 2000) |
|
|
|
this.isLoading = false |
|
|
|
this.hasError = true |
|
|
|
this.errorMessage = error.detail?.errMsg || '未知错误' |
|
|
|
}, |
|
|
|
|
|
|
|
// 返回按钮 |
|
|
|
goBack() { |
|
|
|
uni.navigateBack() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -113,5 +135,73 @@ export default { |
|
|
|
.webview-container { |
|
|
|
width: 100%; |
|
|
|
height: 100vh; |
|
|
|
position: relative; |
|
|
|
} |
|
|
|
|
|
|
|
.loading-container { |
|
|
|
position: absolute; |
|
|
|
top: 0; |
|
|
|
left: 0; |
|
|
|
right: 0; |
|
|
|
bottom: 0; |
|
|
|
display: flex; |
|
|
|
flex-direction: column; |
|
|
|
justify-content: center; |
|
|
|
align-items: center; |
|
|
|
background-color: #fff; |
|
|
|
z-index: 10; |
|
|
|
} |
|
|
|
|
|
|
|
.loading-text { |
|
|
|
font-size: 16px; |
|
|
|
color: #333; |
|
|
|
margin-bottom: 20px; |
|
|
|
} |
|
|
|
|
|
|
|
.debug-info { |
|
|
|
padding: 10px; |
|
|
|
background-color: #f5f5f5; |
|
|
|
border-radius: 4px; |
|
|
|
max-width: 90%; |
|
|
|
font-size: 12px; |
|
|
|
color: #666; |
|
|
|
word-break: break-all; |
|
|
|
} |
|
|
|
|
|
|
|
.error-container { |
|
|
|
position: absolute; |
|
|
|
top: 0; |
|
|
|
left: 0; |
|
|
|
right: 0; |
|
|
|
bottom: 0; |
|
|
|
display: flex; |
|
|
|
flex-direction: column; |
|
|
|
justify-content: center; |
|
|
|
align-items: center; |
|
|
|
background-color: #fff; |
|
|
|
z-index: 10; |
|
|
|
} |
|
|
|
|
|
|
|
.error-text { |
|
|
|
font-size: 18px; |
|
|
|
color: #f56c6c; |
|
|
|
margin-bottom: 10px; |
|
|
|
} |
|
|
|
|
|
|
|
.error-detail { |
|
|
|
font-size: 14px; |
|
|
|
color: #999; |
|
|
|
margin-bottom: 20px; |
|
|
|
text-align: center; |
|
|
|
padding: 0 20px; |
|
|
|
} |
|
|
|
|
|
|
|
.back-btn { |
|
|
|
background-color: #29d3b4; |
|
|
|
color: white; |
|
|
|
border: none; |
|
|
|
padding: 10px 20px; |
|
|
|
border-radius: 4px; |
|
|
|
font-size: 16px; |
|
|
|
} |
|
|
|
</style> |