74 lines
1.7 KiB
Vue
74 lines
1.7 KiB
Vue
<template>
|
|
<view id="test">
|
|
<!-- #ifdef H5 -->
|
|
<web-view :src="url"></web-view>
|
|
<!-- #endif -->
|
|
</view>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { ref,getCurrentInstance } from 'vue';
|
|
import { onLoad,onBackPress } from '@dcloudio/uni-app';
|
|
|
|
let url = ref('');
|
|
let title = ref('');
|
|
onLoad(async(opt) => {
|
|
// console.log(opt)
|
|
url.value = opt.url ;
|
|
title.value = opt.title;
|
|
// #ifdef APP-PLUS
|
|
titleNViewWebview(url.value,title.value);
|
|
// #endif
|
|
})
|
|
|
|
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("加载中...",{
|
|
width:'110px',
|
|
padding:'10px'
|
|
})
|
|
|
|
webview = plus.webview.create(url, 'test', {
|
|
titleNView: {
|
|
backgroundColor: '#307AF5',
|
|
titleText: title,
|
|
titleColor: '#ffffff',
|
|
autoBackButton: true,
|
|
backgroundImage:'./../../static/images/bg-Blue-header.png',
|
|
}
|
|
});
|
|
|
|
webview.addEventListener('loaded', function() {
|
|
nwating.close();
|
|
webview.show();
|
|
}, false);
|
|
|
|
webview.addEventListener('close', function(){
|
|
console.log("close=>")
|
|
webview=null;
|
|
uni.navigateBack();
|
|
});
|
|
}
|
|
|
|
</script>
|
|
|
|
<style scoped>
|
|
|
|
</style> |