You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
117 lines
2.5 KiB
117 lines
2.5 KiB
<!--微信绑定WebView页面-->
|
|
<template>
|
|
<view class="webview-container">
|
|
<web-view
|
|
:src="webviewUrl"
|
|
@message="onMessage"
|
|
@load="onLoad"
|
|
@error="onError">
|
|
</web-view>
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
data() {
|
|
return {
|
|
webviewUrl: ''
|
|
}
|
|
},
|
|
onLoad(options) {
|
|
console.log('webview页面参数:', options)
|
|
|
|
if (options.url) {
|
|
this.webviewUrl = decodeURIComponent(options.url)
|
|
console.log('webview URL:', this.webviewUrl)
|
|
} else {
|
|
uni.showToast({
|
|
title: '参数错误',
|
|
icon: 'none'
|
|
})
|
|
setTimeout(() => {
|
|
uni.navigateBack()
|
|
}, 2000)
|
|
}
|
|
},
|
|
methods: {
|
|
// 监听webview消息
|
|
onMessage(event) {
|
|
console.log('收到webview消息:', event)
|
|
const detail = event.detail
|
|
if (detail && detail.data && detail.data.length > 0) {
|
|
const message = detail.data[0]
|
|
this.handleWebviewMessage(message)
|
|
}
|
|
},
|
|
|
|
// 处理webview消息
|
|
handleWebviewMessage(message) {
|
|
console.log('处理webview消息:', message)
|
|
|
|
if (message.type === 'wechat_bind_success') {
|
|
// 绑定成功
|
|
uni.showToast({
|
|
title: '微信绑定成功!',
|
|
icon: 'success',
|
|
duration: 2000
|
|
})
|
|
|
|
setTimeout(() => {
|
|
// 返回上一页并刷新
|
|
uni.navigateBack({
|
|
delta: 2 // 回到设置页面
|
|
})
|
|
}, 2000)
|
|
|
|
} else if (message.type === 'wechat_bind_error') {
|
|
// 绑定失败
|
|
uni.showToast({
|
|
title: message.msg || '绑定失败',
|
|
icon: 'none',
|
|
duration: 3000
|
|
})
|
|
|
|
setTimeout(() => {
|
|
uni.navigateBack()
|
|
}, 3000)
|
|
|
|
} else if (message.type === 'wechat_bind_cancel') {
|
|
// 用户取消
|
|
uni.showToast({
|
|
title: '用户取消授权',
|
|
icon: 'none'
|
|
})
|
|
|
|
setTimeout(() => {
|
|
uni.navigateBack()
|
|
}, 1500)
|
|
}
|
|
},
|
|
|
|
// webview加载完成
|
|
onLoad() {
|
|
console.log('webview加载完成')
|
|
},
|
|
|
|
// webview加载错误
|
|
onError(error) {
|
|
console.error('webview加载错误:', error)
|
|
uni.showToast({
|
|
title: '页面加载失败',
|
|
icon: 'none'
|
|
})
|
|
|
|
setTimeout(() => {
|
|
uni.navigateBack()
|
|
}, 2000)
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="less" scoped>
|
|
.webview-container {
|
|
width: 100%;
|
|
height: 100vh;
|
|
}
|
|
</style>
|