From 8e25e224cdd54df7b8f20b8ce908c49c3d586009 Mon Sep 17 00:00:00 2001 From: "@feng-yu4279" Date: Tue, 27 May 2025 16:07:18 +0800 Subject: [PATCH] =?UTF-8?q?feat=20(=E6=A0=87=E8=AF=86):=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=20ComponentEncapsulation=20=E4=BB=93=E5=BA=93?= =?UTF-8?q?=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/model/AttributeModifier.ets | 1 + entry/src/main/ets/pages/CommonComponent.ets | 6 ++++-- entry/src/main/ets/pages/ComponentFactory.ets | 4 ++-- entry/src/main/ets/pages/DialogComponent.ets | 6 ++---- entry/src/main/ets/view/CustomImageText.ets | 8 +++++--- entry/src/main/ets/view/FactoryMap.ets | 1 + entry/src/main/resources/base/element/string.json | 4 ++++ entry/src/main/resources/en_US/element/string.json | 4 ++++ entry/src/main/resources/zh_CN/element/string.json | 4 ++++ 9 files changed, 27 insertions(+), 11 deletions(-) diff --git a/entry/src/main/ets/model/AttributeModifier.ets b/entry/src/main/ets/model/AttributeModifier.ets index a2bd036..51c59c9 100644 --- a/entry/src/main/ets/model/AttributeModifier.ets +++ b/entry/src/main/ets/model/AttributeModifier.ets @@ -52,6 +52,7 @@ export class TextModifier implements AttributeModifier { } } // [End image_modifier] + // [Start my_button_modifier] // src/main/ets/model/AttributeModifier.ets // The client implements the AttributeModifier interface with custom class. diff --git a/entry/src/main/ets/pages/CommonComponent.ets b/entry/src/main/ets/pages/CommonComponent.ets index c9bb186..9e4776f 100644 --- a/entry/src/main/ets/pages/CommonComponent.ets +++ b/entry/src/main/ets/pages/CommonComponent.ets @@ -49,7 +49,8 @@ struct CommonComponent { } } // [End common_component] -// [Start my_button] + +// [Start my_button1] //Provider customizes and exports components @Component export struct MyButton { @@ -68,7 +69,8 @@ export struct MyButton { .height(50) } } -// [End my_button] +// [End my_button1] + // [Start my_button_modifier1] // src/main/ets/pages/CommonComponent.ets // The provider creates a custom Class that implements the system's AttributeModifier interface. diff --git a/entry/src/main/ets/pages/ComponentFactory.ets b/entry/src/main/ets/pages/ComponentFactory.ets index 19c784b..a732807 100644 --- a/entry/src/main/ets/pages/ComponentFactory.ets +++ b/entry/src/main/ets/pages/ComponentFactory.ets @@ -15,10 +15,10 @@ // [Start factory_map] // Import the component factory. The path must be based on the actual location. import { factoryMap } from '../view/FactoryMap'; -// [StartExclude get_resource_string] +// [StartExclude factory_map] import { getResourceString } from '../model/GetResourceString'; import { CommonConstants } from '../common/CommonConstants'; -// [EndExclude get_resource_string] +// [EndExclude factory_map] // Get the corresponding WrappedBuilder object from the key value of the component factory Map. let myRadio: WrappedBuilder<[]> = factoryMap.get('Radio') as WrappedBuilder<[]>; let myCheckbox: WrappedBuilder<[]> = factoryMap.get('Checkbox') as WrappedBuilder<[]>; diff --git a/entry/src/main/ets/pages/DialogComponent.ets b/entry/src/main/ets/pages/DialogComponent.ets index d89f3e3..a6051b0 100644 --- a/entry/src/main/ets/pages/DialogComponent.ets +++ b/entry/src/main/ets/pages/DialogComponent.ets @@ -16,12 +16,11 @@ import { CommonConstants } from '../common/CommonConstants'; import { getResourceString } from '../model/GetResourceString'; // [Start dialog_component] import { PopViewUtils } from '../model/PopViewUtils'; -// [StartExclude buildText] +// [StartExclude dialog_component] @Builder export function DialogComponentBuilder() { DialogComponent() } -// [Start dialog_component1] @Builder export function buildText(_obj: Object) { Column({ space: CommonConstants.ROW_SPACING }) { @@ -55,8 +54,7 @@ export function buildText(_obj: Object) { .backgroundColor(Color.White) .borderRadius($r('app.float.border_radius')) } -// [End dialog_component1] -// [StartExclude buildText] +// [EndExclude dialog_component] @Entry @Component struct DialogComponent { diff --git a/entry/src/main/ets/view/CustomImageText.ets b/entry/src/main/ets/view/CustomImageText.ets index f669eef..1a3279f 100644 --- a/entry/src/main/ets/view/CustomImageText.ets +++ b/entry/src/main/ets/view/CustomImageText.ets @@ -23,14 +23,15 @@ export struct CustomImageText { build() { Column({ space: CommonConstants.BUTTON_SPACING }) { - Image(this.imageSrc) + Image($r('app.media.image')) .attributeModifier(this.imageAttribute) - Text(this.text) + Text('Scenery') .attributeModifier(this.textAttribute) } } } // [End custom_image_text] + // [Start my_button] // src/main/ets/view/CustomImageText.ets @Component @@ -46,12 +47,13 @@ struct MyButton { } } // [End my_button] + // [Start index] // src/main/ets/view/CustomImageText.ets @Component struct Index { build() { - MyButton({ text: '点击带有动效', stateEffect: true }) + MyButton({ text: String($r('app.string.click')), stateEffect: true }) } } // [End index] \ No newline at end of file diff --git a/entry/src/main/ets/view/FactoryMap.ets b/entry/src/main/ets/view/FactoryMap.ets index f0b67c5..7a41ffb 100644 --- a/entry/src/main/ets/view/FactoryMap.ets +++ b/entry/src/main/ets/view/FactoryMap.ets @@ -64,6 +64,7 @@ function myCheckBox() { .width(CommonConstants.ONE_HUNDRED_PERCENT) } // [End my_radio] + // [Start factory_map] // Define the component factory Map. let factoryMap: Map = new Map(); diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json index 8d61c21..86e9f1d 100644 --- a/entry/src/main/resources/base/element/string.json +++ b/entry/src/main/resources/base/element/string.json @@ -51,6 +51,10 @@ { "name": "checkbox", "value": "CheckBox" + }, + { + "name": "click", + "value": "CheckBox" } ] } \ No newline at end of file diff --git a/entry/src/main/resources/en_US/element/string.json b/entry/src/main/resources/en_US/element/string.json index 8d61c21..86e9f1d 100644 --- a/entry/src/main/resources/en_US/element/string.json +++ b/entry/src/main/resources/en_US/element/string.json @@ -51,6 +51,10 @@ { "name": "checkbox", "value": "CheckBox" + }, + { + "name": "click", + "value": "CheckBox" } ] } \ No newline at end of file diff --git a/entry/src/main/resources/zh_CN/element/string.json b/entry/src/main/resources/zh_CN/element/string.json index 82248c1..7d20e07 100644 --- a/entry/src/main/resources/zh_CN/element/string.json +++ b/entry/src/main/resources/zh_CN/element/string.json @@ -51,6 +51,10 @@ { "name": "checkbox", "value": "复选框" + }, + { + "name": "click", + "value": "点击带有动效" } ] } \ No newline at end of file -- Gitee