From e7adec064c0d536f2f035d8b0d303a5c11e777bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E5=8B=A4=E6=B0=91?= Date: Wed, 21 May 2025 11:54:53 +0800 Subject: [PATCH] =?UTF-8?q?feat(app):=20=E6=B7=BB=E5=8A=A0=E5=85=B3?= =?UTF-8?q?=E9=97=AD=E7=AA=97=E5=8F=A3=E5=8A=9F=E8=83=BD=E5=B9=B6=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E7=BD=91=E9=A1=B5=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 JSSdkCls 中添加 closeWindows 方法,用于关闭窗口 - 在 types 中添加 'closeWindows' 作为 IAppModeName 的一个选项 - 在 XWebview 中添加 onClose事件监听,用于处理窗口关闭事件 - 在 XWebHelper 中添加 close 方法,用于触发窗口关闭- 在 XWebManager 中实现 close 和 onClose 方法,用于管理窗口关闭逻辑 --- src/main/ets/pages/XWebview.ets | 5 ++++- src/main/ets/utils/XWebHelper.ets | 3 +++ src/main/ets/utils/XWebManager.ets | 12 +++++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/ets/pages/XWebview.ets b/src/main/ets/pages/XWebview.ets index ec3fb73..37efbc1 100644 --- a/src/main/ets/pages/XWebview.ets +++ b/src/main/ets/pages/XWebview.ets @@ -12,7 +12,6 @@ import { SZYXLocalStorageHelper } from '../utils/SZYXLocalStorageHelper'; import { SZYXLocalStorageKeys } from '../utils/SZYXLocalStorageKeys'; import { XWebManager } from '../utils/XWebManager'; import { TitleBarBtn } from '../view/SafeView'; -import { HttpHelper } from '../http/HttpHelper'; @Entry({ routeName: 'XWebview' }) @Component @@ -46,6 +45,10 @@ export struct XWebview { } aboutToAppear(): void { + XWebManager.onClose(()=>{ + router.back() + }) + SZYXLocalStorageHelper.storage.setOrCreate('refresh_web_base', -1) SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.XWebViewCLose, undefined) webview.WebviewController.setWebDebuggingAccess(true); diff --git a/src/main/ets/utils/XWebHelper.ets b/src/main/ets/utils/XWebHelper.ets index 2521305..9a658c6 100644 --- a/src/main/ets/utils/XWebHelper.ets +++ b/src/main/ets/utils/XWebHelper.ets @@ -42,6 +42,9 @@ export interface XWebParams { } export class XWebHelper { + static close() { + XWebManager.close() + } private constructor() { } diff --git a/src/main/ets/utils/XWebManager.ets b/src/main/ets/utils/XWebManager.ets index a072086..9cde610 100644 --- a/src/main/ets/utils/XWebManager.ets +++ b/src/main/ets/utils/XWebManager.ets @@ -1,8 +1,18 @@ import { ToolsHelper } from './ToolsHelper'; export class XWebManager { + private static closeCall?: () => void; + + static onClose(call: () => void) { + XWebManager.closeCall = call + } + + static close() { + XWebManager.closeCall && XWebManager.closeCall() + } + private static MapEventListener = new Map void>(); - static objs:Map = new Map() + static objs: Map = new Map() static addOnMessage(listener: (msg: string) => void): string { const id = ToolsHelper.getUuid()