sadais-piui 1.2.7-beta76 → 1.2.7-beta77
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/pi-webview/index.vue +92 -88
- package/package.json +1 -1
|
@@ -1,88 +1,92 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<view class="pi-scroll-container">
|
|
3
|
-
<!-- #ifndef MP -->
|
|
4
|
-
<slot name="title">
|
|
5
|
-
<pi-navbar :show-home="
|
|
6
|
-
</slot>
|
|
7
|
-
<!-- #endif -->
|
|
8
|
-
<!-- #ifndef APP-PLUS -->
|
|
9
|
-
<web-view v-if="webviewURL" :progress="true" :src="webviewURL" class="pi-scroll pi-safearea" />
|
|
10
|
-
<!-- #endif -->
|
|
11
|
-
</view>
|
|
12
|
-
</template>
|
|
13
|
-
|
|
14
|
-
<script>
|
|
15
|
-
const TAG = 'PiWebview'
|
|
16
|
-
export default {
|
|
17
|
-
name: 'PiWebview',
|
|
18
|
-
props: {
|
|
19
|
-
title: {
|
|
20
|
-
type: String
|
|
21
|
-
},
|
|
22
|
-
|
|
23
|
-
type:
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
1
|
+
<template>
|
|
2
|
+
<view class="pi-scroll-container">
|
|
3
|
+
<!-- #ifndef MP -->
|
|
4
|
+
<slot name="title">
|
|
5
|
+
<pi-navbar :show-home="showHome">{{ title }}</pi-navbar>
|
|
6
|
+
</slot>
|
|
7
|
+
<!-- #endif -->
|
|
8
|
+
<!-- #ifndef APP-PLUS -->
|
|
9
|
+
<web-view v-if="webviewURL" :progress="true" :src="webviewURL" class="pi-scroll pi-safearea" />
|
|
10
|
+
<!-- #endif -->
|
|
11
|
+
</view>
|
|
12
|
+
</template>
|
|
13
|
+
|
|
14
|
+
<script>
|
|
15
|
+
const TAG = 'PiWebview'
|
|
16
|
+
export default {
|
|
17
|
+
name: 'PiWebview',
|
|
18
|
+
props: {
|
|
19
|
+
title: {
|
|
20
|
+
type: String
|
|
21
|
+
},
|
|
22
|
+
showHome: {
|
|
23
|
+
type: Boolean,
|
|
24
|
+
default: () => false
|
|
25
|
+
},
|
|
26
|
+
url: {
|
|
27
|
+
type: String
|
|
28
|
+
},
|
|
29
|
+
autoAddTimestamp: {
|
|
30
|
+
type: Boolean,
|
|
31
|
+
default: () => true
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
data() {
|
|
35
|
+
return {
|
|
36
|
+
webviewURL: ''
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
watch: {
|
|
40
|
+
url: {
|
|
41
|
+
deep: true,
|
|
42
|
+
immediate: true,
|
|
43
|
+
handler(value) {
|
|
44
|
+
value && this.init()
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
methods: {
|
|
49
|
+
init() {
|
|
50
|
+
// 设置标题
|
|
51
|
+
if (this.title) {
|
|
52
|
+
uni.setNavigationBarTitle({
|
|
53
|
+
title: this.title
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
if (!this.url) return
|
|
57
|
+
// H5 url 需要加时间戳,否则会有缓存问题
|
|
58
|
+
this.webviewURL = this.autoAddTimestamp
|
|
59
|
+
? this.urlAddParam(this.url || '', {
|
|
60
|
+
sadaisTimestamp: new Date().getTime() + '-' + Math.round(Math.random(1) * 10000)
|
|
61
|
+
})
|
|
62
|
+
: this.url
|
|
63
|
+
console.log('webview页面即将打开以下URL:', this.webviewURL)
|
|
64
|
+
// #ifdef APP-PLUS
|
|
65
|
+
const wv = plus.webview.create('', 'custom-webview', {
|
|
66
|
+
'plusrequire': 'none', // 禁止远程网页使用plus的API,有些使用mui制作的网页可能会监听plus.key,造成关闭页面混乱,可以通过这种方式禁止
|
|
67
|
+
'uni-app': 'none', // 不加载uni-app渲染层框架,避免样式冲突
|
|
68
|
+
'top': uni.getSystemInfoSync().statusBarHeight + 44 // 放置在titleNView下方。如果还想在webview上方加个地址栏的什么的,可以继续降低TOP值
|
|
69
|
+
})
|
|
70
|
+
wv.loadURL(this.webviewURL)
|
|
71
|
+
const currentWebview = this.$mp.page.$getAppWebview() // 获取当前页面的webview对象
|
|
72
|
+
currentWebview.append(wv) // 一定要append到当前的页面里,才能跟随当前页面一起做动画,一起关闭
|
|
73
|
+
// #endif
|
|
74
|
+
},
|
|
75
|
+
urlAddParam(url, params) {
|
|
76
|
+
params = this.$pi.navi.objToUrl(params)
|
|
77
|
+
if (url.indexOf('?') !== -1 && params) {
|
|
78
|
+
url = url + params.replace('?', '&')
|
|
79
|
+
} else {
|
|
80
|
+
url = url + params
|
|
81
|
+
}
|
|
82
|
+
return url
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
</script>
|
|
87
|
+
|
|
88
|
+
<style lang="scss" scoped>
|
|
89
|
+
.pi-scroll-container {
|
|
90
|
+
background-color: #ffffff;
|
|
91
|
+
}
|
|
92
|
+
</style>
|