From 653a923c7563c2c16986b3eec0808d564edbaf82 Mon Sep 17 00:00:00 2001 From: zhuzhengjun Date: Fri, 12 Jul 2024 11:21:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A4=9Awebview=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E7=99=BD=E5=B1=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhuzhengjun --- .../plugin/webview/in_app_webview/InAppWebView.ets | 7 +++++++ .../plugin/webview/in_app_webview/InAppWebViewClient.ets | 2 +- .../plugin/webview/in_app_webview/OhosWebView.ets | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/flutter_inappwebview_ohos/ohos/src/main/ets/components/plugin/webview/in_app_webview/InAppWebView.ets b/flutter_inappwebview_ohos/ohos/src/main/ets/components/plugin/webview/in_app_webview/InAppWebView.ets index 04a4d777..38401886 100644 --- a/flutter_inappwebview_ohos/ohos/src/main/ets/components/plugin/webview/in_app_webview/InAppWebView.ets +++ b/flutter_inappwebview_ohos/ohos/src/main/ets/components/plugin/webview/in_app_webview/InAppWebView.ets @@ -109,6 +109,7 @@ export default class InAppWebView implements InAppWebViewInterface { private pullToRefreshLayout: PullToRefreshLayout | null = null; private viewWidth = 0; private viewHeight= 0; + private curUrl: string | Resource = ""; constructor(context: Context, plugin: InAppWebViewFlutterPlugin, id: number, windowId: number | null | undefined, customSettings: InAppWebViewSettings, userScripts: Array, contextMenu?: Map) { @@ -256,6 +257,7 @@ export default class InAppWebView implements InAppWebViewInterface { } let realUrl = url.startsWith("resources/rawfile/") ? $rawfile(url.replace("resources/rawfile/", "")) : url; let headers = urlRequest.getHeaders(); + this.curUrl = realUrl; if (headers != null) { this.controller.loadUrl(realUrl, this.toWebHeaders(headers)); return; @@ -267,10 +269,15 @@ export default class InAppWebView implements InAppWebViewInterface { if (this.plugin == null) { return; } + this.curUrl = assetFilePath; await this.waitControllerAttached(); this.controller.loadUrl(assetFilePath) } + getLoadUrl(): string | Resource { + return this.curUrl + } + getLoading(): boolean { return this.isLoading } diff --git a/flutter_inappwebview_ohos/ohos/src/main/ets/components/plugin/webview/in_app_webview/InAppWebViewClient.ets b/flutter_inappwebview_ohos/ohos/src/main/ets/components/plugin/webview/in_app_webview/InAppWebViewClient.ets index 1129f339..71b2ba60 100644 --- a/flutter_inappwebview_ohos/ohos/src/main/ets/components/plugin/webview/in_app_webview/InAppWebViewClient.ets +++ b/flutter_inappwebview_ohos/ohos/src/main/ets/components/plugin/webview/in_app_webview/InAppWebViewClient.ets @@ -204,7 +204,7 @@ export default class InAppWebViewClient { } } onPageEnd = (event: Any) => { - Log.d(TAG, "onPageBegin=" + JSON.stringify(event)) + Log.d(TAG, "onPageEnd=" + JSON.stringify(event)) this.inAppWebView.isLoading = false; this.loadCustomJavaScriptOnPageFinished(this.inAppWebView); InAppWebViewClient.previousAuthRequestFailureCount = 0; diff --git a/flutter_inappwebview_ohos/ohos/src/main/ets/components/plugin/webview/in_app_webview/OhosWebView.ets b/flutter_inappwebview_ohos/ohos/src/main/ets/components/plugin/webview/in_app_webview/OhosWebView.ets index b7a47afe..449b13b1 100644 --- a/flutter_inappwebview_ohos/ohos/src/main/ets/components/plugin/webview/in_app_webview/OhosWebView.ets +++ b/flutter_inappwebview_ohos/ohos/src/main/ets/components/plugin/webview/in_app_webview/OhosWebView.ets @@ -78,7 +78,7 @@ export struct OhosWebView { buildWeb() { Web( { - src: "", + src: this.inAppWebView?.getLoadUrl(), controller: this.controller }) .onControllerAttached(this.inAppWebView!.onControllerAttached) -- Gitee