diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index d1e94928ce215b5bbabf10a60d5419f637e341bd..f5df0db0bb83885c433e8e8e179804f2b5e3b077 100755 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -43,6 +43,8 @@ export default class EntryAbility extends UIAbility { } hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + let uiContext: UIContext | undefined = windowStage.getMainWindowSync().getUIContext() + AppStorage.setOrCreate('uiContext', uiContext); }); } diff --git a/entry/src/main/ets/pages/VuePage.ets b/entry/src/main/ets/pages/VuePage.ets index f109e6ff726883f93edb3b65b6bfcc968644c99d..b36894ec679316f56c93bbafe341da7091735340 100755 --- a/entry/src/main/ets/pages/VuePage.ets +++ b/entry/src/main/ets/pages/VuePage.ets @@ -16,11 +16,12 @@ import { webview } from '@kit.ArkWeb'; import { CommonConstant as Const } from '../common/Constant'; import { NavigatorBean } from '../viewmodel/NavigatorBean'; - +const uiContext: UIContext | undefined = AppStorage.get('uiContext'); +let context = uiContext!.getHostContext()!; class LinkClass { messageFromHtml(value: string) { - let res = getContext(this).resourceManager.getStringSync($r('app.string.congratulate').id); - AlertDialog.show({ + let res = context.resourceManager.getStringSync($r('app.string.congratulate').id); + uiContext!.showAlertDialog!({ message: res + value, confirm: { value: $r('app.string.web_alert_dialog_button_value'), diff --git a/entry/src/main/ets/pages/WebPage.ets b/entry/src/main/ets/pages/WebPage.ets index 8debb553dbc861a11c43c9bcb1571853b349fb25..5690db6b7ee822cb36681ccef923522268077c73 100755 --- a/entry/src/main/ets/pages/WebPage.ets +++ b/entry/src/main/ets/pages/WebPage.ets @@ -17,11 +17,12 @@ import { promptAction } from '@kit.ArkUI'; import { webview } from '@kit.ArkWeb'; import { CommonConstant as Const } from '../common/Constant'; import { NavigatorBean } from '../viewmodel/NavigatorBean'; - +const uiContext: UIContext | undefined = AppStorage.get('uiContext'); +let context = uiContext!.getHostContext()!; class LinkClass { messageFromHtml(value: string) { - let res = getContext(this).resourceManager.getStringSync($r('app.string.congratulate').id); - AlertDialog.show({ + let res = context.resourceManager.getStringSync($r('app.string.congratulate').id); + uiContext!.showAlertDialog({ message: res + value, confirm: { value: $r('app.string.web_alert_dialog_button_value'), @@ -92,13 +93,13 @@ export struct WebPage { }) .onErrorReceive((event) => { if (event?.error.getErrorInfo() === 'ERR_INTERNET_DISCONNECTED') { - promptAction.showToast({ + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.internet_err'), duration: Const.WEB_CONSTANT_DURATION }); } if (event?.error.getErrorInfo() === 'ERR_CONNECTION_TIMED_OUT') { - promptAction.showToast({ + this.getUIContext().getPromptAction().showToast({ message: $r('app.string.internet_err'), duration: Const.WEB_CONSTANT_DURATION });