apt15e安装包
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
<template>
|
||||
<view>
|
||||
<web-view :src="url"></web-view>
|
||||
<web-view :src="url" @onPostMessage="onMessage" @error="onWebViewError"></web-view>
|
||||
<view v-if="loading" class="loading">页面加载中...</view>
|
||||
<view v-if="loadError" class="error">
|
||||
页面加载失败
|
||||
<button @tap="retryLoad">重新加载</button>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
@@ -8,21 +13,67 @@
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
url: ''
|
||||
url: '',
|
||||
originalUrl: 'http://192.168.100.201',
|
||||
loading: true,
|
||||
loadError: false
|
||||
};
|
||||
},
|
||||
onLoad (options) {
|
||||
const url = 'http://192.168.100.201'
|
||||
const timestamp = new Date().getTime()
|
||||
this.url = `${url}?timestamp=${timestamp}`
|
||||
uni.onNetworkStatusChange((res) => {
|
||||
if (res.isConnected) {
|
||||
this.url = `${url}?timestamp=${timestamp}`;
|
||||
}
|
||||
})
|
||||
onLoad(options) {
|
||||
this.initWebView()
|
||||
},
|
||||
onUnload () {
|
||||
methods: {
|
||||
initWebView() {
|
||||
this.loading = true
|
||||
this.loadError = false
|
||||
|
||||
const timestamp = new Date().getTime()
|
||||
this.url = `${this.originalUrl}?timestamp=${timestamp}`
|
||||
|
||||
// 设置超时检测
|
||||
setTimeout(() => {
|
||||
if (this.loading) {
|
||||
this.loading = false
|
||||
this.loadError = true
|
||||
}
|
||||
}, 10000) // 10秒超时
|
||||
|
||||
uni.onNetworkStatusChange((res) => {
|
||||
if (res.isConnected && this.loadError) {
|
||||
this.retryLoad()
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
onWebViewError(e) {
|
||||
console.error('WebView加载错误:', e)
|
||||
this.loading = false
|
||||
this.loadError = true
|
||||
},
|
||||
|
||||
onMessage(e) {
|
||||
// WebView内部发送的消息,可以用于确认页面加载完成
|
||||
this.loading = false
|
||||
this.loadError = false
|
||||
},
|
||||
|
||||
retryLoad() {
|
||||
this.initWebView()
|
||||
}
|
||||
},
|
||||
onUnload() {
|
||||
uni.offNetworkStatusChange()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.loading, .error {
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
text-align: center;
|
||||
z-index: 9999;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user