修改调用

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

View File

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