From 7619f280ebdc5fb05bb5b9810278172ed3d73324 Mon Sep 17 00:00:00 2001 From: yinjiacheng Date: Thu, 6 Jul 2023 16:00:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0web-view=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web-view-local/web-view-local.uvue | 34 +------- pages/component/web-view/web-view.uvue | 84 ++++++++----------- 2 files changed, 39 insertions(+), 79 deletions(-) diff --git a/pages/component/web-view-local/web-view-local.uvue b/pages/component/web-view-local/web-view-local.uvue index 341c720f..f046e14f 100644 --- a/pages/component/web-view-local/web-view-local.uvue +++ b/pages/component/web-view-local/web-view-local.uvue @@ -3,20 +3,6 @@ - - - - - - - - - - - - - - @@ -28,19 +14,7 @@ } }, methods: { - back() { - (this.$refs['web-view'] as IWebViewNode).back(); - }, - forward() { - (this.$refs['web-view'] as IWebViewNode).forward(); - }, - reload() { - (this.$refs['web-view'] as IWebViewNode).reload(); - }, - stop() { - (this.$refs['web-view'] as IWebViewNode).stop(); - }, - message(event: WebViewMessageEvent) { + message(event : WebViewMessageEvent) { console.log(JSON.stringify(event.detail)); const data = event.detail.data; if (data == null) return; @@ -78,13 +52,13 @@ break; } }, - error(event: WebViewErrorEvent) { + error(event : WebViewErrorEvent) { console.log(JSON.stringify(event.detail)); }, - loading(event: WebViewLoadingEvent) { + loading(event : WebViewLoadingEvent) { console.log(JSON.stringify(event.type)); }, - loaded(event: WebViewLoadedEvent) { + loaded(event : WebViewLoadedEvent) { console.log(JSON.stringify(event.type)); } } diff --git a/pages/component/web-view/web-view.uvue b/pages/component/web-view/web-view.uvue index 2564f4fb..19e8f17e 100644 --- a/pages/component/web-view/web-view.uvue +++ b/pages/component/web-view/web-view.uvue @@ -4,17 +4,24 @@ @error="error" @loading="loading" @loaded="loaded"> - - + + - - + + + + + + + - - - - - + + + + + + + @@ -24,7 +31,7 @@ export default { data() { return { - src: 'https://uniapp.dcloud.io/static/web-view.html', + src: 'https://www.baidu.com', webview_styles: { progress: { color: '#FF3333' @@ -45,57 +52,36 @@ stop() { (this.$refs['web-view'] as IWebViewNode).stop(); }, - message(event: WebViewMessageEvent) { + message(event : WebViewMessageEvent) { console.log(JSON.stringify(event.detail)); - const data = event.detail.data; - if (data == null) return; - switch (data['action']) { - case 'navigateTo': - uni.navigateTo({ - url: data['url'] as string - }); - break; - case 'redirectTo': - uni.redirectTo({ - url: data['url'] as string - }); - break; - case 'switchTab': - uni.switchTab({ - url: data['url'] as string - }); - break; - case 'reLaunch': - uni.reLaunch({ - url: data['url'] as string - }); - break; - case 'navigateBack': - uni.navigateBack({ - delta: data['delta'] as number - }); - break; - default: - uni.showModal({ - content: JSON.stringify(event.detail), - showCancel: false - }); - break; - } }, - error(event: WebViewErrorEvent) { + error(event : WebViewErrorEvent) { console.log(JSON.stringify(event.detail)); }, - loading(event: WebViewLoadingEvent) { + loading(event : WebViewLoadingEvent) { console.log(JSON.stringify(event.type)); }, - loaded(event: WebViewLoadedEvent) { + loaded(event : WebViewLoadedEvent) { console.log(JSON.stringify(event.type)); + }, + confirm(event : InputConfirmEvent) { + console.log(event.detail.value); + let url = event.detail.value; + if (!url.startsWith('https://') && !url.startsWith('http://')) { + url = 'https://' + url; + } + this.src = url; } } } \ No newline at end of file -- GitLab