diff --git a/PackageStructureKit/LoginModule/BuildProfile.ets b/PackageStructureKit/LoginModule/BuildProfile.ets new file mode 100644 index 0000000000000000000000000000000000000000..3a501e5ddee8ea6d28961648fc7dd314a5304bd4 --- /dev/null +++ b/PackageStructureKit/LoginModule/BuildProfile.ets @@ -0,0 +1,17 @@ +/** + * Use these variables when you tailor your ArkTS code. They must be of the const type. + */ +export const HAR_VERSION = '1.0.0'; +export const BUILD_MODE_NAME = 'debug'; +export const DEBUG = true; +export const TARGET_NAME = 'default'; + +/** + * BuildProfile Class is used only for compatibility purposes. + */ +export default class BuildProfile { + static readonly HAR_VERSION = HAR_VERSION; + static readonly BUILD_MODE_NAME = BUILD_MODE_NAME; + static readonly DEBUG = DEBUG; + static readonly TARGET_NAME = TARGET_NAME; +} \ No newline at end of file diff --git a/PackageStructureKit/LoginModule/Index.ets b/PackageStructureKit/LoginModule/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..d3ddc9be0579abbaa05b80d1a4c47b8dace90b68 --- /dev/null +++ b/PackageStructureKit/LoginModule/Index.ets @@ -0,0 +1,2 @@ +export { MainPage } from './src/main/ets/components/MainPage'; +export { LoginPage } from './src/main/ets/components/LoginPage'; diff --git a/PackageStructureKit/LoginModule/build-profile.json5 b/PackageStructureKit/LoginModule/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e6773f9f5d76a66d6d19fddc9c6ddb3f5621d3b1 --- /dev/null +++ b/PackageStructureKit/LoginModule/build-profile.json5 @@ -0,0 +1,31 @@ +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + }, + "consumerFiles": [ + "./consumer-rules.txt" + ] + } + }, + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest" + } + ] +} diff --git a/PackageStructureKit/LoginModule/consumer-rules.txt b/PackageStructureKit/LoginModule/consumer-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/PackageStructureKit/LoginModule/hvigorfile.ts b/PackageStructureKit/LoginModule/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..42187071482d292588ad40babeda74f7b8d97a23 --- /dev/null +++ b/PackageStructureKit/LoginModule/hvigorfile.ts @@ -0,0 +1,6 @@ +import { harTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: harTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/PackageStructureKit/LoginModule/obfuscation-rules.txt b/PackageStructureKit/LoginModule/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/PackageStructureKit/LoginModule/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# 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://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# 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 + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/PackageStructureKit/LoginModule/oh-package.json5 b/PackageStructureKit/LoginModule/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f5cc20f81c395cae42ca9f931ff70c72c10f364b --- /dev/null +++ b/PackageStructureKit/LoginModule/oh-package.json5 @@ -0,0 +1,9 @@ +{ + "name": "@ohos/login", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "Index.ets", + "author": "", + "license": "Apache-2.0", + "dependencies": {} +} diff --git a/PackageStructureKit/LoginModule/src/main/ets/components/LoginPage.ets b/PackageStructureKit/LoginModule/src/main/ets/components/LoginPage.ets new file mode 100644 index 0000000000000000000000000000000000000000..27a05f5f24db76f2287d01310908de74e8f6ee2a --- /dev/null +++ b/PackageStructureKit/LoginModule/src/main/ets/components/LoginPage.ets @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:如何实现跨模块的页面跳转功能 +*/ + +// [Start login_page_with_module] +@Component +export struct LoginPage { + @Consume('pathStack') pathStack: NavPathStack; + @State message: string = 'Login Page'; + + build() { + NavDestination() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + .height('100%') + } + .onBackPressed(() => { + this.pathStack.pop(); + return true; + }) + } +} +// [End login_page_with_module] \ No newline at end of file diff --git a/PackageStructureKit/LoginModule/src/main/ets/components/MainPage.ets b/PackageStructureKit/LoginModule/src/main/ets/components/MainPage.ets new file mode 100644 index 0000000000000000000000000000000000000000..9de5eb33fe973c00e1ddc28c9f079ace6d473711 --- /dev/null +++ b/PackageStructureKit/LoginModule/src/main/ets/components/MainPage.ets @@ -0,0 +1,19 @@ +@Component +export struct MainPage { + @State message: string = 'Hello World'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize($r('app.float.page_text_font_size')) + .fontWeight(FontWeight.Bold) + .onClick(() => { + this.message = 'Welcome'; + }) + } + .width('100%') + } + .height('100%') + } +} diff --git a/PackageStructureKit/LoginModule/src/main/module.json5 b/PackageStructureKit/LoginModule/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..bfbf3f70202b2d713e3a1a21beb5aec2858a0782 --- /dev/null +++ b/PackageStructureKit/LoginModule/src/main/module.json5 @@ -0,0 +1,11 @@ +{ + "module": { + "name": "LoginModule", + "type": "har", + "deviceTypes": [ + "default", + "tablet", + "2in1" + ] + } +} diff --git a/PackageStructureKit/LoginModule/src/main/resources/base/element/float.json b/PackageStructureKit/LoginModule/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/PackageStructureKit/LoginModule/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/PackageStructureKit/LoginModule/src/main/resources/base/element/string.json b/PackageStructureKit/LoginModule/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f51a9c8461a55f6312ef950344e3145b7f82d607 --- /dev/null +++ b/PackageStructureKit/LoginModule/src/main/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "page_show", + "value": "page from package" + } + ] +} diff --git a/PackageStructureKit/LoginModule/src/ohosTest/ets/test/Ability.test.ets b/PackageStructureKit/LoginModule/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..85c78f67579d6e31b5f5aeea463e216b9b141048 --- /dev/null +++ b/PackageStructureKit/LoginModule/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,35 @@ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function abilityTest() { + describe('ActsAbilityTest', () => { + // 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. + hilog.info(0x0000, 'testTag', '%{public}s', 'it begin'); + 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); + }) + }) +} \ No newline at end of file diff --git a/PackageStructureKit/LoginModule/src/ohosTest/ets/test/List.test.ets b/PackageStructureKit/LoginModule/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..794c7dc4ed66bd98fa3865e07922906e2fcef545 --- /dev/null +++ b/PackageStructureKit/LoginModule/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,5 @@ +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/PackageStructureKit/LoginModule/src/ohosTest/module.json5 b/PackageStructureKit/LoginModule/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f1fd6a700aa5d56a3ad50f62c22e2ba45535904c --- /dev/null +++ b/PackageStructureKit/LoginModule/src/ohosTest/module.json5 @@ -0,0 +1,13 @@ +{ + "module": { + "name": "LoginModule_test", + "type": "feature", + "deviceTypes": [ + "default", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/PackageStructureKit/LoginModule/src/test/List.test.ets b/PackageStructureKit/LoginModule/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..bb5b5c3731e283dd507c847560ee59bde477bbc7 --- /dev/null +++ b/PackageStructureKit/LoginModule/src/test/List.test.ets @@ -0,0 +1,5 @@ +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/PackageStructureKit/LoginModule/src/test/LocalUnit.test.ets b/PackageStructureKit/LoginModule/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..165fc1615ee8618b4cb6a622f144a9a707eee99f --- /dev/null +++ b/PackageStructureKit/LoginModule/src/test/LocalUnit.test.ets @@ -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); + }); + }); +} \ No newline at end of file diff --git a/PackageStructureKit/build-profile.json5 b/PackageStructureKit/build-profile.json5 index 03ac3a3ae9dd397844173066e5d5ee21b49455a1..2e47cfdc5577c72ca40412b952600d9c0f70c7fc 100644 --- a/PackageStructureKit/build-profile.json5 +++ b/PackageStructureKit/build-profile.json5 @@ -36,6 +36,10 @@ ] } ] + }, + { + "name": "LoginModule", + "srcPath": "./LoginModule", } ] } \ No newline at end of file diff --git a/PackageStructureKit/entry/oh-package-lock.json5 b/PackageStructureKit/entry/oh-package-lock.json5 new file mode 100644 index 0000000000000000000000000000000000000000..65a9e3719ff42b891e0074718d97848bb9a5ea25 --- /dev/null +++ b/PackageStructureKit/entry/oh-package-lock.json5 @@ -0,0 +1,18 @@ +{ + "meta": { + "stableOrder": true + }, + "lockfileVersion": 3, + "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", + "specifiers": { + "@ohos/login@../LoginModule": "@ohos/login@../LoginModule" + }, + "packages": { + "@ohos/login@../LoginModule": { + "name": "@ohos/login", + "version": "1.0.0", + "resolved": "../LoginModule", + "registryType": "local" + } + } +} \ No newline at end of file diff --git a/PackageStructureKit/entry/oh-package.json5 b/PackageStructureKit/entry/oh-package.json5 index 248c3b7541a589682a250f86a6d3ecf7414d2d6a..70f3a6223a5356a64e48679b4f59b92d6829e008 100644 --- a/PackageStructureKit/entry/oh-package.json5 +++ b/PackageStructureKit/entry/oh-package.json5 @@ -1,10 +1,35 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:如何实现跨模块的页面跳转功能 +*/ + +// [Start login_with_module_dependency] { + // [StartExclude login_with_module_dependency] "name": "entry", "version": "1.0.0", "description": "Please describe the basic information.", "main": "", "author": "", "license": "", - "dependencies": {} + // [EndExclude login_with_module_dependency] + "dependencies": { + "@ohos/login": "file:../LoginModule" + } } +// [End login_with_module_dependency] diff --git a/PackageStructureKit/entry/src/main/ets/pages/CrossModulePageJump.ets b/PackageStructureKit/entry/src/main/ets/pages/CrossModulePageJump.ets index 81fa65b6df74e4d37cdb9793c55a3a3c036e9d14..35cdea2f4273aa2722127331e2931c7181f0b5ee 100644 --- a/PackageStructureKit/entry/src/main/ets/pages/CrossModulePageJump.ets +++ b/PackageStructureKit/entry/src/main/ets/pages/CrossModulePageJump.ets @@ -17,41 +17,9 @@ * FAQ:如何实现跨模块的页面跳转功能 */ -// DocsCode 1 -@Component -export struct LoginPage { - @Consume('pathStack') pathStack: NavPathStack; - @State message: string = 'Login Page'; - - build() { - NavDestination() { - Column() { - Text(this.message) - .fontSize(50) - .fontWeight(FontWeight.Bold) - } - .width('100%') - .height('100%') - } - .onBackPressed(() => { - this.pathStack.pop(); - return true; - }) - } -} -// DocsCode 1 - -// DocsCode 2 -{ - // ... - "dependencies": { - "@ohos/login": "file:../login" - } -} -// DocsCode 2 -// DocsCode 3 -// 导入Login模块自定义组件 +// [Start navigation_page] +// Import a custom component of the Login module import { LoginPage } from '@ohos/login'; @Entry @@ -70,7 +38,7 @@ struct NavigationPage { Navigation(this.pathStack) { Button('jump to login page') .onClick(() => { - // NavPathInfo第二个参数为自定义参数,可用于信息传递 + // The second parameter of NavPathInfo is a custom parameter that can be used for message transfer let pathInfo: NavPathInfo = new NavPathInfo('loginPage', new Object()); this.pathStack.pushDestination(pathInfo, true); }) @@ -78,4 +46,4 @@ struct NavigationPage { .navDestination(this.pageMap) } } -// DocsCode 3 \ No newline at end of file +// [End navigation_page] \ No newline at end of file diff --git a/PackageStructureKit/entry/src/main/ets/pages/ErrorInObtainingHSPFile.ets b/PackageStructureKit/entry/src/main/ets/pages/ErrorInObtainingHSPFile.ets index 214bf8cae0085558d8a4baf36f07b7ace49711d9..b10654d043e1aeb3a7f5cefd2bd0ddf157aeec14 100644 --- a/PackageStructureKit/entry/src/main/ets/pages/ErrorInObtainingHSPFile.ets +++ b/PackageStructureKit/entry/src/main/ets/pages/ErrorInObtainingHSPFile.ets @@ -17,7 +17,7 @@ * FAQ:通过resourceManager.getStringResource接口获取HSP资源文件报“Resource id invalid”错误 */ -// DocsCode 1 +// [Start error_in_obtaining_hsp_file] import { common, application } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { JSON } from '@kit.ArkTS'; @@ -25,24 +25,24 @@ import { JSON } from '@kit.ArkTS'; @Entry @Component struct Index { - private context = UIContext.getHostContext() as common.UIAbilityContext; + private context = this.getUIContext().getHostContext() as common.UIAbilityContext; build() { Column() { Button() .onClick(() => { - // 根据模块名创建上下文Context + // Create a context based on the module name let moduleName: string = 'library'; application.createModuleContext(this.context, moduleName) .then((data: common.Context) => { console.info(`CreateModuleContext success, data: ${JSON.stringify(data)}`); if (data !== null) { this.getUIContext().getPromptAction().showToast({ - message: ('成功获取Context') + message: ('get Context success') }); } - // 然后通过getStringByNameSync获取指定资源名称对应的字符串 + // Then run getStringByNameSync to obtain the string corresponding to the specified resource name try { let str = data.resourceManager.getStringByNameSync('shared_desc'); console.info(`getStringByNameSync, data: ${JSON.stringify(str)}`); @@ -59,4 +59,4 @@ struct Index { } } } -// DocsCode 1 \ No newline at end of file +// [End error_in_obtaining_hsp_file] \ No newline at end of file