fix:修正优化首页、个人中心页面广告图url跳转
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
<template>
|
||||
<view class="webview-container">
|
||||
<!-- web-view 组件用于显示外部网页 -->
|
||||
<web-view :src="webUrl" @message="handleMessage" @load="handleLoad" @error="handleError"></web-view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { useI18n } from '@/utils/i18n.js'
|
||||
|
||||
const { t: $t } = useI18n()
|
||||
|
||||
// 网页链接
|
||||
const webUrl = ref('')
|
||||
|
||||
// 页面加载时获取传入的 URL 参数
|
||||
onLoad((options) => {
|
||||
if (options.url) {
|
||||
// 解码 URL
|
||||
webUrl.value = decodeURIComponent(options.url)
|
||||
console.log('加载外部链接:', webUrl.value)
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: $t('common.invalidUrl') || '无效的链接',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
// 2秒后返回上一页
|
||||
setTimeout(() => {
|
||||
uni.navigateBack()
|
||||
}, 2000)
|
||||
}
|
||||
})
|
||||
|
||||
// 网页加载完成
|
||||
const handleLoad = (e) => {
|
||||
console.log('网页加载完成:', e)
|
||||
}
|
||||
|
||||
// 网页加载错误
|
||||
const handleError = (e) => {
|
||||
console.error('网页加载错误:', e)
|
||||
uni.showToast({
|
||||
title: $t('common.loadFailed') || '加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
|
||||
// 接收网页消息(web-view 向小程序发送消息)
|
||||
const handleMessage = (e) => {
|
||||
console.log('收到网页消息:', e)
|
||||
// 可以根据需要处理网页发来的消息
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
// 支持分享
|
||||
onShareAppMessage() {
|
||||
const $t = this.$t || ((key) => key)
|
||||
return {
|
||||
title: $t('share.title') || '分享',
|
||||
path: '/pages/index/index'
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.webview-container {
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
overflow: hidden;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user