@buaa_smat/hometrans 0.1.16 → 0.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +162 -54
- package/agents/code-reviewer.md +321 -65
- package/agents/logic-coder.md +113 -88
- package/agents/logic-context-builder.md +47 -29
- package/agents/scripts/hmos-precheck/backends/arkts.mjs +567 -0
- package/agents/scripts/hmos-precheck/backends/arkts_diff.mjs +159 -0
- package/agents/scripts/hmos-precheck/backends/arkts_project_rules.mjs +398 -0
- package/agents/scripts/hmos-precheck/backends/codelinter.mjs +250 -0
- package/agents/scripts/hmos-precheck/backends/project_integrity.mjs +321 -0
- package/agents/scripts/hmos-precheck/backends/static_precheck.mjs +247 -0
- package/agents/scripts/hmos-precheck/core/config.mjs +184 -0
- package/agents/scripts/hmos-precheck/core/diagnostic_scope.mjs +20 -0
- package/agents/scripts/hmos-precheck/core/process_adapter.mjs +47 -0
- package/agents/scripts/hmos-precheck/core/project_catalog.mjs +50 -0
- package/agents/scripts/hmos-precheck/core/result_projection.mjs +147 -0
- package/agents/scripts/hmos-precheck/core/scope_plan.mjs +131 -0
- package/agents/scripts/hmos-precheck/core/sdk_context.mjs +67 -0
- package/agents/scripts/hmos-precheck/docs/architecture.md +37 -0
- package/agents/scripts/hmos-precheck/docs/performance-optimization.md +28 -0
- package/agents/scripts/hmos-precheck/docs/upstream-reference.json +19 -0
- package/agents/scripts/hmos-precheck/docs/validation.md +50 -0
- package/agents/scripts/hmos-precheck/index.mjs +17 -0
- package/agents/scripts/hmos-precheck/invocation.mjs +231 -0
- package/agents/scripts/hmos-precheck/rules/rule_case_matrix.csv +32 -0
- package/agents/scripts/hmos-precheck/rules/rule_inventory.csv +64 -0
- package/agents/scripts/hmos-precheck/rules/rule_inventory.mjs +59 -0
- package/agents/scripts/hmos-precheck/rules/rule_policy.mjs +54 -0
- package/agents/scripts/platform_query.mjs +626 -0
- package/agents/scripts/platform_query.test.mjs +422 -0
- package/agents/self-test-fixer.md +36 -34
- package/agents/self-tester.md +123 -143
- package/agents/test-case-generation-generator.md +317 -0
- package/agents/test-case-generation-validator.md +231 -0
- package/dist/cli/config-store.js +16 -63
- package/dist/cli/env-vars.js +1 -3
- package/dist/cli/index.js +0 -11
- package/dist/cli/init.js +127 -144
- package/dist/cli/uninstall.js +76 -110
- package/dist/utils/regex.js +8 -0
- package/env-requirements.json +55 -54
- package/package.json +6 -6
- package/resource/convert_pipeline_process.svg +103 -0
- package/resource/project_architecture.svg +122 -0
- package/resource/title_dark.png +0 -0
- package/skills/hmos-batch-ui-align/SKILL.md +345 -41
- package/skills/hmos-batch-ui-align/references/conversion-procedure.md +661 -180
- package/skills/hmos-batch-ui-align/references/mappings/android-to-harmonyOS-ui-atomic-component-mapping-reference.md +2533 -2533
- package/skills/hmos-batch-ui-align/references/mappings/android-to-harmonyOS-ui-interaction-mapping-reference.md +555 -555
- package/skills/hmos-batch-ui-align/references/mappings/android-to-harmonyOS-ui-layout-mapping-reference.md +117 -117
- package/skills/hmos-batch-ui-align/references/mvvm/@Link/350/243/205/351/245/260/345/231/250/357/274/232/347/210/266/345/255/220/345/217/214/345/220/221/345/220/214/346/255/245.md +648 -648
- package/skills/hmos-batch-ui-align/references/mvvm/@Observed/350/243/205/351/245/260/345/231/250/345/222/214@ObjectLink/350/243/205/351/245/260/345/231/250/357/274/232/345/265/214/345/245/227/347/261/273/345/257/271/350/261/241/345/261/236/346/200/247/345/217/230/345/214/226.md +2088 -2088
- package/skills/hmos-batch-ui-align/references/mvvm/@Prop/350/243/205/351/245/260/345/231/250/357/274/232/347/210/266/345/255/220/345/215/225/345/220/221/345/220/214/346/255/245.md +1033 -1033
- package/skills/hmos-batch-ui-align/references/mvvm/@Provide/350/243/205/351/245/260/345/231/250/345/222/214@Consume/350/243/205/351/245/260/345/231/250/357/274/232/344/270/216/345/220/216/344/273/243/347/273/204/344/273/266/345/217/214/345/220/221/345/220/214/346/255/245.md +1183 -1183
- package/skills/hmos-batch-ui-align/references/mvvm/@State/350/243/205/351/245/260/345/231/250/357/274/232/347/273/204/344/273/266/345/206/205/347/212/266/346/200/201.md +576 -576
- package/skills/hmos-batch-ui-align/references/mvvm/@Track/350/243/205/351/245/260/345/231/250/357/274/232class/345/257/271/350/261/241/345/261/236/346/200/247/347/272/247/346/233/264/346/226/260.md +297 -297
- package/skills/hmos-batch-ui-align/references/mvvm/@Watch/350/243/205/351/245/260/345/231/250/357/274/232/347/212/266/346/200/201/345/217/230/351/207/217/346/233/264/346/224/271/351/200/232/347/237/245.md +395 -395
- package/skills/hmos-batch-ui-align/references/mvvm/AppStorage/357/274/232/345/272/224/347/224/250/345/205/250/345/261/200/347/232/204UI/347/212/266/346/200/201/345/255/230/345/202/250.md +902 -902
- package/skills/hmos-batch-ui-align/references/mvvm/Environment/357/274/232/350/256/276/345/244/207/347/216/257/345/242/203/346/237/245/350/257/242.md +106 -106
- package/skills/hmos-batch-ui-align/references/mvvm/LocalStorage/357/274/232/351/241/265/351/235/242/347/272/247UI/347/212/266/346/200/201/345/255/230/345/202/250.md +1178 -1178
- package/skills/hmos-batch-ui-align/references/mvvm/MVVM/346/250/241/345/274/217/357/274/210V1/357/274/211.md +911 -911
- package/skills/hmos-batch-ui-align/references/mvvm/PersistentStorage/357/274/232/346/214/201/344/271/205/345/214/226/345/255/230/345/202/250UI/347/212/266/346/200/201.md +354 -354
- package/skills/hmos-batch-ui-align/references/mvvm//347/256/241/347/220/206/345/272/224/347/224/250/346/213/245/346/234/211/347/232/204/347/212/266/346/200/201/346/246/202/350/277/260.md +11 -11
- package/skills/hmos-batch-ui-align/references/mvvm-v2/!!/350/257/255/346/263/225/357/274/232/345/217/214/345/220/221/347/273/221/345/256/232.md +206 -0
- package/skills/hmos-batch-ui-align/references/mvvm-v2/@Computed/350/243/205/351/245/260/345/231/250/357/274/232/350/256/241/347/256/227/345/261/236/346/200/247.md +373 -0
- package/skills/hmos-batch-ui-align/references/mvvm-v2/@Event/350/243/205/351/245/260/345/231/250/357/274/232/350/247/204/350/214/203/347/273/204/344/273/266/350/276/223/345/207/272.md +158 -0
- package/skills/hmos-batch-ui-align/references/mvvm-v2/@Local/350/243/205/351/245/260/345/231/250/357/274/232/347/273/204/344/273/266/345/206/205/351/203/250/347/212/266/346/200/201.md +750 -0
- package/skills/hmos-batch-ui-align/references/mvvm-v2/@Monitor/350/243/205/351/245/260/345/231/250/357/274/232/347/212/266/346/200/201/345/217/230/351/207/217/344/277/256/346/224/271/345/274/202/346/255/245/347/233/221/345/220/254.md +1704 -0
- package/skills/hmos-batch-ui-align/references/mvvm-v2/@ObservedV2/350/243/205/351/245/260/345/231/250/345/222/214@Trace/350/243/205/351/245/260/345/231/250/357/274/232/347/261/273/345/261/236/346/200/247/345/217/230/345/214/226/350/247/202/346/265/213.md +1012 -0
- package/skills/hmos-batch-ui-align/references/mvvm-v2/@Once/350/243/205/351/245/260/345/231/250/357/274/232/345/210/235/345/247/213/345/214/226/345/220/214/346/255/245/344/270/200/346/254/241.md +164 -0
- package/skills/hmos-batch-ui-align/references/mvvm-v2/@Param/350/243/205/351/245/260/345/231/250/357/274/232/347/273/204/344/273/266/345/244/226/351/203/250/350/276/223/345/205/245.md +840 -0
- package/skills/hmos-batch-ui-align/references/mvvm-v2/@Provider/350/243/205/351/245/260/345/231/250/345/222/214@Consumer/350/243/205/351/245/260/345/231/250/357/274/232/350/267/250/347/273/204/344/273/266/345/261/202/347/272/247/345/217/214/345/220/221/345/220/214/346/255/245.md +856 -0
- package/skills/hmos-batch-ui-align/references/mvvm-v2/@Type/350/243/205/351/245/260/345/231/250/357/274/232/346/240/207/350/256/260/347/261/273/345/261/236/346/200/247/347/232/204/347/261/273/345/236/213.md +83 -0
- package/skills/hmos-batch-ui-align/references/mvvm-v2/AppStorageV2/357/274/232/345/272/224/347/224/250/345/205/250/345/261/200UI/347/212/266/346/200/201/345/255/230/345/202/250.md +294 -0
- package/skills/hmos-batch-ui-align/references/mvvm-v2/MVVM/346/250/241/345/274/217/357/274/210V2/357/274/211.md +1407 -0
- package/skills/hmos-batch-ui-align/references/mvvm-v2/PersistenceV2/357/274/232/346/214/201/344/271/205/345/214/226/345/255/230/345/202/250UI/347/212/266/346/200/201.md +1220 -0
- package/skills/hmos-batch-ui-align/references/mvvm-v2/_/350/214/203/345/274/217/351/200/211/346/213/251/350/257/264/346/230/216.md +47 -0
- package/skills/hmos-batch-ui-align/references/mvvm-v2/_/350/243/205/351/245/260/345/231/250/351/200/237/346/237/245.md +133 -0
- package/skills/hmos-batch-ui-align/references/mvvm-v2//347/212/266/346/200/201/347/256/241/347/220/206V1/345/220/221V2/350/277/201/347/247/273/344/270/216/346/267/267/347/224/250/346/214/207/345/257/274.md +840 -0
- package/skills/hmos-batch-ui-align/scripts/android_parse_fast.ts +1798 -0
- package/skills/hmos-batch-ui-align/scripts/arkts_static_check.ts +1592 -0
- package/skills/hmos-batch-ui-align/scripts/measure_pack.ts +752 -0
- package/skills/hmos-convert-pipeline/SKILL.md +168 -121
- package/skills/hmos-fix-build-errors/SKILL.md +87 -67
- package/skills/hmos-fix-build-errors/references/arkts-strict-patterns.md +219 -219
- package/skills/hmos-fix-build-errors/references/known-patterns.md +157 -157
- package/skills/hmos-fix-build-errors/references/rdb-entity-pattern.md +131 -131
- package/skills/hmos-incremental-ui-align/README.md +53 -36
- package/skills/hmos-incremental-ui-align/SKILL.md +179 -23
- package/skills/hmos-incremental-ui-align/diff_analysis.md +52 -52
- package/skills/hmos-incremental-ui-align/page_align.md +62 -62
- package/skills/hmos-incremental-ui-align/references/Comparison_Template.md +38 -2
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Link/350/243/205/351/245/260/345/231/250/357/274/232/347/210/266/345/255/220/345/217/214/345/220/221/345/220/214/346/255/245.md +648 -648
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Observed/350/243/205/351/245/260/345/231/250/345/222/214@ObjectLink/350/243/205/351/245/260/345/231/250/357/274/232/345/265/214/345/245/227/347/261/273/345/257/271/350/261/241/345/261/236/346/200/247/345/217/230/345/214/226.md +2088 -2088
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Prop/350/243/205/351/245/260/345/231/250/357/274/232/347/210/266/345/255/220/345/215/225/345/220/221/345/220/214/346/255/245.md +1033 -1033
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Provide/350/243/205/351/245/260/345/231/250/345/222/214@Consume/350/243/205/351/245/260/345/231/250/357/274/232/344/270/216/345/220/216/344/273/243/347/273/204/344/273/266/345/217/214/345/220/221/345/220/214/346/255/245.md +1183 -1183
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@State/350/243/205/351/245/260/345/231/250/357/274/232/347/273/204/344/273/266/345/206/205/347/212/266/346/200/201.md +576 -576
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Track/350/243/205/351/245/260/345/231/250/357/274/232class/345/257/271/350/261/241/345/261/236/346/200/247/347/272/247/346/233/264/346/226/260.md +297 -297
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Watch/350/243/205/351/245/260/345/231/250/357/274/232/347/212/266/346/200/201/345/217/230/351/207/217/346/233/264/346/224/271/351/200/232/347/237/245.md +395 -395
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/AppStorage/357/274/232/345/272/224/347/224/250/345/205/250/345/261/200/347/232/204UI/347/212/266/346/200/201/345/255/230/345/202/250.md +902 -902
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/Environment/357/274/232/350/256/276/345/244/207/347/216/257/345/242/203/346/237/245/350/257/242.md +106 -106
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/LocalStorage/357/274/232/351/241/265/351/235/242/347/272/247UI/347/212/266/346/200/201/345/255/230/345/202/250.md +1178 -1178
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/MVVM/346/250/241/345/274/217V1.md +911 -911
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/PersistentStorage/357/274/232/346/214/201/344/271/205/345/214/226/345/255/230/345/202/250UI/347/212/266/346/200/201.md +354 -354
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243//347/256/241/347/220/206/345/272/224/347/224/250/346/213/245/346/234/211/347/232/204/347/212/266/346/200/201/346/246/202/350/277/260.md +11 -11
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/!!/350/257/255/346/263/225/357/274/232/345/217/214/345/220/221/347/273/221/345/256/232.md +206 -0
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/@Computed/350/243/205/351/245/260/345/231/250/357/274/232/350/256/241/347/256/227/345/261/236/346/200/247.md +373 -0
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/@Event/350/243/205/351/245/260/345/231/250/357/274/232/350/247/204/350/214/203/347/273/204/344/273/266/350/276/223/345/207/272.md +158 -0
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/@Local/350/243/205/351/245/260/345/231/250/357/274/232/347/273/204/344/273/266/345/206/205/351/203/250/347/212/266/346/200/201.md +750 -0
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/@Monitor/350/243/205/351/245/260/345/231/250/357/274/232/347/212/266/346/200/201/345/217/230/351/207/217/344/277/256/346/224/271/345/274/202/346/255/245/347/233/221/345/220/254.md +1704 -0
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/@ObservedV2/350/243/205/351/245/260/345/231/250/345/222/214@Trace/350/243/205/351/245/260/345/231/250/357/274/232/347/261/273/345/261/236/346/200/247/345/217/230/345/214/226/350/247/202/346/265/213.md +1012 -0
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/@Once/350/243/205/351/245/260/345/231/250/357/274/232/345/210/235/345/247/213/345/214/226/345/220/214/346/255/245/344/270/200/346/254/241.md +164 -0
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/@Param/350/243/205/351/245/260/345/231/250/357/274/232/347/273/204/344/273/266/345/244/226/351/203/250/350/276/223/345/205/245.md +840 -0
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/@Provider/350/243/205/351/245/260/345/231/250/345/222/214@Consumer/350/243/205/351/245/260/345/231/250/357/274/232/350/267/250/347/273/204/344/273/266/345/261/202/347/272/247/345/217/214/345/220/221/345/220/214/346/255/245.md +856 -0
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/@Type/350/243/205/351/245/260/345/231/250/357/274/232/346/240/207/350/256/260/347/261/273/345/261/236/346/200/247/347/232/204/347/261/273/345/236/213.md +83 -0
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/AppStorageV2/357/274/232/345/272/224/347/224/250/345/205/250/345/261/200UI/347/212/266/346/200/201/345/255/230/345/202/250.md +294 -0
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/MVVM/346/250/241/345/274/217/357/274/210V2/357/274/211.md +1407 -0
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/PersistenceV2/357/274/232/346/214/201/344/271/205/345/214/226/345/255/230/345/202/250UI/347/212/266/346/200/201.md +1220 -0
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2/_/350/214/203/345/274/217/351/200/211/346/213/251/350/257/264/346/230/216.md +47 -0
- package/skills/hmos-incremental-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243V2//347/212/266/346/200/201/347/256/241/347/220/206V1/345/220/221V2/350/277/201/347/247/273/344/270/216/346/267/267/347/224/250/346/214/207/345/257/274.md +840 -0
- package/skills/hmos-incremental-ui-align/references/State_Model_Template.md +74 -0
- package/skills/hmos-incremental-ui-align/references/UI_Analysis_Template.md +34 -4
- package/skills/hmos-incremental-ui-align/references/android-to-harmonyOS-ui-atomic-component-mapping-reference.md +2533 -2533
- package/skills/hmos-incremental-ui-align/references/android-to-harmonyOS-ui-interaction-mapping-reference.md +555 -555
- package/skills/hmos-incremental-ui-align/references/android-to-harmonyOS-ui-layout-mapping-reference.md +117 -117
- package/skills/hmos-incremental-ui-align/scripts/app_feature_verify.ts +937 -0
- package/skills/hmos-incremental-ui-align/scripts/extract_checklist.ts +343 -0
- package/skills/hmos-incremental-ui-align/scripts/navigation-capure.md +44 -5
- package/skills/hmos-incremental-ui-align/scripts/page_capture.ts +977 -0
- package/skills/hmos-incremental-ui-align/scripts/page_capture_burst.ts +188 -0
- package/skills/hmos-integration-test/README.md +61 -70
- package/skills/hmos-integration-test/SKILL.md +128 -111
- package/skills/hmos-resources-convert/SKILL.md +334 -66
- package/skills/hmos-resources-convert/references/code-vector-icon-rules.md +335 -0
- package/skills/hmos-resources-convert/references/conversion-rules.md +676 -663
- package/skills/hmos-resources-convert/references/dependency-analysis-rules.md +410 -388
- package/skills/hmos-resources-convert/references/lottie-conversion-rules.md +219 -0
- package/skills/hmos-resources-convert/references/resource-mapping-rules.md +482 -457
- package/skills/hmos-resources-convert/references/xml-drawable-to-svg-rules.md +592 -513
- package/skills/hmos-resources-convert/scripts/a2h_resource_convert.ts +2163 -0
- package/skills/hmos-resources-convert/scripts/code_vector_icons.ts +591 -0
- package/skills/hmos-resources-convert/scripts/svg_fidelity_check.ts +632 -0
- package/skills/hmos-spec-generate/SKILL.md +293 -214
- package/skills/hmos-spec-generate/scripts/parse_requirements.ts +515 -0
- package/skills/hmos-spec-generate/template/REQ.txt +22 -0
- package/skills/hmos-spec-generate/template/REQ.xlsx +0 -0
- package/skills/hmos-test-case-generation/README.md +241 -0
- package/skills/hmos-test-case-generation/SKILL.md +324 -0
- package/skills/hmos-test-case-generation/references/contract.md +315 -0
- package/skills/hmos-test-case-generation/references/review-notes-template.md +84 -0
- package/skills/hmos-test-case-generation/references/ui-elements-schema.md +142 -0
- package/skills/hmos-test-case-generation/tools/convert_to_ui_elements.ts +550 -0
- package/skills/hmos-test-case-generation/tools/validate.ts +1312 -0
- package/tools/bfs-crawl/README.md +73 -0
- package/tools/bfs-crawl/android_viewtree_bfs_crawler.ts +1662 -0
- package/tools/test-tools/autotest/config.ts +175 -0
- package/tools/test-tools/autotest/deps/autotest-agent-0.1.1.tgz +0 -0
- package/tools/test-tools/autotest/docs/README.md +266 -0
- package/tools/test-tools/autotest/{testcases_schema.md → docs/testcases_schema.md} +1 -1
- package/tools/test-tools/autotest/engine/batch-launcher.ts +327 -0
- package/tools/test-tools/autotest/engine/report-tool.ts +773 -0
- package/tools/test-tools/autotest/engine/self-test-runner.ts +961 -0
- package/tools/test-tools/autotest/engine/testcases-tool.ts +246 -0
- package/tools/test-tools/autotest/paths.ts +41 -0
- package/tools/test-tools/autotest/resolve-metadata-tool.ts +143 -0
- package/tools/test-tools/autotest/runner/logger.ts +45 -0
- package/tools/test-tools/autotest/runner/process-utils.ts +41 -0
- package/tools/test-tools/autotest/validate.ts +167 -0
- package/agents/build-fixer.md +0 -385
- package/agents/logic-coder/scripts/platform_context_query.py +0 -568
- package/agents/review-fixer.md +0 -405
- package/agents/spec-generator.md +0 -541
- package/dist/cli/mcp-setup.js +0 -258
- package/dist/cli/mcp.js +0 -94
- package/dist/context/index.js +0 -694
- package/resource/migration_process.svg +0 -94
- package/resource/migration_process_transparent.svg +0 -93
- package/skills/hmos-batch-ui-align/scripts/android_parse_fast.py +0 -1606
- package/skills/hmos-incremental-ui-align/scripts/__pycache__/app_feature_verify.cpython-314.pyc +0 -0
- package/skills/hmos-incremental-ui-align/scripts/app_feature_verify.py +0 -542
- package/skills/hmos-incremental-ui-align/scripts/page_capture.py +0 -597
- package/skills/hmos-resources-convert/evals/evals.json +0 -171
- package/skills/hmos-resources-convert/template/AppScope/app.json5 +0 -10
- package/skills/hmos-resources-convert/template/AppScope/resources/base/element/string.json +0 -8
- package/skills/hmos-resources-convert/template/AppScope/resources/base/media/background.png +0 -0
- package/skills/hmos-resources-convert/template/AppScope/resources/base/media/foreground.png +0 -0
- package/skills/hmos-resources-convert/template/AppScope/resources/base/media/layered_image.json +0 -7
- package/skills/hmos-resources-convert/template/build-profile.json5 +0 -42
- package/skills/hmos-resources-convert/template/code-linter.json5 +0 -32
- package/skills/hmos-resources-convert/template/entry/build-profile.json5 +0 -33
- package/skills/hmos-resources-convert/template/entry/hvigorfile.ts +0 -6
- package/skills/hmos-resources-convert/template/entry/obfuscation-rules.txt +0 -23
- package/skills/hmos-resources-convert/template/entry/oh-package.json5 +0 -10
- package/skills/hmos-resources-convert/template/entry/src/main/ets/entryability/EntryAbility.ets +0 -48
- package/skills/hmos-resources-convert/template/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +0 -16
- package/skills/hmos-resources-convert/template/entry/src/main/ets/pages/Index.ets +0 -23
- package/skills/hmos-resources-convert/template/entry/src/main/module.json5 +0 -55
- package/skills/hmos-resources-convert/template/entry/src/main/resources/base/element/color.json +0 -8
- package/skills/hmos-resources-convert/template/entry/src/main/resources/base/element/float.json +0 -8
- package/skills/hmos-resources-convert/template/entry/src/main/resources/base/element/string.json +0 -16
- package/skills/hmos-resources-convert/template/entry/src/main/resources/base/media/background.png +0 -0
- package/skills/hmos-resources-convert/template/entry/src/main/resources/base/media/foreground.png +0 -0
- package/skills/hmos-resources-convert/template/entry/src/main/resources/base/media/layered_image.json +0 -7
- package/skills/hmos-resources-convert/template/entry/src/main/resources/base/media/startIcon.png +0 -0
- package/skills/hmos-resources-convert/template/entry/src/main/resources/base/profile/backup_config.json +0 -3
- package/skills/hmos-resources-convert/template/entry/src/main/resources/base/profile/main_pages.json +0 -5
- package/skills/hmos-resources-convert/template/entry/src/main/resources/dark/element/color.json +0 -8
- package/skills/hmos-resources-convert/template/entry/src/mock/mock-config.json5 +0 -2
- package/skills/hmos-resources-convert/template/entry/src/ohosTest/ets/test/Ability.test.ets +0 -35
- package/skills/hmos-resources-convert/template/entry/src/ohosTest/ets/test/List.test.ets +0 -5
- package/skills/hmos-resources-convert/template/entry/src/ohosTest/module.json5 +0 -16
- package/skills/hmos-resources-convert/template/entry/src/test/List.test.ets +0 -5
- package/skills/hmos-resources-convert/template/entry/src/test/LocalUnit.test.ets +0 -33
- package/skills/hmos-resources-convert/template/hvigor/hvigor-config.json5 +0 -23
- package/skills/hmos-resources-convert/template/hvigorfile.ts +0 -6
- package/skills/hmos-resources-convert/template/oh-package-lock.json5 +0 -28
- package/skills/hmos-resources-convert/template/oh-package.json5 +0 -10
- package/skills/hmos-resources-convert/tools/apktool.bat +0 -85
- package/skills/hmos-resources-convert/tools/apktool_3.0.1.jar +0 -0
- package/skills/hmos-spec-generate/references/android-platform-tokens.md +0 -105
- package/skills/hmos-spec-generate/references/spec-sample-1.md +0 -78
- package/skills/hmos-spec-generate/references/spec-sample-2.md +0 -58
- package/skills/hmos-spec-generate/references/spec-sample-3.md +0 -116
- package/skills/hmos-spec-generate/references/step4-report-template.md +0 -33
- package/tools/test-tools/autotest/README.md +0 -238
- package/tools/test-tools/autotest/pyproject.toml +0 -26
- package/tools/test-tools/autotest/report_tool.py +0 -759
- package/tools/test-tools/autotest/self_test_runner.py +0 -895
- package/tools/test-tools/autotest/testcases_tool.py +0 -215
- package/tools/test-tools/autotest/uv.lock +0 -3156
- package/tools/test-tools/harmony_autotest-0.1.0-py3-none-any.whl +0 -0
- package/tools/test-tools/hypium-6.1.0.210-py3-none-any.whl +0 -0
- package/tools/test-tools/hypium_mcp-0.6.5-py3-none-any.whl +0 -0
- package/tools/test-tools/xdevice-6.1.0.210-py3-none-any.whl +0 -0
- package/tools/test-tools/xdevice_devicetest-6.1.0.210-py3-none-any.whl +0 -0
- package/tools/test-tools/xdevice_ohos-6.1.0.210-py3-none-any.whl +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
# 管理应用拥有的状态概述
|
|
2
|
-
|
|
3
|
-
在管理组件拥有的状态章节中介绍的装饰器仅能在页面内,即一个组件树上共享状态变量。如果开发者要实现应用级的,或者多个页面的状态数据共享,就需要用到应用级别的状态管理的概念。ArkTS根据不同特性,提供了多种应用状态管理的能力:
|
|
4
|
-
|
|
5
|
-
- [LocalStorage](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/arkts-localstorage):页面级UI状态存储,通常用于[UIAbility](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-app-ability-uiability)内、页面间的状态共享。
|
|
6
|
-
|
|
7
|
-
- [AppStorage](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/arkts-appstorage):特殊的单例LocalStorage对象,由UI框架在应用程序启动时创建,为应用程序UI状态属性提供中央存储。
|
|
8
|
-
|
|
9
|
-
- [PersistentStorage](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/arkts-persiststorage):持久化存储UI状态,通常和AppStorage配合使用,选择AppStorage存储的数据写入磁盘,以确保这些属性在应用程序重新启动时的值与应用程序关闭时的值相同。
|
|
10
|
-
|
|
11
|
-
- [Environment](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/arkts-environment):应用程序运行的设备的环境参数,环境参数会同步到AppStorage中,可以和AppStorage搭配使用。
|
|
1
|
+
# 管理应用拥有的状态概述
|
|
2
|
+
|
|
3
|
+
在管理组件拥有的状态章节中介绍的装饰器仅能在页面内,即一个组件树上共享状态变量。如果开发者要实现应用级的,或者多个页面的状态数据共享,就需要用到应用级别的状态管理的概念。ArkTS根据不同特性,提供了多种应用状态管理的能力:
|
|
4
|
+
|
|
5
|
+
- [LocalStorage](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/arkts-localstorage):页面级UI状态存储,通常用于[UIAbility](https://developer.huawei.com/consumer/cn/doc/harmonyos-references/js-apis-app-ability-uiability)内、页面间的状态共享。
|
|
6
|
+
|
|
7
|
+
- [AppStorage](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/arkts-appstorage):特殊的单例LocalStorage对象,由UI框架在应用程序启动时创建,为应用程序UI状态属性提供中央存储。
|
|
8
|
+
|
|
9
|
+
- [PersistentStorage](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/arkts-persiststorage):持久化存储UI状态,通常和AppStorage配合使用,选择AppStorage存储的数据写入磁盘,以确保这些属性在应用程序重新启动时的值与应用程序关闭时的值相同。
|
|
10
|
+
|
|
11
|
+
- [Environment](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/arkts-environment):应用程序运行的设备的环境参数,环境参数会同步到AppStorage中,可以和AppStorage搭配使用。
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
在状态管理V1中,推荐使用[$$](../$$语法:系统组件双向同步/arkts-two-way-sync.md)实现系统组件的双向绑定。
|
|
2
|
+
|
|
3
|
+
在状态管理V2中,推荐使用!!语法糖统一处理双向绑定。
|
|
4
|
+
|
|
5
|
+
说明
|
|
6
|
+
|
|
7
|
+
!!语法从API version 12开始支持。
|
|
8
|
+
|
|
9
|
+
## 概述
|
|
10
|
+
|
|
11
|
+
!!双向绑定语法,是一个语法糖方便开发者实现数据双向绑定,用于初始化子组件的[@Param](../../状态管理(V2)/管理组件拥有的状态/@Param:组件外部输入/arkts-new-param.md)和[@Event](../../状态管理(V2)/管理组件拥有的状态/@Event装饰器:规范组件输出/arkts-new-event.md)。其中@Event方法名需要声明为“$”+ @Param属性名,详见[使用场景](arkts-new-binding.md#使用场景)。
|
|
12
|
+
|
|
13
|
+
* 如果使用了!!双向绑定语法,表明父组件的变化会同步给子组件,子组件的变化也会同步给父组件。
|
|
14
|
+
* 父组件未使用!!时,变化是单向的。
|
|
15
|
+
|
|
16
|
+
## 使用场景
|
|
17
|
+
|
|
18
|
+
### 自定义组件间双向绑定
|
|
19
|
+
|
|
20
|
+
1. 在Index中构造Star子组件,双向绑定父子组件中的value属性,并初始化子组件的@Param value和@Event $value。
|
|
21
|
+
|
|
22
|
+
@Param与@Event装饰器配合使用的双向绑定语法糖。
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
1. Child({ value: this.value, $value: (val: number) => { this.value = val; } })
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
[Binding\_Star\_Param\_Event.ets](https://gitcode.com/HarmonyOS_Samples/guide-snippets/blob/HarmonyOS-feature-20260402/ArkUISample/ArkUI_Binding/entry/src/main/ets/pages/Binding_Star_Param_Event.ets#L29-L31)
|
|
29
|
+
|
|
30
|
+
上述语法可以简化为!!双向绑定语法糖。
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
1. Star({ value: this.value!! })
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
[Binding\_Star.ets](https://gitcode.com/HarmonyOS_Samples/guide-snippets/blob/HarmonyOS-feature-20260402/ArkUISample/ArkUI_Binding/entry/src/main/ets/pages/Binding_Star.ets#L29-L31)
|
|
37
|
+
2. 使用@Param value与@Event $value语法实现自定义组件双向绑定。
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
1. @Entry
|
|
41
|
+
2. @ComponentV2
|
|
42
|
+
3. struct Parent {
|
|
43
|
+
4. @Local value: number = 0;
|
|
44
|
+
|
|
45
|
+
6. build() {
|
|
46
|
+
7. Column() {
|
|
47
|
+
8. Text(`${this.value}`)
|
|
48
|
+
9. // 点击Index中的Button改变value值,父组件Parent和子组件Child中的Text将同步更新。
|
|
49
|
+
10. Button(`change value in parent component`).onClick(() => {
|
|
50
|
+
11. this.value++;
|
|
51
|
+
12. })
|
|
52
|
+
13. // 使用@Param与@Event语法实现自定义组件双向绑定。
|
|
53
|
+
14. Child({ value: this.value, $value: (val: number) => { this.value = val; } })
|
|
54
|
+
15. // ...
|
|
55
|
+
16. // ···
|
|
56
|
+
17. }
|
|
57
|
+
18. }
|
|
58
|
+
19. }
|
|
59
|
+
|
|
60
|
+
21. @ComponentV2
|
|
61
|
+
22. struct Child {
|
|
62
|
+
23. @Param value: number = 0;
|
|
63
|
+
24. @Event $value: (val: number) => void = (val: number) => {};
|
|
64
|
+
|
|
65
|
+
26. build() {
|
|
66
|
+
27. Column() {
|
|
67
|
+
28. Text(`${this.value}`)
|
|
68
|
+
29. // 点击子组件Child中的Button,调用`this.$value(10)`方法,父组件Parent和子组件Child中的Text将同步更新。
|
|
69
|
+
30. Button(`change value in child component`).onClick(() => {
|
|
70
|
+
31. this.$value(10);
|
|
71
|
+
32. })
|
|
72
|
+
33. }
|
|
73
|
+
34. }
|
|
74
|
+
35. }
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
[Binding\_Star\_Param\_Event.ets](https://gitcode.com/HarmonyOS_Samples/guide-snippets/blob/HarmonyOS-feature-20260402/ArkUISample/ArkUI_Binding/entry/src/main/ets/pages/Binding_Star_Param_Event.ets#L15-L55)
|
|
78
|
+
3. 使用!!语法糖实现自定义组件双向绑定。
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
1. @Entry
|
|
82
|
+
2. @ComponentV2
|
|
83
|
+
3. struct Index {
|
|
84
|
+
4. @Local value: number = 0;
|
|
85
|
+
|
|
86
|
+
6. build() {
|
|
87
|
+
7. Column() {
|
|
88
|
+
8. Text(`${this.value}`)
|
|
89
|
+
9. // 点击Index中的Button改变value值,父组件Index和子组件Star中的Text将同步更新。
|
|
90
|
+
10. Button(`change value in parent component`).onClick(() => {
|
|
91
|
+
11. this.value++;
|
|
92
|
+
12. })
|
|
93
|
+
13. // 使用!!语法糖实现自定义组件双向绑定。
|
|
94
|
+
14. Star({ value: this.value!! })
|
|
95
|
+
15. // ...
|
|
96
|
+
16. }
|
|
97
|
+
17. }
|
|
98
|
+
18. }
|
|
99
|
+
|
|
100
|
+
20. @ComponentV2
|
|
101
|
+
21. struct Star {
|
|
102
|
+
22. @Param value: number = 0;
|
|
103
|
+
23. @Event $value: (val: number) => void = (val: number) => {};
|
|
104
|
+
|
|
105
|
+
25. build() {
|
|
106
|
+
26. Column() {
|
|
107
|
+
27. Text(`${this.value}`)
|
|
108
|
+
28. // 点击子组件Star中的Button,调用`this.$value(10)`方法,父组件Index和子组件Star中的Text将同步更新。
|
|
109
|
+
29. Button(`change value in child component`).onClick(() => {
|
|
110
|
+
30. this.$value(10);
|
|
111
|
+
31. })
|
|
112
|
+
32. }
|
|
113
|
+
33. }
|
|
114
|
+
34. }
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
[Binding\_Star.ets](https://gitcode.com/HarmonyOS_Samples/guide-snippets/blob/HarmonyOS-feature-20260402/ArkUISample/ArkUI_Binding/entry/src/main/ets/pages/Binding_Star.ets#L15-L54)
|
|
118
|
+
|
|
119
|
+
**使用限制**
|
|
120
|
+
|
|
121
|
+
* !!双向绑定语法不支持多层父子组件传递。
|
|
122
|
+
* 不支持与@Event混用。从API version 18开始,当使用!!双向绑定语法给子组件传递参数时,给对应的@Event方法传参会编译报错。
|
|
123
|
+
* 当使用3个或更多感叹号(!!!、!!!!、!!!!!等)时,不支持双向绑定功能。
|
|
124
|
+
|
|
125
|
+
### 系统组件参数双向绑定
|
|
126
|
+
|
|
127
|
+
!!运算符为系统组件提供TS变量的引用,使得TS变量和系统组件的内部状态保持同步。添加方式是在变量名后添加,例如isShow!!。
|
|
128
|
+
|
|
129
|
+
内部状态的含义由组件决定。例如:[bindMenu](../../../../../../../harmonyos-references/ArkUI(方舟UI框架)/ArkTS组件/通用属性/弹窗控制/菜单控制/ts-universal-attributes-menu.md#bindmenu11)组件的isShow参数。
|
|
130
|
+
|
|
131
|
+
```
|
|
132
|
+
1. import { hilog } from '@kit.PerformanceAnalysisKit';
|
|
133
|
+
|
|
134
|
+
3. const TAG: string = 'click show Menu';
|
|
135
|
+
4. const DOMAIN = 0xFF00;
|
|
136
|
+
|
|
137
|
+
6. @Entry
|
|
138
|
+
7. @ComponentV2
|
|
139
|
+
8. struct BindMenuInterface {
|
|
140
|
+
9. @Local isShow: boolean = false;
|
|
141
|
+
|
|
142
|
+
11. build() {
|
|
143
|
+
12. Column() {
|
|
144
|
+
13. Row() {
|
|
145
|
+
14. Text('click show Menu')
|
|
146
|
+
15. .bindMenu(this.isShow!!, // 双向绑定。
|
|
147
|
+
16. [
|
|
148
|
+
17. {
|
|
149
|
+
18. value: 'Menu1',
|
|
150
|
+
19. action: () => {
|
|
151
|
+
20. hilog.info(DOMAIN, TAG, 'handle Menu1 click');
|
|
152
|
+
21. }
|
|
153
|
+
22. },
|
|
154
|
+
23. {
|
|
155
|
+
24. value: 'Menu2',
|
|
156
|
+
25. action: () => {
|
|
157
|
+
26. hilog.info(DOMAIN, TAG, 'handle Menu2 click');
|
|
158
|
+
27. }
|
|
159
|
+
28. },
|
|
160
|
+
29. ])
|
|
161
|
+
30. }.height('50%')
|
|
162
|
+
|
|
163
|
+
32. Text('isShow: ' + this.isShow).fontSize(18).fontColor(Color.Red)
|
|
164
|
+
33. Row() {
|
|
165
|
+
34. Button('Click')
|
|
166
|
+
35. .onClick(() => {
|
|
167
|
+
36. this.isShow = true;
|
|
168
|
+
37. })
|
|
169
|
+
38. .width(100)
|
|
170
|
+
39. .fontSize(20)
|
|
171
|
+
40. .margin(10)
|
|
172
|
+
41. }
|
|
173
|
+
42. }.width('100%')
|
|
174
|
+
43. }
|
|
175
|
+
44. }
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
[Sys\_Binding.ets](https://gitcode.com/HarmonyOS_Samples/guide-snippets/blob/HarmonyOS-feature-20260402/ArkUISample/ArkUI_Binding/entry/src/main/ets/pages/Sys_Binding.ets#L15-L59)
|
|
179
|
+
|
|
180
|
+

|
|
181
|
+
|
|
182
|
+
**使用规则**
|
|
183
|
+
|
|
184
|
+
* 当前!!双向绑定支持基础类型变量,当该变量使用[@State](../../状态管理(V1)/管理组件拥有的状态/@State装饰器:组件内状态/arkts-state.md)等状态管理V1装饰器装饰,或者[@Local](../../状态管理(V2)/管理组件拥有的状态/@Local装饰器:组件内部状态/arkts-new-local.md)等状态管理V2装饰器装饰时,变量值的变化会触发UI刷新。
|
|
185
|
+
|
|
186
|
+
| 属性 | 支持的参数 | 起始API版本 |
|
|
187
|
+
| --- | --- | --- |
|
|
188
|
+
| [bindMenu](../../../../../../../harmonyos-references/ArkUI(方舟UI框架)/ArkTS组件/通用属性/弹窗控制/菜单控制/ts-universal-attributes-menu.md#bindmenu11) | isShow | 18 |
|
|
189
|
+
| [bindContextMenu](../../../../../../../harmonyos-references/ArkUI(方舟UI框架)/ArkTS组件/通用属性/弹窗控制/菜单控制/ts-universal-attributes-menu.md#bindcontextmenu12) | isShown | 18 |
|
|
190
|
+
| [bindPopup](../../../../../../../harmonyos-references/ArkUI(方舟UI框架)/ArkTS组件/通用属性/弹窗控制/Popup控制/ts-universal-attributes-popup.md#bindpopup) | show | 18 |
|
|
191
|
+
| [TextInput](../../../../../../../harmonyos-references/ArkUI(方舟UI框架)/ArkTS组件/文本与输入/TextInput/ts-basic-components-textinput.md#textinputoptions对象说明) | text | 18 |
|
|
192
|
+
| [TextArea](../../../../../../../harmonyos-references/ArkUI(方舟UI框架)/ArkTS组件/文本与输入/TextArea/ts-basic-components-textarea.md#textareaoptions对象说明) | text | 18 |
|
|
193
|
+
| [Search](../../../../../../../harmonyos-references/ArkUI(方舟UI框架)/ArkTS组件/文本与输入/Search/ts-basic-components-search.md#searchoptions18对象说明) | value | 18 |
|
|
194
|
+
| [BindSheet](../../../../../../../harmonyos-references/ArkUI(方舟UI框架)/ArkTS组件/通用属性/模态转场设置/半模态转场/ts-universal-attributes-sheet-transition.md#bindsheet) | isShow | 18 |
|
|
195
|
+
| [BindContentCover](../../../../../../../harmonyos-references/ArkUI(方舟UI框架)/ArkTS组件/通用属性/模态转场设置/全屏模态转场/ts-universal-attributes-modal-transition.md#bindcontentcover) | isShow | 18 |
|
|
196
|
+
| [SideBarContainer](../../../../../../../harmonyos-references/ArkUI(方舟UI框架)/ArkTS组件/栅格与分栏/SideBarContainer/ts-container-sidebarcontainer.md#sidebarwidth) | sideBarWidth | 18 |
|
|
197
|
+
| [Navigation](../../../../../../../harmonyos-references/ArkUI(方舟UI框架)/ArkTS组件/导航与切换/Navigation/ts-basic-components-navigation.md#navbarwidth9) | navBarWidth | 18 |
|
|
198
|
+
| [Toggle](../../../../../../../harmonyos-references/ArkUI(方舟UI框架)/ArkTS组件/按钮与选择/Toggle/ts-basic-components-toggle.md#toggleoptions18对象说明) | isOn | 18 |
|
|
199
|
+
| [Checkbox](../../../../../../../harmonyos-references/ArkUI(方舟UI框架)/ArkTS组件/按钮与选择/Checkbox/ts-basic-components-checkbox.md#select) | select | 18 |
|
|
200
|
+
| [CheckboxGroup](../../../../../../../harmonyos-references/ArkUI(方舟UI框架)/ArkTS组件/按钮与选择/CheckboxGroup/ts-basic-components-checkboxgroup.md#selectall) | selectAll | 18 |
|
|
201
|
+
| [Radio](../../../../../../../harmonyos-references/ArkUI(方舟UI框架)/ArkTS组件/按钮与选择/Radio/ts-basic-components-radio.md#checked) | checked | 18 |
|
|
202
|
+
| [Rating](../../../../../../../harmonyos-references/ArkUI(方舟UI框架)/ArkTS组件/按钮与选择/Rating/ts-basic-components-rating.md#ratingoptions18对象说明) | rating | 18 |
|
|
203
|
+
| [Slider](../../../../../../../harmonyos-references/ArkUI(方舟UI框架)/ArkTS组件/按钮与选择/Slider/ts-basic-components-slider.md#slideroptions对象说明) | value | 18 |
|
|
204
|
+
| [Select](../../../../../../../harmonyos-references/ArkUI(方舟UI框架)/ArkTS组件/按钮与选择/Select/ts-basic-components-select.md#selected) | selected | 18 |
|
|
205
|
+
| [Select](../../../../../../../harmonyos-references/ArkUI(方舟UI框架)/ArkTS组件/按钮与选择/Select/ts-basic-components-select.md#value) | value | 18 |
|
|
206
|
+
| [MenuItem](../../../../../../../harmonyos-references/ArkUI(方舟UI框架)/ArkTS组件/菜单/MenuItem/ts-basic-components-menuitem.md#selected) | selected | 18 |
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
# @Computed装饰器:计算属性
|
|
2
|
+
|
|
3
|
+
当开发者使用相同的计算逻辑重复绑定在UI上时,为了防止重复计算,可以使用@Computed计算属性。计算属性中依赖的状态变量变化时,只会计算一次。这解决了UI多次重用该属性导致的重复计算和性能问题。
|
|
4
|
+
|
|
5
|
+
```arkts
|
|
6
|
+
@Computed
|
|
7
|
+
get sum() {
|
|
8
|
+
return this.count1 + this.count2 + this.count3;
|
|
9
|
+
}
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
```arkts
|
|
13
|
+
Text(`${this.count1 + this.count2 + this.count3}`) // 计算this.count1 + this.count2 + this.count3
|
|
14
|
+
Text(`${this.count1 + this.count2 + this.count3}`) // 重复计算this.count1 + this.count2 + this.count3
|
|
15
|
+
Text(`${this.sum}`) // 读取@Computed sum的缓存值,节省上述重复计算
|
|
16
|
+
Text(`${this.sum}`) // 读取@Computed sum的缓存值,节省上述重复计算
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
在阅读本文档前,建议提前阅读:
|
|
20
|
+
- [@ComponentV2](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/arkts-create-custom-components)
|
|
21
|
+
- [@ObservedV2和@Trace](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/arkts-new-observedv2-and-trace)
|
|
22
|
+
- [@Local](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/arkts-new-local)
|
|
23
|
+
|
|
24
|
+
@Computed装饰器从API version 12开始支持。
|
|
25
|
+
从API version 12开始,该装饰器支持在元服务中使用。
|
|
26
|
+
从API version 23开始,该装饰器支持在ArkTS卡片中使用。
|
|
27
|
+
|
|
28
|
+
## 概述
|
|
29
|
+
|
|
30
|
+
@Computed为方法装饰器,装饰getter方法。@Computed会检测被计算的属性变化,当被计算的属性变化时,@Computed只会被求解一次。不建议在@Computed中修改变量,错误的使用会导致数据无法被追踪或appfreeze等问题。
|
|
31
|
+
|
|
32
|
+
但需要注意,对于简单计算,不建议使用计算属性,因为计算属性本身也有开销。对于复杂的计算,@Computed能带来性能收益。
|
|
33
|
+
|
|
34
|
+
## 装饰器说明
|
|
35
|
+
|
|
36
|
+
@Computed语法:
|
|
37
|
+
```arkts
|
|
38
|
+
@Computed
|
|
39
|
+
get varName(): T {
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
| @Computed方法装饰器 | 说明 |
|
|
45
|
+
| --- | --- |
|
|
46
|
+
| 支持类型 | getter访问器。 |
|
|
47
|
+
| 从父组件初始化 | 禁止。 |
|
|
48
|
+
| 可初始化子组件 | [@Param](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/arkts-new-param)。 |
|
|
49
|
+
| 被执行的时机 | @ComponentV2中的@Computed会在自定义组件创建的时候初始化,触发@Computed计算。@ObservedV2装饰的类中的@Computed,会在@ObservedV2装饰的类实例创建后,异步初始化,触发@Computed计算。在@Computed中计算的状态变量被改变时,计算属性会重新计算。 |
|
|
50
|
+
| 是否允许赋值 | @Computed装饰的属性是只读的,不允许赋值。 |
|
|
51
|
+
|
|
52
|
+
## 使用限制
|
|
53
|
+
|
|
54
|
+
1. @Computed为方法装饰器,仅能装饰getter方法。
|
|
55
|
+
```arkts
|
|
56
|
+
@Computed
|
|
57
|
+
get fullName() { // 正确用法
|
|
58
|
+
return this.firstName + ' ' + this.lastName;
|
|
59
|
+
}
|
|
60
|
+
@Computed val: number = 0; // 错误用法,编译时报错
|
|
61
|
+
@Computed
|
|
62
|
+
func() { // 错误用法,编译时报错
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
2. @Computed装饰的方法只有在初始化,或者其被计算的状态变量改变时,才会发生重新计算。不建议开发者在@Computed装饰的getter方法中做除获取数据外其余的逻辑操作。
|
|
67
|
+
```arkts
|
|
68
|
+
@Entry
|
|
69
|
+
@ComponentV2
|
|
70
|
+
struct Page {
|
|
71
|
+
@Local firstName: string = 'Hua';
|
|
72
|
+
@Local lastName: string = 'Li';
|
|
73
|
+
@Local showFullNameRequestCount: number = 0;
|
|
74
|
+
private fullNameRequestCount: number = 0;
|
|
75
|
+
@Computed
|
|
76
|
+
get fullName() {
|
|
77
|
+
console.info('fullName');
|
|
78
|
+
// 不建议在@Computed的计算中做赋值逻辑
|
|
79
|
+
this.fullNameRequestCount++;
|
|
80
|
+
return this.firstName + ' ' + this.lastName;
|
|
81
|
+
}
|
|
82
|
+
build() {
|
|
83
|
+
Column() {
|
|
84
|
+
Text(`${this.fullName}`)
|
|
85
|
+
Text(`${this.fullName}`)
|
|
86
|
+
Text(`count ${this.showFullNameRequestCount}`)
|
|
87
|
+
Button('get fullName').onClick(() => {
|
|
88
|
+
this.showFullNameRequestCount = this.fullNameRequestCount;
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
3. 在@Computed装饰的getter方法中,不能改变参与计算的属性,以防止重复执行计算属性导致的appfreeze。
|
|
96
|
+
```arkts
|
|
97
|
+
@Entry
|
|
98
|
+
@ComponentV2
|
|
99
|
+
struct Page {
|
|
100
|
+
@Local firstName: string = 'Hua';
|
|
101
|
+
@Local lastName: string = 'Li';
|
|
102
|
+
@Computed
|
|
103
|
+
get fullName1() {
|
|
104
|
+
console.info('fullName1');
|
|
105
|
+
this.lastName += 'a'; // 错误,不能改变参与计算的属性
|
|
106
|
+
return this.firstName + ' ' + this.lastName;
|
|
107
|
+
}
|
|
108
|
+
@Computed
|
|
109
|
+
get fullName2() {
|
|
110
|
+
console.info('fullName2');
|
|
111
|
+
this.firstName += 'a'; // 错误,不能改变参与计算的属性
|
|
112
|
+
return this.firstName + ' ' + this.lastName;
|
|
113
|
+
}
|
|
114
|
+
build() {
|
|
115
|
+
Column() {
|
|
116
|
+
Text(`${this.fullName1}`)
|
|
117
|
+
Text(`${this.fullName2}`)
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
4. @Computed不能和双向绑定!!连用,@Computed装饰的是getter访问器,不会被子组件同步,也不能被赋值。
|
|
124
|
+
```arkts
|
|
125
|
+
@ComponentV2
|
|
126
|
+
struct Child {
|
|
127
|
+
@Param double: number = 100;
|
|
128
|
+
@Event $double: (val: number) => void;
|
|
129
|
+
build() {
|
|
130
|
+
Button('ChildChange')
|
|
131
|
+
.onClick(() => {
|
|
132
|
+
this.$double(200);
|
|
133
|
+
})
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
@Entry
|
|
137
|
+
@ComponentV2
|
|
138
|
+
struct Index {
|
|
139
|
+
@Local count: number = 100;
|
|
140
|
+
@Computed
|
|
141
|
+
get double() {
|
|
142
|
+
return this.count * 2;
|
|
143
|
+
}
|
|
144
|
+
set double(newValue : number) {
|
|
145
|
+
this.count = newValue / 2;
|
|
146
|
+
}
|
|
147
|
+
build() {
|
|
148
|
+
Scroll() {
|
|
149
|
+
Column({ space: 3 }) {
|
|
150
|
+
Text(`${this.count}`)
|
|
151
|
+
Child({ double: this.double!! }) // 错误写法
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
5. @Computed为状态管理V2提供的能力,只能在@ComponentV2和@ObservedV2中使用。
|
|
159
|
+
|
|
160
|
+
6. 多个@Computed一起使用时,警惕循环求解,以防止计算过程中的死循环。
|
|
161
|
+
```arkts
|
|
162
|
+
@Local a : number = 1;
|
|
163
|
+
@Computed
|
|
164
|
+
get b() {
|
|
165
|
+
return this.a + ' ' + this.c; // 错误写法,存在循环
|
|
166
|
+
}
|
|
167
|
+
@Computed
|
|
168
|
+
get c() {
|
|
169
|
+
return this.a + ' ' + this.b; // 错误写法,存在循环
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## 使用场景
|
|
174
|
+
|
|
175
|
+
### 当被计算的属性变化时,@Computed装饰的getter访问器只会被求解一次
|
|
176
|
+
|
|
177
|
+
**1. 在自定义组件中使用计算属性**
|
|
178
|
+
|
|
179
|
+
点击第一个Button改变lastName,触发@Computed fullName重新计算。this.fullName被绑定在两个Text组件上,计算只发生了一次。
|
|
180
|
+
|
|
181
|
+
```arkts
|
|
182
|
+
import { hilog } from '@kit.PerformanceAnalysisKit';
|
|
183
|
+
const TAG = '[Sample_Textcomponent]';
|
|
184
|
+
const DOMAIN = 0xF811;
|
|
185
|
+
const BUNDLE = 'Textcomponent_';
|
|
186
|
+
|
|
187
|
+
@Entry
|
|
188
|
+
@ComponentV2
|
|
189
|
+
struct CustomComponentUse {
|
|
190
|
+
@Local firstName: string = 'Li';
|
|
191
|
+
@Local lastName: string = 'Hua';
|
|
192
|
+
age: number = 20;
|
|
193
|
+
@Computed
|
|
194
|
+
get fullName() {
|
|
195
|
+
hilog.info(DOMAIN, TAG, BUNDLE + '---------Computed----------');
|
|
196
|
+
return this.firstName + ' ' + this.lastName + this.age;
|
|
197
|
+
}
|
|
198
|
+
build() {
|
|
199
|
+
Column() {
|
|
200
|
+
Text(this.lastName + ' ' + this.firstName)
|
|
201
|
+
Text(this.lastName + ' ' + this.firstName)
|
|
202
|
+
Divider()
|
|
203
|
+
Text(this.fullName)
|
|
204
|
+
Text(this.fullName)
|
|
205
|
+
Button('changed lastName')
|
|
206
|
+
.onClick(() => {
|
|
207
|
+
this.lastName += 'a';
|
|
208
|
+
})
|
|
209
|
+
Button('changed age')
|
|
210
|
+
.onClick(() => {
|
|
211
|
+
this.age++; // 无法触发Computed
|
|
212
|
+
})
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
计算属性本身会带来性能开销,在实际应用开发中需要注意:
|
|
219
|
+
- 对于简单的计算逻辑,可以不使用计算属性。
|
|
220
|
+
- 如果计算逻辑在视图中仅使用一次,则不使用计算属性,直接求解。
|
|
221
|
+
|
|
222
|
+
**2. 在@ObservedV2装饰的类中使用计算属性**
|
|
223
|
+
|
|
224
|
+
点击Button改变lastName,触发@Computed fullName重新计算,且只被计算一次。
|
|
225
|
+
|
|
226
|
+
```arkts
|
|
227
|
+
import { hilog } from '@kit.PerformanceAnalysisKit';
|
|
228
|
+
const TAG = '[Sample_Textcomponent]';
|
|
229
|
+
const DOMAIN = 0xF811;
|
|
230
|
+
const BUNDLE = 'Textcomponent_';
|
|
231
|
+
|
|
232
|
+
@ObservedV2
|
|
233
|
+
class Name {
|
|
234
|
+
@Trace public firstName: string = 'Hua';
|
|
235
|
+
@Trace public lastName: string = 'Li';
|
|
236
|
+
@Computed
|
|
237
|
+
get fullName() {
|
|
238
|
+
hilog.info(DOMAIN, TAG, BUNDLE + '---------Computed----------');
|
|
239
|
+
return this.firstName + ' ' + this.lastName;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const name: Name = new Name();
|
|
244
|
+
@Entry
|
|
245
|
+
@ComponentV2
|
|
246
|
+
struct ObservedV2ClassUser {
|
|
247
|
+
name1: Name = name;
|
|
248
|
+
build() {
|
|
249
|
+
Column() {
|
|
250
|
+
Text(this.name1.fullName)
|
|
251
|
+
Text(this.name1.fullName)
|
|
252
|
+
Button('changed lastName').onClick(() => {
|
|
253
|
+
this.name1.lastName += 'a';
|
|
254
|
+
})
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
### @Computed装饰的属性可以被@Monitor监听变化
|
|
261
|
+
|
|
262
|
+
使用计算属性求解fahrenheit和kelvin:
|
|
263
|
+
|
|
264
|
+
```arkts
|
|
265
|
+
import { hilog } from '@kit.PerformanceAnalysisKit';
|
|
266
|
+
const TAG = '[Sample_Textcomponent]';
|
|
267
|
+
const DOMAIN = 0xF811;
|
|
268
|
+
const BUNDLE = 'Textcomponent_';
|
|
269
|
+
|
|
270
|
+
@Entry
|
|
271
|
+
@ComponentV2
|
|
272
|
+
struct ComputedPropertyResolution {
|
|
273
|
+
@Local celsius: number = 20;
|
|
274
|
+
@Computed
|
|
275
|
+
get fahrenheit(): number {
|
|
276
|
+
return this.celsius * 9 / 5 + 32;
|
|
277
|
+
}
|
|
278
|
+
@Computed
|
|
279
|
+
get kelvin(): number {
|
|
280
|
+
return (this.fahrenheit - 32) * 5 / 9 + 273.15;
|
|
281
|
+
}
|
|
282
|
+
@Monitor('kelvin')
|
|
283
|
+
onKelvinMonitor(mon: IMonitor) {
|
|
284
|
+
hilog.info(DOMAIN, TAG, BUNDLE + 'kelvin changed from' + mon.value()?.before + ' to ' + mon.value()?.now);
|
|
285
|
+
}
|
|
286
|
+
build() {
|
|
287
|
+
Column({ space: 20 }) {
|
|
288
|
+
Row({ space: 20 }) {
|
|
289
|
+
Button('-')
|
|
290
|
+
.onClick(() => {
|
|
291
|
+
this.celsius--;
|
|
292
|
+
})
|
|
293
|
+
Text(`Celsius ${this.celsius.toFixed(1)}`).fontSize(40)
|
|
294
|
+
Button('+')
|
|
295
|
+
.onClick(() => {
|
|
296
|
+
this.celsius++;
|
|
297
|
+
})
|
|
298
|
+
}
|
|
299
|
+
Text(`Fahrenheit ${this.fahrenheit.toFixed(2)}`).fontSize(40)
|
|
300
|
+
Text(`Kelvin ${this.kelvin.toFixed(2)}`).fontSize(40)
|
|
301
|
+
}
|
|
302
|
+
.width('100%')
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
### @Computed装饰的属性可以初始化@Param
|
|
308
|
+
|
|
309
|
+
使用@Computed初始化@Param:
|
|
310
|
+
|
|
311
|
+
```arkts
|
|
312
|
+
@ObservedV2
|
|
313
|
+
class Article {
|
|
314
|
+
@Trace public quantity: number = 0;
|
|
315
|
+
public unitPrice: number = 0;
|
|
316
|
+
constructor(quantity: number, unitPrice: number) {
|
|
317
|
+
this.quantity = quantity;
|
|
318
|
+
this.unitPrice = unitPrice;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
@Entry
|
|
323
|
+
@ComponentV2
|
|
324
|
+
struct ComputingInitParam {
|
|
325
|
+
@Local shoppingBasket: Article[] = [new Article(1, 20), new Article(5, 2)];
|
|
326
|
+
@Computed
|
|
327
|
+
get total(): number {
|
|
328
|
+
return this.shoppingBasket.reduce((acc: number, item: Article) => acc + (item.quantity * item.unitPrice), 0);
|
|
329
|
+
}
|
|
330
|
+
@Computed
|
|
331
|
+
get qualifiesForDiscount(): boolean {
|
|
332
|
+
return this.total >= 100;
|
|
333
|
+
}
|
|
334
|
+
build() {
|
|
335
|
+
Column() {
|
|
336
|
+
Text(`Shopping List: `)
|
|
337
|
+
.fontSize(30)
|
|
338
|
+
ForEach(this.shoppingBasket, (item: Article) => {
|
|
339
|
+
Row() {
|
|
340
|
+
Text(`unitPrice: ${item.unitPrice}`)
|
|
341
|
+
Button('-')
|
|
342
|
+
.onClick(() => {
|
|
343
|
+
if (item.quantity > 0) {
|
|
344
|
+
item.quantity--;
|
|
345
|
+
}
|
|
346
|
+
})
|
|
347
|
+
Text(`quantity: ${item.quantity}`)
|
|
348
|
+
Button('+')
|
|
349
|
+
.onClick(() => {
|
|
350
|
+
item.quantity++;
|
|
351
|
+
})
|
|
352
|
+
}
|
|
353
|
+
Divider()
|
|
354
|
+
})
|
|
355
|
+
Child({ total: this.total, qualifiesForDiscount: this.qualifiesForDiscount })
|
|
356
|
+
}.alignItems(HorizontalAlign.Start)
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
@ComponentV2
|
|
361
|
+
struct Child {
|
|
362
|
+
@Param total: number = 0;
|
|
363
|
+
@Param qualifiesForDiscount: boolean = false;
|
|
364
|
+
build() {
|
|
365
|
+
Row() {
|
|
366
|
+
Text(`Total: ${this.total} `)
|
|
367
|
+
.fontSize(30)
|
|
368
|
+
Text(`Discount: ${this.qualifiesForDiscount} `)
|
|
369
|
+
.fontSize(30)
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
```
|