修改调用

This commit is contained in:
DevWiki 2024-04-18 11:45:36 +08:00
parent b543224480
commit e3873432bc
2 changed files with 13 additions and 11 deletions

View File

@ -7,6 +7,7 @@ import { WebPageDialog } from './web/WebPageDialog'
import promptAction from '@ohos.promptAction';
import { BusinessError } from '@ohos.base';
import { Log } from '../utils/Log';
import { DemoLocalStorage } from '../utils/LocalStorage';
@CustomDialog
struct WebViewDialog {
@ -39,6 +40,7 @@ struct Index {
aboutToAppear(): void {
ScreenUtil.getInstance().initScreenSize();
DemoLocalStorage.getInstance().init(getContext(this).getApplicationContext());
}
onPageShow(): void {

View File

@ -3,24 +3,24 @@ import { Context } from '@kit.AbilityKit';
import dataPreferences from '@ohos.data.preferences';
import { Log } from './Log';
export class LocalStorageKey {
export class DemoLocalStorageKey {
static readonly KEY_SERVER_CONFIG = "key_config";
}
export class LocalStorage {
export class DemoLocalStorage {
private static instance: LocalStorage;
private static instance: DemoLocalStorage;
private static lock: boolean = false;
private static readonly XY_DP_Name = "LocalData";
static getInstance(): LocalStorage {
if (!LocalStorage.instance) {
if (!LocalStorage.lock) {
LocalStorage.lock = true;
LocalStorage.instance = new LocalStorage();
LocalStorage.lock = false;
static getInstance(): DemoLocalStorage {
if (!DemoLocalStorage.instance) {
if (!DemoLocalStorage.lock) {
DemoLocalStorage.lock = true;
DemoLocalStorage.instance = new DemoLocalStorage();
DemoLocalStorage.lock = false;
}
}
return LocalStorage.instance;
return DemoLocalStorage.instance;
}
private context: Context | null = null;
@ -31,7 +31,7 @@ export class LocalStorage {
public init(context: Context): void {
if (!this.context) {
this.context = context.getApplicationContext();
let options: dataPreferences.Options = { name: LocalStorage.XY_DP_Name };
let options: dataPreferences.Options = { name: DemoLocalStorage.XY_DP_Name };
this.preferences = dataPreferences.getPreferencesSync(this.context, options);
} else {
Log.i("LocalStorage is already init.")