copy1.nvue
1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<template>
<view class="content">
<CustomNavBar ref="navBar" :title="t('asis.HeatMap')" />
<button @click="openWebview">打开</button>
<button @click="closeWebview">关闭</button>
</view>
</template>
<script setup>
import { onMounted,onBeforeUnmount } from 'vue';
import { onBackPress } from '@dcloudio/uni-app'
import CustomNavBar from '@/components/CustomNav.nvue'
import {
t
} from '@/plugins/index.js'
let webview = null
onMounted(()=>{
openWebview()
})
onBeforeUnmount(()=>{
})
onBackPress(()=>{
closeWebview()
})
const openWebview = ()=>{
// 销毁已存在的 WebView
if (webview) {
plus.webview.close(webview)
webview = null
}
// 获取导航栏高度(默认值)
// const navHeight = this.navHeight || 44
const navHeight = 44
const statusBarHeight = plus.navigator.getStatusbarHeight()
const top = navHeight + statusBarHeight
// 创建新 WebView
webview = plus.webview.create(
// "https://store.keliuyun.com/apph5/heatMap?token=6c094ce1-0eb7-4c57-ac12-ef28f6b54338&mallId=12750&startDate=2025-06-10&endDate=2025-06-16&level=rt",
// "http://192.168.1.20:3000/apph5/demo",
"https://store.keliuyun.com/apph5/heatMap?token=6c094ce1-0eb7-4c57-ac12-ef28f6b54338&mallId=12750&startDate=2025-06-10&endDate=2025-06-16&level=rt",
"demo-webview",
{
top: `${top+100}px`, // 关键:从导航栏下方开始
bottom: "0px",
left: "0px",
right: "0px",
'uni-app': 'none',
popGesture:'close',
// backButtonAutoControl:'close',
hardwareAccelerated: true,
wkwebview: true,
}
)
webview.show()
const webs = plus.webview.getWebviewById('demo-webview')
console.log('=====');
console.log(webs);
// 添加事件监听
webview.addEventListener("loaded", () => {
console.log("网页加载完成")
})
}
const closeWebview = ()=>{
if(webview){
// 正确关闭方式
webview.hide()
webview.close()
webview = null
}
}
</script>