diff --git a/code/ArkTS1.2/ModuleSample/README.md b/code/ArkTS1.2/ModuleSample/README.md new file mode 100644 index 0000000000000000000000000000000000000000..8e35d2a0e269a0b4b340d8aaa45c881a130ccc7f --- /dev/null +++ b/code/ArkTS1.2/ModuleSample/README.md @@ -0,0 +1,327 @@ +# 模块化引用示例 + +## 介绍 + +本示例为模块化引用示例。 + +## 效果图预览 + + + + **场景说明** + 1. 懒加载机制默认实现:引入但未使用的类不会被加载。 + 2. export出来的类,其余未export的情况不会加载。 + 3. har包引入后,未使用的情况下不加载。 + +## 实现思路 +### 场景1:懒加载机制默认实现:引入但未使用的类不会被加载。 + +- 在mod1.ets文件内写入类Mod1以及一条打印日志的顶层语句,Mod1类内包含一个静态代码块,静态代码块内为打印日志语句。 +- 在Index.ets文件内导入Mod1.ets文件,不点击按钮"import"时,Mod1为引入但未使用的类,此时不会打印"executeModule mod1"以及"executeModule import 顶层语句"日志。 +- 点击按钮时,使用Mod1类,此时才会打印"executeModule mod1"日志。"executeModule import 顶层语句"日志为顶层语句不会被打印。 + +```typescript +// mod1.ets +export class Mod1 { + static name: string = 'mod'; + static { + hilog.info(0x0000, 'testTag', "executeModule mod1"); + } +} +hilog.info(0x0000, 'testTag', "executeModule import 顶层语句"); +``` +```typescript +// Index.ets +import { Mod1 } from './mod/mod1'; +@Component +struct MyStateSample { + build() { + ... + Button("import") + .width('60%') + .onClick((e: ClickEvent) => { + let mod1 = new Mod1(); + }) + ... + } +} +``` +### 场景2:export出来的类,其余未export的情况不会加载。 +#### 2.1 顶层语句不会被加载 + +- 在mod2.ets文件内包含一个导出类Mod2以及一条打印日志的顶层语句,Mod2类内包含一个静态代码块,静态代码块内为打印日志语句。 +- 在Index.ets文件内导入Mod2.ets文件,点击"export1"按钮时,Mod2.ets文件内未导出的顶层语句不会被加载,不会打印日志"executeModule export 顶层语句"。 + +```typescript +// mod2.ets +export class Mod2 { + static name: string = ''; + static { + hilog.info(0x0000, 'testTag', "executeModule mod2"); + } +} +hilog.info(0x0000, 'testTag', "executeModule export 顶层语句"); +``` +```typescript +// Index.ets +import { Mod2 } from './mod/mod2'; +@Component +struct MyStateSample { + build() { + ... + Button("export1") + .width('60%') + .onClick((e: ClickEvent) => { + let mod2 = new Mod2(); + }) + ... + } +} +``` +#### 2.2 其余未导出的类不会被加载 + +- mod3文件内导出内容有:五个类,类名分别为A,B,C,D,E,A类内有一个静态成员变量count,值为1,A类的静态代码块只有hilog语句,顶层代码将A.count设置为100。 B,C,D,E内的静态成员变量count默认值为0,B,C,D,E内的静态代码块将每个类的count的值设置为++A.count。 +- 在Index文件内导入两个类A和E,arkts1.0 export时所有类都会export,因此A.count经过四次增加,以及一次顶层语句的赋值,E.count的值为105。其余export的类不加载,E.count的值应该为2,仅导入两个类A和E。 + +```typescript +// mod3.ets +import hilog from '@ohos.hilog' +export class A { + static count = 1; + static { + hilog.info(0x0000, 'testTag', "executeModule execute A"); + } +} +A.count = 101; +export class B { + static count = 0; + static { + B.count = ++A.count; + hilog.info(0x0000, 'testTag', "executeModule execute B"); + } +} + +export class C { + static count = 0; + static { + C.count = ++A.count; + hilog.info(0x0000, 'testTag', "executeModule execute C"); + } +} +export class D { + static count = 0; + static { + D.count = ++A.count; + hilog.info(0x0000, 'testTag', "executeModule execute D"); + } +} +export class E { + static count = 0; + static { + E.count = ++A.count; + hilog.info(0x0000, 'testTag', "executeModule execute E"); + } +} +``` +```typescript +// Index.ets +import { A, E } from './mod/mod3'; +@Component +struct MyStateSample { + build() { + ... + Button("export2") + .width('60%') + .onClick((e: ClickEvent) => { + let modA = new A(); + let modE = new E(); + let promptAction: PromptAction = this.uiContext!.getPromptAction(); + promptAction.showToast({ + message: '共加载了 E.count: ' + E.count + '个类', + duration: 20000 + }); + }) + ... + } +} +``` + +#### 2.3 通过耗时验证其余未导出的类没有被加载 +- mod4.ets文件包含一个导出类ExportSmallClassTest,如果这个类被加载会运行静态模块,在静态模块内将此时的时间记录到静态成员变量exportTime中。 +- 在exportTestPage1.ets文件内,将mod4.ets中导出的类ExportSmallClassTest导入,导入后用现在的时间减去ExportSmallClassTest类中的exportTime就是导入耗时,将耗时写到Text组件,显示到界面上。 +- mod5.ets文件里面包括两个类,ExportSmallClass和ExportBigClass,ExportSmallClass和在mod4中的ExportSmallClassTest类的内容完全一致,静态成员变量isExportOtherClass默认值为false,ExportBigClass是一个有15000多个成员变量的超大类,在这个类的静态代码块中将ExportSmallClass.isExportOtherClass置为true。如果加载了这个超大类,ExportSmallClass的静态成员变量isExportOtherClass的值将置为true。 +- 在exportTestPage2.ets页面导入mod5中的ExportSmallClass类,将耗时记录下来,显示在界面上。并判断ExportSmallClass.isExportOtherClass是否为true,如果为true则代表超大类也导出了,此时显示文本“不需要的类也加载了”。 +```typescript +// mod4.ets +import hilog from '@ohos.hilog' + +export class ExportSmallClassTest { + static exportTime: double = 0; + static isExportOtherClass = false; + static { + ExportSmallClassTest.exportTime = Date.now(); + hilog.info(0x0000, 'testTag', "executeModule mod4 smallclass"); + } + static na = 'zhangsan'; +} +``` +```typescript +// exportTestPage1.ets +import { ExportSmallClassTest } from './mod/mod4'; +let exportTime: double = ExportSmallClassTest.exportTime; +let dur = Date.now() - exportTime; +@Entry +@Component +struct page1 { + @State message: string = "预期结果"; + build() { + Column() { + Text('page1') + .fontSize(30) + Text('耗时' + dur + 'ms') + .fontSize(20) + Button("back") + .onClick((e: ClickEvent) => { + this.getUIContext().getRouter().back(); + }) + } + .width('100%') + .height('100%') + } +} +``` +```typescript +// mod5.ets +import hilog from '@ohos.hilog' +export class ExportSmallClass { + static exportTime: double = 0; + static isExportOtherClass = false; + static { + ExportSmallClass.exportTime = Date.now(); + hilog.info(0x0000, 'testTag', "executeModule mod5 smallclass"); + } + static na = 'zhangsan'; +} + export class ExportBigClass { + static exportTime: double = 0; + static { + ExportBigClass.exportTime = Date.now(); + ExportSmallClass.isExportOtherClass = true; + hilog.info(0x0000, 'testTag', "executeModule mod5 bigclass"); + } + static attribute_0 = 0; + static attribute_1 = 1; + static attribute_2 = 2; + static attribute_3 = 3; + ... + static attribute_15000 = 15000; +} +``` +```typescript +// exportTestPage2.ets +import { ExportSmallClass } from './mod/mod5'; +let exportTime: double = ExportSmallClass.exportTime; +let dur = Date.now() - exportTime; +@Entry +@Component +struct page2 { + build() { + Column() { + Text('page2') + .fontSize(30) + Text('耗时' + dur + 'ms') + .fontSize(20) + if(ExportSmallClass.isExportOtherClass) { + Text('不需要的类也加载了') + } + Button("back") + .onClick((e: ClickEvent) => { + this.getUIContext().getRouter().back(); + }) + } + .width('100%') + .height('100%') + } +} +``` +### 场景3:har包引入后,未使用的情况下不加载。 + +- 在项目中新建har包,命名为ImportHar。 +- 在har包内MainPage.ets页面。 +- 点击按钮时,使用Mod1类,此时才会打印"executeModule mod1"日志。"executeModule import 顶层语句"日志为顶层语句不会被打印。 + +```typescript +// ImportHar/src/main/ets/components/MainPage.ets +import hilog from '@ohos.hilog' +export class Har { + static { + hilog.info(0x0000, 'testTag', "executeModule mod 导入har包"); + } +} + ``` +```typescript +// Index.ets +import { Har } from 'importhar'; +@Component +struct MyStateSample { + build() { + ... + Button("import har") + .width('60%') + .onClick((e: ClickEvent) => { + let har = new Har(); + }) + ... + } +} +``` + +### 高性能知识点 + +不涉及 + +### 相关权限 + +无 + +### 依赖 + +无 + +### 约束与限制 + +1. 本示例仅支持标准系统上运行,支持设备:Phone; +2. 本示例为Stage模型,支持API20版本SDK,SDK版本号(API Version 20),镜像版本号(6.0.0.33)。 +3. 本示例需要使用DevEco Studio 版本号(6.0.0.21)版本才可编译运行。 + +### 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo code/ArkTS1.2/ModuleSample/ > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull +``` + +### 工程结构&模块类型 + +``` + ModuleSample + |---entry + | |---src/main/ets/pages + | | |---mod // 模块 + | | | |---mod1.ets + | | | |---mod2.ets + | | | |---mod3.ets + | | | |---mod4.ets + | | | |---mod5.ets + | | |---exportTestPage1.ets + | | |---exportTestPage2.ets + | | |---Index.ets // 主页 + |---ImportHar // har包 + | |---src/main/ets/pages/components + | | |---MainPage.ets +``` \ No newline at end of file diff --git a/code/ArkTS1.2/ModuleSample/build-profile.json5 b/code/ArkTS1.2/ModuleSample/build-profile.json5 index daf68e32f799c00a252c48351cc0f1728af610f0..920317bba9bf8b947b7e46f1b67da28841dd00ac 100644 --- a/code/ArkTS1.2/ModuleSample/build-profile.json5 +++ b/code/ArkTS1.2/ModuleSample/build-profile.json5 @@ -5,7 +5,7 @@ { "name": "default", "signingConfig": "default", - "compatibleSdkVersion": "5.0.2(14)", + "compatibleSdkVersion": "6.0.0(20)", "runtimeOS": "HarmonyOS", "arkTSVersion": "1.2", "buildOption": { diff --git a/code/ArkTS1.2/ModuleSample/entry/src/main/ets/entryability/EntryAbility.ets b/code/ArkTS1.2/ModuleSample/entry/src/main/ets/entryability/EntryAbility.ets index b892d18a00d879e20ee20840d94a2e06f10ae1c5..c75cab5aa2a5a5b5500236a6c53d1f4eb71a0e1a 100644 --- a/code/ArkTS1.2/ModuleSample/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/ArkTS1.2/ModuleSample/entry/src/main/ets/entryability/EntryAbility.ets @@ -1,3 +1,17 @@ +/* + * Copyright (c) 2025 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. + */ import UIAbility from '@ohos.app.ability.UIAbility'; import AbilityConstant from '@ohos.app.ability.AbilityConstant'; import Want from '@ohos.app.ability.Want'; diff --git a/code/ArkTS1.2/ModuleSample/entry/src/main/ets/pages/Index.ets b/code/ArkTS1.2/ModuleSample/entry/src/main/ets/pages/Index.ets index a387639744400a8d8761409110ce0f01f517ab85..775511f026982d0b3623879bde28d6c74338ebd8 100644 --- a/code/ArkTS1.2/ModuleSample/entry/src/main/ets/pages/Index.ets +++ b/code/ArkTS1.2/ModuleSample/entry/src/main/ets/pages/Index.ets @@ -1,46 +1,86 @@ -import { memo, __memo_context_type, __memo_id_type } from '@ohos.arkui.stateManagement' // should be insert by ui-plugins -import { Text, TextAttribute, Column, Component, Button, ButtonAttribute, ClickEvent, UserView } from '@ohos.arkui.component' // TextAttribute should be insert by ui-plugins -import { State, StateDecoratedVariable, MutableState, stateOf, observableProxy } from '@ohos.arkui.stateManagement' // should be insert by ui-plugins +/* + * Copyright (c) 2025 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. + */ +import { memo, __memo_context_type, __memo_id_type } from "@ohos.arkui.stateManagement" // should be insert by ui-plugins +import { $r, HorizontalAlign, FlexAlign, Text, TextAttribute, Column, Component, Button, ButtonAttribute, ClickEvent, UserView } from "@ohos.arkui.component" // TextAttribute should be insert by ui-plugins +import { State, MutableState, stateOf, observableProxy } from "@ohos.arkui.stateManagement" // should be insert by ui-plugins import hilog from '@ohos.hilog' -import { Mod1 } from './mod/mod1' +import { Mod1 } from './mod/mod1'; import { Mod2 } from './mod/mod2'; +import promptAction from '@ohos.promptAction'; +import { UIContext, PromptAction } from '@ohos.arkui.UIContext'; import { A, E } from './mod/mod3'; -import { ExportSmallClassTest } from './mod/mod4' -import { ExportSmallClass } from './mod/mod5' -import { Har } from 'importhar' - +import { Har } from 'importhar'; +import { Router } from '@ohos.arkui.UIContext' @Component struct MyStateSample { - aboutToAppear() { - hilog.info(0x0000, 'testTag', 'executeModule modTest start'); - let mod1 = new Mod1; - let mod2 = new Mod2; - let modA = new A(); - let modE = new E(); - hilog.info(0x0000, 'testTag', 'executeModule E.count:' + E.count); - let mod5 = new ExportSmallClass(); - hilog.info(0x0000, 'testTag', 'executeModule ExportSmallClass.isExportOtherClass:' + ExportSmallClass.isExportOtherClass); - let har: Har = new Har(); + @State stateVar: string = "state var"; + uiContext: UIContext | undefined = undefined; + + aboutToAppear(): void { + this.uiContext = this.getUIContext(); } - @State stateVar: string = 'state var'; - message: string = 'var'; build() { Column(undefined) { - Button(this.message).backgroundColor('#FFFF00FF') + Button("import") + .width('60%') + .onClick((e: ClickEvent) => { + let mod1 = new Mod1(); + }) + Button("export1") + .width('60%') + .onClick((e: ClickEvent) => { + let mod2 = new Mod2(); + }) + Button("export2") + .width('60%') + .onClick((e: ClickEvent) => { + let modA = new A(); + let modE = new E(); + let promptAction: PromptAction = this.uiContext!.getPromptAction(); + promptAction.showToast({ + message: "共加载了 E.count: " + E.count + '个类', + duration: 20000 + }); + }) + Button("export3") + .width('60%') + .onClick((e: ClickEvent) => { + this.getUIContext().getRouter().pushUrl({url: 'pages/exportTestPage1'}); + }) + Button("export4") + .width('60%') + .onClick((e: ClickEvent) => { + this.getUIContext().getRouter().pushUrl({url: 'pages/exportTestPage2'}); + }) + Button("import har") + .width('60%') .onClick((e: ClickEvent) => { - hilog.info(0x0000, 'testTag', 'On Click'); + let har = new Har(); }) - Text(this.stateVar).fontSize(20) } + .width('100%') + .height('100%') + .alignItems(HorizontalAlign.Center) + .justifyContent(FlexAlign.SpaceEvenly) } } export class ComExampleTrivialApplication extends UserView { getBuilder() { - hilog.info(0x0000, 'testTag', 'getBuilder'); let wrapper = @memo () => { - hilog.info(0x0000, 'testTag', 'MyStateSample'); MyStateSample(undefined) } return wrapper diff --git a/code/ArkTS1.2/ModuleSample/entry/src/main/ets/pages/exportTestPage1.ets b/code/ArkTS1.2/ModuleSample/entry/src/main/ets/pages/exportTestPage1.ets new file mode 100644 index 0000000000000000000000000000000000000000..72953aa4670561bd98686951ba072ffc457942c8 --- /dev/null +++ b/code/ArkTS1.2/ModuleSample/entry/src/main/ets/pages/exportTestPage1.ets @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2025 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. + */ +import { + memo, + __memo_context_type, + __memo_id_type +} from '@ohos.arkui.stateManagement' // should be insert by ui-plugins +import { + Text, + TextAttribute, + Column, + Component, + Button, + ButtonAttribute, + ClickEvent, + UserView, + Row, + Scroll, + Entry, + Divider, + $r +} from '@ohos.arkui.component' // TextAttribute should be insert by ui-plugins +import { + State, + MutableState, + stateOf, + observableProxy +} from '@ohos.arkui.stateManagement' // should be insert by ui-plugins +import hilog from '@ohos.hilog' +import router from '@ohos.router' +import { ExportSmallClassTest } from './mod/mod4'; +let exportTime: double = ExportSmallClassTest.exportTime; +let dur = Date.now() - exportTime; +@Entry +@Component +struct page1 { + build() { + Column() { + Text('page1') + .fontSize(30) + Text('耗时' + dur + 'ms') + .fontSize(20) + Button('back') + .onClick((e: ClickEvent) => { + this.getUIContext().getRouter().back(); + }) + } + .width('100%') + .height('100%') + } +} + +export class ComExampleTrivialApplication extends UserView { + getBuilder() { + let wrapper = @memo() =>{ + page1(undefined) + } + return wrapper + } +} \ No newline at end of file diff --git a/code/ArkTS1.2/ModuleSample/entry/src/main/ets/pages/exportTestPage2.ets b/code/ArkTS1.2/ModuleSample/entry/src/main/ets/pages/exportTestPage2.ets new file mode 100644 index 0000000000000000000000000000000000000000..3ecf13402ccf7b51c28879710809bdfec6a27472 --- /dev/null +++ b/code/ArkTS1.2/ModuleSample/entry/src/main/ets/pages/exportTestPage2.ets @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2025 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. + */ +import { + memo, + __memo_context_type, + __memo_id_type +} from '@ohos.arkui.stateManagement' // should be insert by ui-plugins +import { + Text, + TextAttribute, + Column, + Component, + Button, + ButtonAttribute, + ClickEvent, + UserView, + Row, + Scroll, + Entry, + Divider, + $r +} from '@ohos.arkui.component' // TextAttribute should be insert by ui-plugins +import { + State, + MutableState, + stateOf, + observableProxy +} from '@ohos.arkui.stateManagement' // should be insert by ui-plugins +import hilog from '@ohos.hilog' +import router from '@ohos.router' +import { ExportSmallClass } from './mod/mod5'; +let exportTime: double = ExportSmallClass.exportTime; +let dur = Date.now() - exportTime; +@Entry +@Component +struct page2 { + build() { + Column() { + Text('page2') + .fontSize(30) + Text('耗时' + dur + 'ms') + .fontSize(20) + if(ExportSmallClass.isExportOtherClass) { + Text($r('app.string.Unnecessary_class_loading')) + } + Button("back") + .onClick((e: ClickEvent) => { + this.getUIContext().getRouter().back(); + }) + } + .width('100%') + .height('100%') + } +} + +export class ComExampleTrivialApplication extends UserView { + getBuilder() { + let wrapper = @memo() => { + page2(undefined) + } + return wrapper + } +} \ No newline at end of file diff --git a/code/ArkTS1.2/ModuleSample/entry/src/main/ets/pages/mod/mod1.ets b/code/ArkTS1.2/ModuleSample/entry/src/main/ets/pages/mod/mod1.ets index 822a00deaaf736794c7cd99a3ec3d34dbea57ac9..0e51d6a5479acf9ac24a0a613e9f3a771f961a40 100644 --- a/code/ArkTS1.2/ModuleSample/entry/src/main/ets/pages/mod/mod1.ets +++ b/code/ArkTS1.2/ModuleSample/entry/src/main/ets/pages/mod/mod1.ets @@ -1,8 +1,23 @@ +/* + * Copyright (c) 2025 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. + */ import hilog from '@ohos.hilog' + export class Mod1 { - nna: string = ''; + static name: string = 'mod'; static { - hilog.info(0x0000, 'testTag', 'executeModule mod mod1'); + hilog.info(0x0000, 'testTag', 'executeModule mod1'); } } hilog.info(0x0000, 'testTag', 'executeModule import 顶层语句'); \ No newline at end of file diff --git a/code/ArkTS1.2/ModuleSample/entry/src/main/ets/pages/mod/mod2.ets b/code/ArkTS1.2/ModuleSample/entry/src/main/ets/pages/mod/mod2.ets index 3c5c83d3c055f4ff6e66215cf6c42d9fb90da068..1dc3b4bef4d5458f34f916fb14a735465894a9bb 100644 --- a/code/ArkTS1.2/ModuleSample/entry/src/main/ets/pages/mod/mod2.ets +++ b/code/ArkTS1.2/ModuleSample/entry/src/main/ets/pages/mod/mod2.ets @@ -1,4 +1,19 @@ +/* + * Copyright (c) 2025 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. + */ import hilog from '@ohos.hilog' + export class Mod2 { name: string = ''; static { diff --git a/code/ArkTS1.2/ModuleSample/entry/src/main/ets/pages/mod/mod3.ets b/code/ArkTS1.2/ModuleSample/entry/src/main/ets/pages/mod/mod3.ets index 6a6a370f8b742cd873b8f19ff639ac61e466e7da..d3b8229cf353683e176531d44d8ba4e2360382b6 100644 --- a/code/ArkTS1.2/ModuleSample/entry/src/main/ets/pages/mod/mod3.ets +++ b/code/ArkTS1.2/ModuleSample/entry/src/main/ets/pages/mod/mod3.ets @@ -1,3 +1,17 @@ +/* + * Copyright (c) 2025 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. + */ import hilog from '@ohos.hilog' export class A { static count = 1; diff --git a/code/ArkTS1.2/ModuleSample/entry/src/main/ets/pages/mod/mod4.ets b/code/ArkTS1.2/ModuleSample/entry/src/main/ets/pages/mod/mod4.ets index 965019320a819e761993065c55848e74e0f2e28b..97fce5b14c8302fbc657caafbefcda80786a2c5f 100644 --- a/code/ArkTS1.2/ModuleSample/entry/src/main/ets/pages/mod/mod4.ets +++ b/code/ArkTS1.2/ModuleSample/entry/src/main/ets/pages/mod/mod4.ets @@ -1,4 +1,19 @@ +/* + * Copyright (c) 2025 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. + */ import hilog from '@ohos.hilog' + export class ExportSmallClassTest { static exportTime: double = 0; static isExportOtherClass = false; diff --git a/code/ArkTS1.2/ModuleSample/entry/src/main/ets/pages/mod/mod5.ets b/code/ArkTS1.2/ModuleSample/entry/src/main/ets/pages/mod/mod5.ets index d973bb56cd52db8bc5c1e40cdea8453ccbbdbf6f..fed69e5954ea4c409e827b9af9c59c14f1bc3e88 100644 --- a/code/ArkTS1.2/ModuleSample/entry/src/main/ets/pages/mod/mod5.ets +++ b/code/ArkTS1.2/ModuleSample/entry/src/main/ets/pages/mod/mod5.ets @@ -1,3 +1,17 @@ +/* + * Copyright (c) 2025 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. + */ import hilog from '@ohos.hilog' export class ExportSmallClass { static exportTime: double = 0; diff --git a/code/ArkTS1.2/ModuleSample/entry/src/main/resources/base/element/string.json b/code/ArkTS1.2/ModuleSample/entry/src/main/resources/base/element/string.json index 3224d66293285b31e7d8c95d6723fa7ff1e1378c..f33ff3ff4b7385c76f9d6e4301e6ebb9f00ac7d6 100644 --- a/code/ArkTS1.2/ModuleSample/entry/src/main/resources/base/element/string.json +++ b/code/ArkTS1.2/ModuleSample/entry/src/main/resources/base/element/string.json @@ -10,7 +10,11 @@ }, { "name": "EntryAbility_label", - "value": "模块化引用" + "value": "ModuleSample" + }, + { + "name": "Unnecessary_class_loading", + "value": "不需要的类也加载了" } ] } \ No newline at end of file diff --git a/code/ArkTS1.2/ModuleSample/entry/src/main/resources/base/media/moduleSample.png b/code/ArkTS1.2/ModuleSample/entry/src/main/resources/base/media/moduleSample.png new file mode 100644 index 0000000000000000000000000000000000000000..dce750f3e1152e140d833bd08e5949cd90ca797d Binary files /dev/null and b/code/ArkTS1.2/ModuleSample/entry/src/main/resources/base/media/moduleSample.png differ diff --git a/code/ArkTS1.2/ModuleSample/entry/src/main/resources/base/profile/main_pages.json b/code/ArkTS1.2/ModuleSample/entry/src/main/resources/base/profile/main_pages.json index 1898d94f58d6128ab712be2c68acc7c98e9ab9ce..4e54c6d4d4b10ba948904756b6c32f26206f54dd 100644 --- a/code/ArkTS1.2/ModuleSample/entry/src/main/resources/base/profile/main_pages.json +++ b/code/ArkTS1.2/ModuleSample/entry/src/main/resources/base/profile/main_pages.json @@ -1,5 +1,7 @@ { "src": [ - "pages/Index" + "pages/Index", + "pages/exportTestPage1", + "pages/exportTestPage2" ] -} +} \ No newline at end of file diff --git a/code/ArkTS1.2/ModuleSample/importHar/src/main/ets/components/MainPage.ets b/code/ArkTS1.2/ModuleSample/importHar/src/main/ets/components/MainPage.ets index fd735bf62414e9606b287e5e237e7dc67761c898..5adcf31a2ec6ed1211e098edaab2d6de7035960b 100644 --- a/code/ArkTS1.2/ModuleSample/importHar/src/main/ets/components/MainPage.ets +++ b/code/ArkTS1.2/ModuleSample/importHar/src/main/ets/components/MainPage.ets @@ -1,3 +1,17 @@ +/* + * Copyright (c) 2025 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. + */ import hilog from '@ohos.hilog' export class Har { static { diff --git a/code/ArkTS1.2/ModuleSample/ohosTest.md b/code/ArkTS1.2/ModuleSample/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..4551bbd1e0f857e97b4eb254f7ef6b3ce6bf1b8a --- /dev/null +++ b/code/ArkTS1.2/ModuleSample/ohosTest.md @@ -0,0 +1,12 @@ +# 模块化引用测试用例 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +|-----------------------------------|-------------------------------------|----------------------|------------------------------------|------|------| +| 引入类加载验证 | 1. 需在真机测试
2. 构建并安装测试hap
3.启动测试hap| 1、不点击页面中的import按钮
2、点击页面中的import按钮 | 1、不打印日志“executeModule mod1”
2、打印日志“executeModule mod1 | 否 | Pass | +| har引入加载验证 | 1. 需在真机测试
2. 构建并安装测试hap
3.启动测试hap| 1、不点击页面中的import har按钮
2、点击页面中的import har按钮 | 1、不打印日志“executeModule mod 导入har包”
2、打印日志“executeModule mod 导入har包”| 否 | Pass | +| 导出类加载验证 | 1. 需在真机测试
2. 构建并安装测试hap
3.启动测试hap| 1、点击页面中的export1按钮 | 1、打印日志“executeModule mod2” | 否 | Pass | +| 其余导出类静态模块 | 1. 需在真机测试
2. 构建并安装测试hap
3.启动测试hap| 1、点击页面中的export2按钮 | 1、页面加载并显示弹窗及内容:共加载了 E.count: 2个类 | 否 | Pass | +| 其余导出类耗时验证 | 1. 需在真机测试
2. 构建并安装测试hap
3.启动测试hap| 1、点击页面中的export3按钮 | 1、页面跳转并显示耗时时间 | 否 | Pass | +| 其余导出类耗时验证 | 1. 需在真机测试
2. 构建并安装测试hap
3.启动测试hap| 1、点击页面中的export4按钮 | 1、页面跳转并显示耗时时间 | 否 | Pass | \ No newline at end of file