修改webview

This commit is contained in:
xuli3099
2025-08-20 13:52:43 +08:00
parent 876b9b1c06
commit 558b56420b

View File

@@ -1,6 +1,6 @@
<template>
<view id="test">
<!-- #ifdef h5 -->
<!-- #ifdef H5 -->
<web-view :src="url"></web-view>
<!-- #endif -->
</view>
@@ -9,31 +9,45 @@
<script setup>
import { ref,onMounted,getCurrentInstance } from 'vue';
import { onLoad,onReady,onBackPress } from '@dcloudio/uni-app';
const { proxy } = getCurrentInstance();
import { showAlert } from '@/utils/message.js'
const { proxy } = getCurrentInstance();
let windowInfo = ref(null);
let url = ref('');
let title = ref('');
onLoad(async(opt) => {
console.log(opt)
// console.log(opt)
url.value = opt.url ;
title.value = opt.title;
// #ifdef APP-PLUS
titleNViewWebview(url.value,title.value);
// #endif
// uni.getSystemInfo({
// success: (res)=> {
// windowInfo.value = res;
// createWvAndLoadUrl(url.value,title.value);
// }
// });
})
onBackPress((e)=> {//响应返回事件
console.log("onBackPress=>",e)
if (e.from === 'navigateBack') { //这个地方必须要有的,否则会死循环
return false;
}
console.log('点击返回....');
let pages = getCurrentPages()
let page = pages[pages.length - 1];
let currentPages = page.$getAppWebview()
currentPages.close()
uni.navigateBack({delta:2})
return true;
})
// 带标题栏控件的Webview窗口
let webview = null;
function titleNViewWebview(url,title) {
console.log("titleNViewWebview=>",url,title)
let nwating = plus.nativeUI.showWaiting("loading...",{
width:'110px',
padding:'10px'
})
webview = plus.webview.create(url, 'test', {
titleNView: {
backgroundColor: '#307AF5',
@@ -41,32 +55,21 @@ function titleNViewWebview(url,title) {
titleColor: '#ffffff',
autoBackButton: true,
backgroundImage:'./../../static/images/bg-Blue-header.png',
buttons:[{onclick:clickButton}]
}
});
webview.addEventListener('close', function(){
webview=null;
});
webview.addEventListener('titleUpdate', function(){
webview.addEventListener('loaded', function() {
nwating.close();
webview.show();
}, false);
webview.addEventListener('close', function(){
console.log("close=>")
webview=null;
uni.navigateBack();
});
webview.addEventListener('loading', () => {
plus.nativeUI.showWaiting("loading...",{
width:'110px',
padding:'10px'
})
}, false);
//plus.nativeUI.showWaiting()
webview.addEventListener('loaded', () => {
plus.nativeUI.closeWaiting();
}, false);
}
// 左侧按钮返回
function clickButton(){
// plus.nativeUI.alert('clicked!');
webview=null;
}
</script>
<style scoped>