From b41b8ac20a0a15ac5acdff5af8bbfb3b2c3bc4d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E5=8B=A4=E6=B0=91?= Date: Tue, 22 Oct 2024 12:00:04 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E7=AD=BE=E7=9B=B8=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/ets/pages/XWebview.ets | 7 ++++++ src/main/ets/utils/SZYXLocalStorageKeys.ts | 1 + src/main/ets/utils/ToolsHelper.ets | 2 +- src/main/ets/utils/XWebHelper.ets | 25 ++++++++++++---------- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/main/ets/pages/XWebview.ets b/src/main/ets/pages/XWebview.ets index 4be23b5..a97dc5e 100644 --- a/src/main/ets/pages/XWebview.ets +++ b/src/main/ets/pages/XWebview.ets @@ -7,6 +7,8 @@ import { BusinessError } from '@kit.BasicServicesKit'; import { ToolsHelper } from '../utils/ToolsHelper'; import { XWebParams } from '../utils/XWebHelper'; import { WindowHelper } from '../utils/WindowHelper'; +import { SZYXLocalStorageHelper } from '../utils/SZYXLocalStorageHelper'; +import { SZYXLocalStorageKeys } from '../utils/SZYXLocalStorageKeys'; @Entry({ routeName: 'XWebview' }) @Preview @@ -15,6 +17,7 @@ export struct XWebview { // 手机号 @State url: string = (router.getParams() as XWebParams).url @State title?: string = (router.getParams() as XWebParams).title + @State closeTag?: string = (router.getParams() as XWebParams).closeTag @State showMenu: boolean = (router.getParams() as XWebParams).showMenu ?? false @State errorInfo: string | null = null @State progress: number = 0 @@ -22,9 +25,13 @@ export struct XWebview { dialogController: XDialogController = {} as XDialogController aboutToAppear(): void { + SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.XWebViewCLose, undefined) } aboutToDisappear(): void { + if (this.closeTag !== undefined) { + SZYXLocalStorageHelper.storage.setOrCreate(SZYXLocalStorageKeys.XWebViewCLose, this.closeTag) + } } onBackPress(): boolean | void { diff --git a/src/main/ets/utils/SZYXLocalStorageKeys.ts b/src/main/ets/utils/SZYXLocalStorageKeys.ts index 8bdae1e..4145f86 100644 --- a/src/main/ets/utils/SZYXLocalStorageKeys.ts +++ b/src/main/ets/utils/SZYXLocalStorageKeys.ts @@ -2,4 +2,5 @@ export class SZYXLocalStorageKeys{ public static HttpHandlerList: string = 'httpHandlerList'; public static HttpHandlerListLength: string = 'HttpHandlerListLength'; + public static XWebViewCLose: string = 'SZYX_XWebViewCLose'; } \ No newline at end of file diff --git a/src/main/ets/utils/ToolsHelper.ets b/src/main/ets/utils/ToolsHelper.ets index c262352..18b4c2b 100644 --- a/src/main/ets/utils/ToolsHelper.ets +++ b/src/main/ets/utils/ToolsHelper.ets @@ -37,7 +37,7 @@ interface ListItem { } @Builder -function customDialogBuilder(option: ListOptions, dialogTag: string) { +export function customDialogBuilder(option: ListOptions, dialogTag: string) { Column() { Text(option.title) diff --git a/src/main/ets/utils/XWebHelper.ets b/src/main/ets/utils/XWebHelper.ets index 29984df..1275411 100644 --- a/src/main/ets/utils/XWebHelper.ets +++ b/src/main/ets/utils/XWebHelper.ets @@ -9,6 +9,7 @@ export interface XWebParams { url: string title?: string showMenu?: boolean + closeTag?:string } export class XWebHelper { @@ -16,17 +17,19 @@ export class XWebHelper { * 打开web页面,加载h5 * @param params */ - public static openWeb(params: XWebParams) { - - router.pushNamedRoute({ - name: 'XWebview', - params: params - }, router.RouterMode.Single).then(() => { - console.info('Succeeded in jumping to the XWebview page.') - - }).catch((err: BusinessError) => { - console.error(`Failed to jump to the second page.Code is ${err.code}, message is ${err.message}`) - ToolsHelper.showMessage(`Failed to jump to the second page.Code is ${err.code}, message is ${err.message}`) + public static openWeb(params: XWebParams): Promise { + return new Promise((resolve) => { + router.pushNamedRoute({ + name: 'XWebview', + params: params + }, router.RouterMode.Single).then(() => { + console.info('Succeeded in jumping to the XWebview page.') + resolve(true) + }).catch((err: BusinessError) => { + resolve(false) + console.error(`Failed to jump to the second page.Code is ${err.code}, message is ${err.message}`) + ToolsHelper.showMessage(`Failed to jump to the second page.Code is ${err.code}, message is ${err.message}`) + }) }) } } \ No newline at end of file