调整架构 添加base 基础工具模块
This commit is contained in:
		| @@ -6,7 +6,8 @@ | ||||
|   "author": "", | ||||
|   "license": "", | ||||
|   "dependencies": { | ||||
|     "@devwiki/common_ui": "file:../common_ui" | ||||
|     "@devwiki/common_ui": "file:../common_ui", | ||||
|     "@devwiki/base": "file:../base" | ||||
|   } | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -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() { | ||||
|   | ||||
| @@ -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() }); | ||||
|  | ||||
|           Button("Layout").width(100).height('100%').type(ButtonType.Normal).onClick(() =>{ | ||||
|             router.pushUrl({url: "pages/layout/LinearLayoutPage"}); | ||||
|             .onClick(async () => { | ||||
|               this.dialogController.open() | ||||
|             }); | ||||
|  | ||||
|           Button("Animation").width(100).height('100%').type(ButtonType.Normal).onClick(() =>{ | ||||
|             router.pushUrl({url: "pages/animation/CompTransitionPage"}); | ||||
|           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" }); | ||||
|           }); | ||||
|  | ||||
|         }.width('100%').height(48).justifyContent(FlexAlign.SpaceEvenly) | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -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'; | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| import { ScreenUtil } from '@devwiki/common_ui/Index'; | ||||
| import { ScreenUtil } from '@devwiki/base'; | ||||
| import { WebPage } from './WebPage'; | ||||
|  | ||||
| @CustomDialog | ||||
|   | ||||
							
								
								
									
										6
									
								
								base/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								base/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | ||||
| /node_modules | ||||
| /oh_modules | ||||
| /.preview | ||||
| /build | ||||
| /.cxx | ||||
| /.test | ||||
							
								
								
									
										8
									
								
								base/Index.ets
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								base/Index.ets
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | ||||
| export { Log } from "./src/main/ets/utils/Log" | ||||
|  | ||||
| export { ScreenUtil } from './src/main/ets/utils/ScreenUtil' | ||||
|  | ||||
| export { BaseLocalStorage, BaseLocalStorageKey } from './src/main/ets/utils/BaseLocalStorage' | ||||
|  | ||||
| export { Emitter, EmitterItem } from './src/main/ets/event/Emitter' | ||||
| export { WebViewEventKey } from './src/main/ets/event/EventKey' | ||||
							
								
								
									
										25
									
								
								base/build-profile.json5
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								base/build-profile.json5
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,25 @@ | ||||
| { | ||||
|   "apiType": "stageMode", | ||||
|   "buildOption": { | ||||
|   }, | ||||
|   "buildOptionSet": [ | ||||
|     { | ||||
|       "name": "release", | ||||
|       "arkOptions": { | ||||
|         "obfuscation": { | ||||
|           "ruleOptions": { | ||||
|             "enable": true, | ||||
|             "files": [ | ||||
|               "./obfuscation-rules.txt" | ||||
|             ] | ||||
|           } | ||||
|         } | ||||
|       }, | ||||
|     }, | ||||
|   ], | ||||
|   "targets": [ | ||||
|     { | ||||
|       "name": "default" | ||||
|     } | ||||
|   ] | ||||
| } | ||||
							
								
								
									
										6
									
								
								base/hvigorfile.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								base/hvigorfile.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | ||||
| import { hspTasks } from '@ohos/hvigor-ohos-plugin'; | ||||
|  | ||||
| export default { | ||||
|     system: hspTasks,  /* Built-in plugin of Hvigor. It cannot be modified. */ | ||||
|     plugins:[]         /* Custom plugin to extend the functionality of Hvigor. */ | ||||
| } | ||||
							
								
								
									
										18
									
								
								base/obfuscation-rules.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								base/obfuscation-rules.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,18 @@ | ||||
| # Define project specific obfuscation rules here. | ||||
| # You can include the obfuscation configuration files in the current module's build-profile.json5. | ||||
| # | ||||
| # For more details, see | ||||
| #   https://gitee.com/openharmony/arkcompiler_ets_frontend/blob/master/arkguard/README.md | ||||
|  | ||||
| # Obfuscation options: | ||||
| # -disable-obfuscation: disable all obfuscations | ||||
| # -enable-property-obfuscation: obfuscate the property names | ||||
| # -enable-toplevel-obfuscation: obfuscate the names in the global scope | ||||
| # -compact: remove unnecessary blank spaces and all line feeds | ||||
| # -remove-log: remove all console.* statements | ||||
| # -print-namecache: print the name cache that contains the mapping from the old names to new names | ||||
| # -apply-namecache: reuse the given cache file | ||||
|  | ||||
| # Keep options: | ||||
| # -keep-property-name: specifies property names that you want to keep | ||||
| # -keep-global-name: specifies names that you want to keep in the global scope | ||||
							
								
								
									
										11
									
								
								base/oh-package.json5
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								base/oh-package.json5
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| { | ||||
|   "name": "base", | ||||
|   "version": "1.0.0", | ||||
|   "description": "Please describe the basic information.", | ||||
|   "main": "Index.ets", | ||||
|   "author": "", | ||||
|   "license": "Apache-2.0", | ||||
|   "packageType": "InterfaceHar", | ||||
|   "dependencies": { | ||||
|   } | ||||
| } | ||||
| @@ -4,12 +4,12 @@ export interface EmitterItem { | ||||
|   listener: Function | ||||
| } | ||||
| 
 | ||||
| type XYEmitterAllType = string | object | boolean | number | Object | Number | BigInt; | ||||
| type EmitterAllType = string | object | boolean | number | Object | Number | BigInt; | ||||
| 
 | ||||
| export class Emitter { | ||||
|   private static instance: Emitter; | ||||
|   private static events: Map<string, EmitterItem[]> = new Map | ||||
|   private static viscosityData: Map<string, XYEmitterAllType[]> = new Map | ||||
|   private static viscosityData: Map<string, EmitterAllType[]> = new Map | ||||
| 
 | ||||
|   public static getInstance(): Emitter { | ||||
|     if (!Emitter.instance) { | ||||
| @@ -87,7 +87,7 @@ export class Emitter { | ||||
|    */ | ||||
|   public emmitViscosity<T>(key: string, ...args: T[]) { | ||||
|     this.emmit(key, ...args); | ||||
|     Emitter.viscosityData.set(key, args as XYEmitterAllType[]); | ||||
|     Emitter.viscosityData.set(key, args as EmitterAllType[]); | ||||
|   } | ||||
| 
 | ||||
|   /** | ||||
							
								
								
									
										17
									
								
								base/src/main/ets/pages/Index.ets
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								base/src/main/ets/pages/Index.ets
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | ||||
| @Entry | ||||
| @Component | ||||
| struct Index { | ||||
|   @State message: string = 'Hello World'; | ||||
|  | ||||
|   build() { | ||||
|     Row() { | ||||
|       Column() { | ||||
|         Text(this.message) | ||||
|           .fontSize(50) | ||||
|           .fontWeight(FontWeight.Bold) | ||||
|       } | ||||
|       .width('100%') | ||||
|     } | ||||
|     .height('100%') | ||||
|   } | ||||
| } | ||||
| @@ -3,24 +3,24 @@ import { Context } from '@kit.AbilityKit'; | ||||
| import dataPreferences from '@ohos.data.preferences'; | ||||
| import { Log } from './Log'; | ||||
| 
 | ||||
| export class DemoLocalStorageKey { | ||||
| export class BaseLocalStorageKey { | ||||
|   static readonly KEY_SERVER_CONFIG = "key_config"; | ||||
| } | ||||
| 
 | ||||
| export class DemoLocalStorage { | ||||
| export class BaseLocalStorage { | ||||
| 
 | ||||
|   private static instance: DemoLocalStorage; | ||||
|   private static instance: BaseLocalStorage; | ||||
|   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; | ||||
|   static getInstance(): BaseLocalStorage { | ||||
|     if (!BaseLocalStorage.instance) { | ||||
|       if (!BaseLocalStorage.lock) { | ||||
|         BaseLocalStorage.lock = true; | ||||
|         BaseLocalStorage.instance = new BaseLocalStorage(); | ||||
|         BaseLocalStorage.lock = false; | ||||
|       } | ||||
|     } | ||||
|     return DemoLocalStorage.instance; | ||||
|     return BaseLocalStorage.instance; | ||||
|   } | ||||
| 
 | ||||
|   private context: Context | null = null; | ||||
| @@ -31,7 +31,7 @@ export class DemoLocalStorage { | ||||
|   public init(context: Context): void { | ||||
|     if (!this.context) { | ||||
|       this.context = context.getApplicationContext(); | ||||
|       let options: dataPreferences.Options = { name: DemoLocalStorage.XY_DP_Name }; | ||||
|       let options: dataPreferences.Options = { name: BaseLocalStorage.XY_DP_Name }; | ||||
|       this.preferences = dataPreferences.getPreferencesSync(this.context, options); | ||||
|     } else { | ||||
|       Log.i("LocalStorage is already init.") | ||||
| @@ -1,5 +1,6 @@ | ||||
| import window from '@ohos.window'; | ||||
| import mediaquery from '@ohos.mediaquery'; | ||||
| import { Log } from './Log'; | ||||
| 
 | ||||
| export class ScreenUtil { | ||||
|   // TODO: 工具待抽离, key统一定义 | ||||
| @@ -103,4 +104,12 @@ export class ScreenUtil { | ||||
|       .catch((error: Error) => { | ||||
|       }) | ||||
|   } | ||||
| 
 | ||||
|   setWindowKeepScreenOn(isKeep: boolean) { | ||||
|     Log.i(`setWindowKeepScreenOn:${isKeep}`) | ||||
|     window.getLastWindow(getContext(this)) | ||||
|       .then((windowClass: window.Window) => { | ||||
|         windowClass.setWindowKeepScreenOn(isKeep); | ||||
|       }); | ||||
|   } | ||||
| } | ||||
							
								
								
									
										14
									
								
								base/src/main/module.json5
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								base/src/main/module.json5
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,14 @@ | ||||
| { | ||||
|   "module": { | ||||
|     "name": "base", | ||||
|     "type": "shared", | ||||
|     "description": "$string:shared_desc", | ||||
|     "deviceTypes": [ | ||||
|       "phone", | ||||
|       "tablet", | ||||
|       "2in1" | ||||
|     ], | ||||
|     "deliveryWithInstall": true, | ||||
|     "pages": "$profile:main_pages" | ||||
|   } | ||||
| } | ||||
							
								
								
									
										8
									
								
								base/src/main/resources/base/element/color.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								base/src/main/resources/base/element/color.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | ||||
| { | ||||
|   "color": [ | ||||
|     { | ||||
|       "name": "white", | ||||
|       "value": "#FFFFFF" | ||||
|     } | ||||
|   ] | ||||
| } | ||||
							
								
								
									
										8
									
								
								base/src/main/resources/base/element/string.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								base/src/main/resources/base/element/string.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | ||||
| { | ||||
|   "string": [ | ||||
|     { | ||||
|       "name": "shared_desc", | ||||
|       "value": "description" | ||||
|     } | ||||
|   ] | ||||
| } | ||||
							
								
								
									
										5
									
								
								base/src/main/resources/base/profile/main_pages.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								base/src/main/resources/base/profile/main_pages.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,5 @@ | ||||
| { | ||||
|   "src": [ | ||||
|     "pages/Index" | ||||
|   ] | ||||
| } | ||||
							
								
								
									
										5
									
								
								base/src/test/List.test.ets
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								base/src/test/List.test.ets
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,5 @@ | ||||
| import localUnitTest from './LocalUnit.test'; | ||||
|  | ||||
| export default function testsuite() { | ||||
|   localUnitTest(); | ||||
| } | ||||
							
								
								
									
										33
									
								
								base/src/test/LocalUnit.test.ets
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								base/src/test/LocalUnit.test.ets
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,33 @@ | ||||
| import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; | ||||
|  | ||||
| export default function localUnitTest() { | ||||
|   describe('localUnitTest',() => { | ||||
|     // Defines a test suite. Two parameters are supported: test suite name and test suite function. | ||||
|     beforeAll(() => { | ||||
|       // Presets an action, which is performed only once before all test cases of the test suite start. | ||||
|       // This API supports only one parameter: preset action function. | ||||
|     }); | ||||
|     beforeEach(() => { | ||||
|       // Presets an action, which is performed before each unit test case starts. | ||||
|       // The number of execution times is the same as the number of test cases defined by **it**. | ||||
|       // This API supports only one parameter: preset action function. | ||||
|     }); | ||||
|     afterEach(() => { | ||||
|       // Presets a clear action, which is performed after each unit test case ends. | ||||
|       // The number of execution times is the same as the number of test cases defined by **it**. | ||||
|       // This API supports only one parameter: clear action function. | ||||
|     }); | ||||
|     afterAll(() => { | ||||
|       // Presets a clear action, which is performed after all test cases of the test suite end. | ||||
|       // This API supports only one parameter: clear action function. | ||||
|     }); | ||||
|     it('assertContain', 0, () => { | ||||
|       // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. | ||||
|       let a = 'abc'; | ||||
|       let b = 'b'; | ||||
|       // Defines a variety of assertion methods, which are used to declare expected boolean conditions. | ||||
|       expect(a).assertContain(b); | ||||
|       expect(a).assertEqual(a); | ||||
|     }); | ||||
|   }); | ||||
| } | ||||
| @@ -67,6 +67,18 @@ | ||||
|           ] | ||||
|         } | ||||
|       ] | ||||
|     }, | ||||
|     { | ||||
|       "name": "base", | ||||
|       "srcPath": "./base", | ||||
|       "targets": [ | ||||
|         { | ||||
|           "name": "default", | ||||
|           "applyToProducts": [ | ||||
|             "default" | ||||
|           ] | ||||
|         } | ||||
|       ] | ||||
|     } | ||||
|   ] | ||||
| } | ||||
| @@ -1,8 +1,5 @@ | ||||
| export { TitleBar, TitleBarMenuType } from './src/main/ets/component/TitleBar' | ||||
| export { ComponentConst } from './src/main/ets/component/ComponentConst' | ||||
| export { WebViewEventKey } from './src/main/ets/event/EventKey' | ||||
| export { Emitter } from './src/main/ets/event/Emitter' | ||||
| export { WebViewEventKey } from '../base/src/main/ets/event/EventKey' | ||||
| export { WebView, WebViewController, WebViewParam } from './src/main/ets/component/web/WebView' | ||||
|  | ||||
| export { CommonRes, CommonMediaName } from './src/main/ets/utils/CommonRes' | ||||
| export { ScreenUtil } from './src/main/ets/utils/ScreenUtil' | ||||
|   | ||||
| @@ -7,5 +7,6 @@ | ||||
|   "license": "Apache-2.0", | ||||
|   "packageType": "InterfaceHar", | ||||
|   "dependencies": { | ||||
|     "@devwiki/base": "file:../base" | ||||
|   } | ||||
| } | ||||
| @@ -3,6 +3,7 @@ | ||||
| 本项目模块分为: | ||||
| - app: 主入口模块 | ||||
| - common_ui : 通用UI动态共享库模块 | ||||
| - base: 最底层的依赖库, 包含最通用的代码封装. | ||||
|  | ||||
|  | ||||
| ## app模块 | ||||
| @@ -19,8 +20,8 @@ | ||||
| - 自定标题栏: [TitleBar](common_ui/src/main/ets/component/TitleBar.ets) | ||||
|  | ||||
| 事件相关: | ||||
| - 事件发射器 [Emitter](common_ui/src/main/ets/event/Emitter.ets) | ||||
| - 事件发射器 [Emitter](base/src/main/ets/event/Emitter.ets) | ||||
|  | ||||
| 工具类: | ||||
| - 公用资源调用类[CommonRes](common_ui/src/main/ets/utils/CommonRes.ets) | ||||
| - 屏幕相关[ScreenUtil](common_ui/src/main/ets/utils/ScreenUtil.ets) | ||||
| - 屏幕相关[ScreenUtil](base/src/main/ets/utils/ScreenUtil.ets) | ||||
		Reference in New Issue
	
	Block a user