调整架构 添加base 基础工具模块

This commit is contained in:
2024-04-18 18:44:19 +08:00
parent e3873432bc
commit ec474c43d9
29 changed files with 225 additions and 41 deletions

View File

@@ -1,7 +1,6 @@
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { window } from '@kit.ArkUI';
import { ScreenUtil } from '@devwiki/common_ui/Index';
export default class AppAbility extends UIAbility {
constructor() {

View File

@@ -1,20 +1,18 @@
import { ComponentConst, ScreenUtil, TitleBar } from '@devwiki/common_ui';
import { TitleBar } from '@devwiki/common_ui';
import web_webview from '@ohos.web.webview';
import { TitleBarMenuType } from '@devwiki/common_ui';
import { WebPage } from './web/WebPage';
import { router, window } from '@kit.ArkUI';
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';
import { Log } from '@devwiki/base';
import { BaseLocalStorage, ScreenUtil } from '@devwiki/base';
@CustomDialog
struct WebViewDialog {
webUrl: string = "https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/password"
private webviewController: web_webview.WebviewController = new web_webview.WebviewController();
dialogController: CustomDialogController;
@StorageLink(ScreenUtil.isPortraitKey)isPortrait: boolean = true;
@StorageLink(ScreenUtil.isPortraitKey) isPortrait: boolean = true;
build() {
Row() {
@@ -29,9 +27,7 @@ struct WebViewDialog {
@Entry
@Component
struct Index {
@State title: string = "Home";
dialogController: CustomDialogController = new CustomDialogController({
builder: WebViewDialog(),
alignment: DialogAlignment.BottomEnd,
@@ -40,7 +36,7 @@ struct Index {
aboutToAppear(): void {
ScreenUtil.getInstance().initScreenSize();
DemoLocalStorage.getInstance().init(getContext(this).getApplicationContext());
BaseLocalStorage.getInstance().init(getContext(this));
}
onPageShow(): void {
@@ -97,21 +93,25 @@ struct Index {
Column() {
TitleBar({
title: this.title,
onLeftClicked: ()=> { this.onBackPress() },
onLeftClicked: () => {
this.onBackPress()
},
rightMenuType: TitleBarMenuType.None
}).width('100%')
Column() {
Row() {
Button("WebDialog").width(100).height('100%').type(ButtonType.Normal)
.onClick(() => { this.dialogController.open() });
.onClick(async () => {
this.dialogController.open()
});
Button("Layout").width(100).height('100%').type(ButtonType.Normal).onClick(() =>{
router.pushUrl({url: "pages/layout/LinearLayoutPage"});
Button("Layout").width(100).height('100%').type(ButtonType.Normal).onClick(() => {
router.pushUrl({ url: "pages/layout/LinearLayoutPage" });
});
Button("Animation").width(100).height('100%').type(ButtonType.Normal).onClick(() =>{
router.pushUrl({url: "pages/animation/CompTransitionPage"});
Button("Animation").width(100).height('100%').type(ButtonType.Normal).onClick(() => {
router.pushUrl({ url: "pages/animation/CompTransitionPage" });
});
}.width('100%').height(48).justifyContent(FlexAlign.SpaceEvenly)

View File

@@ -2,7 +2,6 @@ import { TitleBar } from '@devwiki/common_ui/Index';
import picker from '@ohos.file.picker';
import { BusinessError } from '@kit.BasicServicesKit';
import fs, { ReadOptions } from '@ohos.file.fs';
import common from '@ohos.app.ability.common';
import buffer from '@ohos.buffer';
@Entry

View File

@@ -1,4 +1,4 @@
import { CommonMediaName, CommonRes, TitleBar, TitleBarMenuType } from '@devwiki/common_ui/Index'
import { CommonRes, TitleBar, TitleBarMenuType } from '@devwiki/common_ui'
import { curves, router } from '@kit.ArkUI';

View File

@@ -1,4 +1,5 @@
import { WebView, WebViewParam, ComponentConst, CommonRes, TitleBar, WebViewController, ScreenUtil } from '@devwiki/common_ui/Index';
import { WebView, WebViewParam, ComponentConst, CommonRes, TitleBar, WebViewController } from '@devwiki/common_ui/Index';
import { ScreenUtil } from '@devwiki/base'
@Entry
@Component

View File

@@ -1,4 +1,4 @@
import { ScreenUtil } from '@devwiki/common_ui/Index';
import { ScreenUtil } from '@devwiki/base';
import { WebPage } from './WebPage';
@CustomDialog

View File

@@ -1,65 +0,0 @@
import { Context } from '@kit.AbilityKit';
import dataPreferences from '@ohos.data.preferences';
import { Log } from './Log';
export class DemoLocalStorageKey {
static readonly KEY_SERVER_CONFIG = "key_config";
}
export class DemoLocalStorage {
private static instance: DemoLocalStorage;
private static lock: boolean = false;
private static readonly XY_DP_Name = "LocalData";
static getInstance(): DemoLocalStorage {
if (!DemoLocalStorage.instance) {
if (!DemoLocalStorage.lock) {
DemoLocalStorage.lock = true;
DemoLocalStorage.instance = new DemoLocalStorage();
DemoLocalStorage.lock = false;
}
}
return DemoLocalStorage.instance;
}
private context: Context | null = null;
private preferences: dataPreferences.Preferences | null = null;
private constructor() {
}
public init(context: Context): void {
if (!this.context) {
this.context = context.getApplicationContext();
let options: dataPreferences.Options = { name: DemoLocalStorage.XY_DP_Name };
this.preferences = dataPreferences.getPreferencesSync(this.context, options);
} else {
Log.i("LocalStorage is already init.")
}
}
public putData(key: string, value: dataPreferences.ValueType) {
Log.i(`put sp data, key:${key}, value:${value}`)
this.preferences?.putSync(key, value);
this.preferences?.flush();
}
public clearData(key: string) {
this.preferences?.delete(key);
this.preferences?.flush();
}
public getData(key: string, defaultValue: dataPreferences.ValueType): dataPreferences.ValueType | undefined {
let value = this.preferences?.getSync(key, defaultValue);
Log.i(`get sp data, key:${key}, value:${value}`)
return value;
}
public getObject<T>(key: string): T {
let value = this.getData(key, "{}") as string;
if (value.toString().length > 0) {
return JSON.parse(value) as T;
}
return "{}" as T;
}
}

View File

@@ -1,33 +0,0 @@
import hilog from '@ohos.hilog';
let domain: number = 0xFF00;
let prefix: string = 'HM4Demo';
let format: string = `%{public}s, %{public}s`;
export class Log {
static d(...args: string[]) {
hilog.debug(domain, prefix, format, args);
}
static i(...args: string[]) {
hilog.info(domain, prefix, format, args);
}
static w(...args: string[]) {
hilog.warn(domain, prefix, format, args);
}
static e(...args: string[]) {
hilog.error(domain, prefix, format, args);
}
static f(...args: string[]) {
hilog.fatal(domain,prefix, format, args);
}
static isLoggable(level: number) {
hilog.isLoggable(domain, prefix, level);
}
}