-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e94186
commit bb40e63
Showing
2 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<template> | ||
<view class="pi-scroll-container"> | ||
<!-- #ifndef MP --> | ||
<pi-navbar :show-home="false">{{ title }}</pi-navbar> | ||
<!-- #endif --> | ||
<!-- #ifndef APP-PLUS --> | ||
<web-view :progress="true" :src="webviewURL" class="pi-scroll pi-safearea" /> | ||
<!-- #endif --> | ||
</view> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
name: 'PiWebview', | ||
props: { | ||
title: { | ||
type: String | ||
}, | ||
url: { | ||
type: String | ||
} | ||
}, | ||
data() { | ||
return { | ||
webviewURL: '' | ||
} | ||
}, | ||
created() { | ||
this.init() | ||
}, | ||
methods: { | ||
init() { | ||
// 设置标题 | ||
uni.setNavigationBarTitle({ | ||
title: this.title | ||
}) | ||
if (!this.url) { | ||
return this.$toast('打开页面URL为空,请检查') | ||
} | ||
// H5 url 需要加时间戳,否则会有缓存问题 | ||
this.webviewURL = this.urlAddParam(this.url || '', { | ||
sadaisTimestamp: new Date().getTime() + '-' + Math.round(Math.random(1) * 10000) | ||
}) | ||
console.log('webview页面即将打开以下URL:', this.webviewURL) | ||
// #ifdef APP-PLUS | ||
const wv = plus.webview.create('', 'custom-webview', { | ||
'plusrequire': 'none', // 禁止远程网页使用plus的API,有些使用mui制作的网页可能会监听plus.key,造成关闭页面混乱,可以通过这种方式禁止 | ||
'uni-app': 'none', // 不加载uni-app渲染层框架,避免样式冲突 | ||
'top': uni.getSystemInfoSync().statusBarHeight + 44 // 放置在titleNView下方。如果还想在webview上方加个地址栏的什么的,可以继续降低TOP值 | ||
}) | ||
wv.loadURL(this.webviewURL) | ||
const currentWebview = this.$mp.page.$getAppWebview() // 获取当前页面的webview对象 | ||
currentWebview.append(wv) // 一定要append到当前的页面里,才能跟随当前页面一起做动画,一起关闭 | ||
// #endif | ||
}, | ||
urlAddParam(url, params) { | ||
params = this.$pi.navi.objToUrl(params) | ||
if (url.indexOf('?') !== -1 && params) { | ||
url = url + params.replace('?', '&') | ||
} else { | ||
url = url + params | ||
} | ||
return url | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.pi-scroll-container { | ||
background-color: #ffffff; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters