From d1e96a2e78c3a0abdecc3fe4288de9a1c89acdf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=B3=E4=B8=9C=E6=B5=B7?= Date: Tue, 6 May 2025 11:43:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E5=BA=9F=E5=BC=83?= =?UTF-8?q?=E7=9A=84API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/common/utils/CommonUtils.ets | 4 +++- entry/src/main/ets/common/utils/DBUtils.ets | 4 ++-- entry/src/main/ets/entryability/EntryAbility.ets | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/entry/src/main/ets/common/utils/CommonUtils.ets b/entry/src/main/ets/common/utils/CommonUtils.ets index f2a3cde..0a49b55 100644 --- a/entry/src/main/ets/common/utils/CommonUtils.ets +++ b/entry/src/main/ets/common/utils/CommonUtils.ets @@ -15,9 +15,11 @@ import { promptAction } from '@kit.ArkUI'; +const uiContext: UIContext | undefined = AppStorage.get('uiContext'); + export class CommonUtils { showToast(message: string | Resource) { - promptAction.showToast({ + uiContext?.getPromptAction().showToast({ message: message, duration: 1000 }); diff --git a/entry/src/main/ets/common/utils/DBUtils.ets b/entry/src/main/ets/common/utils/DBUtils.ets index a4892c0..121131b 100644 --- a/entry/src/main/ets/common/utils/DBUtils.ets +++ b/entry/src/main/ets/common/utils/DBUtils.ets @@ -20,7 +20,7 @@ import { CommonConstants } from '../constants/CommonConstants'; import Logger from './Logger'; let store: relationalStore.RdbStore | undefined = undefined; -let context = getContext(this); +const uiContext: UIContext | undefined = AppStorage.get('uiContext'); const STORE_CONFIG: relationalStore.StoreConfig = { name: "RdbTest.db", securityLevel: relationalStore.SecurityLevel.S1 @@ -37,7 +37,7 @@ export class DBUtils { * Creating a User Table. */ createDB() { - relationalStore.getRdbStore(context, STORE_CONFIG, (err: BusinessError, rdbStore: relationalStore.RdbStore) => { + relationalStore.getRdbStore(uiContext?.getHostContext(), STORE_CONFIG, (err: BusinessError, rdbStore: relationalStore.RdbStore) => { store = rdbStore; if (store !== undefined) { (store as relationalStore.RdbStore).executeSql(CommonConstants.SQL_CREATE_USER_TABLE, (err) => { diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 8bd1dd3..bfbb5e1 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -31,6 +31,7 @@ export default class EntryAbility extends UIAbility { hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); windowStage.loadContent('pages/Index', (err, data) => { + AppStorage.setOrCreate('uiContext', windowStage.getMainWindowSync().getUIContext()); if (err.code) { hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); return; -- Gitee