deveco-harness 0.1.0

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.
Files changed (135) hide show
  1. package/README.en.md +71 -0
  2. package/README.md +71 -0
  3. package/deveco-harness.example.jsonc +32 -0
  4. package/dist/index.js +758 -0
  5. package/package.json +48 -0
  6. package/prompts/build.txt +164 -0
  7. package/prompts/plan.txt +118 -0
  8. package/skills/arkts-error-fixes/README.md +151 -0
  9. package/skills/arkts-error-fixes/SKILL.md +150 -0
  10. package/skills/arkts-error-fixes/assets/AnyTypeError.ets +269 -0
  11. package/skills/arkts-error-fixes/assets/AppStorageError.ets +22 -0
  12. package/skills/arkts-error-fixes/assets/ArrowFunctionConversionError.ets +42 -0
  13. package/skills/arkts-error-fixes/assets/AvoidAreaTypeError.ets +43 -0
  14. package/skills/arkts-error-fixes/assets/BreakpointTypeError.ets +71 -0
  15. package/skills/arkts-error-fixes/assets/CatchClauseTypeError.ets +54 -0
  16. package/skills/arkts-error-fixes/assets/ColorConsistencyError.ets +88 -0
  17. package/skills/arkts-error-fixes/assets/ColorPropertyError.ets +39 -0
  18. package/skills/arkts-error-fixes/assets/ContextTypeError.ets +105 -0
  19. package/skills/arkts-error-fixes/assets/DecoratorStateError.ets +64 -0
  20. package/skills/arkts-error-fixes/assets/DisplayListenerTypeError.ets +129 -0
  21. package/skills/arkts-error-fixes/assets/DuplicateEntryError.ets +35 -0
  22. package/skills/arkts-error-fixes/assets/ESObjectTypeError.ets +137 -0
  23. package/skills/arkts-error-fixes/assets/FontColorPropertyError.ets +42 -0
  24. package/skills/arkts-error-fixes/assets/FunctionReturnTypeError.ets +41 -0
  25. package/skills/arkts-error-fixes/assets/IDataSourceError.ets +79 -0
  26. package/skills/arkts-error-fixes/assets/ImplementationNotAllowedError.ets +38 -0
  27. package/skills/arkts-error-fixes/assets/InterfaceMethodSignatureError.ets +43 -0
  28. package/skills/arkts-error-fixes/assets/NotificationError.ets +34 -0
  29. package/skills/arkts-error-fixes/assets/ObjectLiteralInterfaceError.ets +49 -0
  30. package/skills/arkts-error-fixes/assets/ObjectLiteralTypeError.ets +54 -0
  31. package/skills/arkts-error-fixes/assets/ObjectSpreadError.ets +29 -0
  32. package/skills/arkts-error-fixes/assets/PossiblyNullError.ets +32 -0
  33. package/skills/arkts-error-fixes/assets/ResourceConversionError.ets +159 -0
  34. package/skills/arkts-error-fixes/assets/StandaloneFunctionContext.ets +116 -0
  35. package/skills/arkts-error-fixes/assets/StandaloneFunctionError.ets +85 -0
  36. package/skills/arkts-error-fixes/assets/StorageLinkDefaultError.ets +41 -0
  37. package/skills/arkts-error-fixes/assets/TitleButtonRectTypeError.ets +86 -0
  38. package/skills/arkts-error-fixes/assets/UnusedVariableWarning.ets +102 -0
  39. package/skills/arkts-error-fixes/assets/UtilityTypeError.ets +176 -0
  40. package/skills/arkts-error-fixes/assets/WindowRectSizeError.ets +65 -0
  41. package/skills/arkts-error-fixes/assets/WindowTypeError.ets +37 -0
  42. package/skills/arkts-error-fixes/reference/any_type_errors.md +433 -0
  43. package/skills/arkts-error-fixes/reference/appstorage_errors.md +95 -0
  44. package/skills/arkts-error-fixes/reference/arrow_function_conversion_errors.md +163 -0
  45. package/skills/arkts-error-fixes/reference/avoid_area_type_errors.md +59 -0
  46. package/skills/arkts-error-fixes/reference/breakpoint_type_errors.md +122 -0
  47. package/skills/arkts-error-fixes/reference/catch_clause_type_errors.md +89 -0
  48. package/skills/arkts-error-fixes/reference/color_consistency_errors.md +209 -0
  49. package/skills/arkts-error-fixes/reference/color_property_errors.md +136 -0
  50. package/skills/arkts-error-fixes/reference/context_type_errors.md +260 -0
  51. package/skills/arkts-error-fixes/reference/decorator_state_errors.md +109 -0
  52. package/skills/arkts-error-fixes/reference/display_listener_type_errors.md +149 -0
  53. package/skills/arkts-error-fixes/reference/duplicate_entry_errors.md +193 -0
  54. package/skills/arkts-error-fixes/reference/esobject_type_errors.md +110 -0
  55. package/skills/arkts-error-fixes/reference/fontcolor_property_errors.md +104 -0
  56. package/skills/arkts-error-fixes/reference/function_return_type_errors.md +194 -0
  57. package/skills/arkts-error-fixes/reference/idata_source_errors.md +77 -0
  58. package/skills/arkts-error-fixes/reference/implementation_not_allowed_errors.md +191 -0
  59. package/skills/arkts-error-fixes/reference/interface_method_signature_errors.md +143 -0
  60. package/skills/arkts-error-fixes/reference/notification_errors.md +110 -0
  61. package/skills/arkts-error-fixes/reference/object_literal_interface_errors.md +156 -0
  62. package/skills/arkts-error-fixes/reference/object_literal_type_errors.md +110 -0
  63. package/skills/arkts-error-fixes/reference/object_spread_errors.md +105 -0
  64. package/skills/arkts-error-fixes/reference/possibly_null_errors.md +156 -0
  65. package/skills/arkts-error-fixes/reference/resource_conversion_errors.md +154 -0
  66. package/skills/arkts-error-fixes/reference/standalone_function_errors.md +68 -0
  67. package/skills/arkts-error-fixes/reference/storage_link_default_errors.md +124 -0
  68. package/skills/arkts-error-fixes/reference/title_button_rect_type_errors.md +167 -0
  69. package/skills/arkts-error-fixes/reference/unused_variable_warnings.md +295 -0
  70. package/skills/arkts-error-fixes/reference/utility_type_errors.md +290 -0
  71. package/skills/arkts-error-fixes/reference/window_rect_size_errors.md +70 -0
  72. package/skills/arkts-error-fixes/reference/window_type_errors.md +95 -0
  73. package/skills/arkts-grammar-standards/SKILL.md +71 -0
  74. package/skills/arkts-grammar-standards/references/basic-syntax.md +103 -0
  75. package/skills/arkts-grammar-standards/references/restrictions.md +100 -0
  76. package/skills/arkts-grammar-standards/references/topic-aliases.json +93 -0
  77. package/skills/arkts-grammar-standards/references/ts-diff.md +108 -0
  78. package/skills/arkts-runtime-fix/SKILL.md +152 -0
  79. package/skills/arkts-runtime-fix/SKILL_CN.md +123 -0
  80. package/skills/arkts-runtime-fix/evals/evals.json +17 -0
  81. package/skills/arkts-runtime-fix/scripts/collect-hilog.mjs +116 -0
  82. package/skills/arkts-runtime-fix/scripts/collect-hilog.ts +115 -0
  83. package/skills/arkts-runtime-fix/scripts/fetch-faultlog.mjs +117 -0
  84. package/skills/arkts-runtime-fix/scripts/fetch-faultlog.ts +116 -0
  85. package/skills/arkts-runtime-fix/scripts/jscrash-report.mjs +149 -0
  86. package/skills/arkts-runtime-fix/scripts/parse-jscrash-log.mjs +126 -0
  87. package/skills/arkts-runtime-fix/scripts/parse-jscrash-log.ts +126 -0
  88. package/skills/arkts-runtime-fix/scripts/probe-faultlogger.mjs +160 -0
  89. package/skills/arkts-runtime-fix/scripts/probe-faultlogger.ts +160 -0
  90. package/skills/arkts-runtime-fix/scripts/shared/hdc.mjs +107 -0
  91. package/skills/arkts-runtime-fix/scripts/shared/hdc.ts +58 -0
  92. package/skills/arkts-runtime-fix/scripts/shared/jscrash-faultlogger.mjs +143 -0
  93. package/skills/arkts-runtime-fix/scripts/shared/jscrash-faultlogger.ts +148 -0
  94. package/skills/arkts-runtime-fix/scripts/shared/jscrash-parse.mjs +389 -0
  95. package/skills/arkts-runtime-fix/scripts/shared/jscrash-parse.ts +409 -0
  96. package/skills/arkts-runtime-fix/scripts/shared/utils.mjs +27 -0
  97. package/skills/arkts-runtime-fix/scripts/shared/utils.ts +27 -0
  98. package/skills/arkui-knowledge/SKILL.md +90 -0
  99. package/skills/arkui-knowledge/references/api-guardrails.md +60 -0
  100. package/skills/arkui-knowledge/references/common-mistakes.md +119 -0
  101. package/skills/arkui-knowledge/references/component-cookbook.md +135 -0
  102. package/skills/arkui-knowledge/references/ui-quality-checklist.md +36 -0
  103. package/skills/deveco-create-project/SKILL.md +144 -0
  104. package/skills/deveco-create-project/application/AppScope/app.json5 +10 -0
  105. package/skills/deveco-create-project/application/AppScope/resources/base/element/string.json +8 -0
  106. package/skills/deveco-create-project/application/AppScope/resources/base/media/background.png +0 -0
  107. package/skills/deveco-create-project/application/AppScope/resources/base/media/foreground.png +0 -0
  108. package/skills/deveco-create-project/application/AppScope/resources/base/media/layered_image.json +7 -0
  109. package/skills/deveco-create-project/application/build-profile.json5 +42 -0
  110. package/skills/deveco-create-project/application/code-linter.json5 +32 -0
  111. package/skills/deveco-create-project/application/entry/build-profile.json5 +33 -0
  112. package/skills/deveco-create-project/application/entry/hvigorfile.ts +7 -0
  113. package/skills/deveco-create-project/application/entry/obfuscation-rules.txt +23 -0
  114. package/skills/deveco-create-project/application/entry/oh-package.json5 +10 -0
  115. package/skills/deveco-create-project/application/entry/src/main/ets/entryability/EntryAbility.ets +63 -0
  116. package/skills/deveco-create-project/application/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +31 -0
  117. package/skills/deveco-create-project/application/entry/src/main/ets/pages/Index.ets +38 -0
  118. package/skills/deveco-create-project/application/entry/src/main/module.json5 +50 -0
  119. package/skills/deveco-create-project/application/entry/src/main/resources/base/element/color.json +8 -0
  120. package/skills/deveco-create-project/application/entry/src/main/resources/base/element/float.json +8 -0
  121. package/skills/deveco-create-project/application/entry/src/main/resources/base/element/string.json +16 -0
  122. package/skills/deveco-create-project/application/entry/src/main/resources/base/media/background.png +0 -0
  123. package/skills/deveco-create-project/application/entry/src/main/resources/base/media/foreground.png +0 -0
  124. package/skills/deveco-create-project/application/entry/src/main/resources/base/media/layered_image.json +7 -0
  125. package/skills/deveco-create-project/application/entry/src/main/resources/base/media/startIcon.png +0 -0
  126. package/skills/deveco-create-project/application/entry/src/main/resources/base/profile/backup_config.json +3 -0
  127. package/skills/deveco-create-project/application/entry/src/main/resources/base/profile/main_pages.json +5 -0
  128. package/skills/deveco-create-project/application/entry/src/main/resources/dark/element/color.json +8 -0
  129. package/skills/deveco-create-project/application/hvigor/hvigor-config.json5 +23 -0
  130. package/skills/deveco-create-project/application/hvigorfile.ts +7 -0
  131. package/skills/deveco-create-project/application/oh-package.json5 +10 -0
  132. package/skills/deveco-create-project/scripts/copy-template.mjs +216 -0
  133. package/skills/deveco-create-project/scripts/copy-template.ts +214 -0
  134. package/skills/deveco-create-project/scripts/detect-sdk.mjs +82 -0
  135. package/skills/deveco-create-project/scripts/detect-sdk.ts +95 -0
@@ -0,0 +1,59 @@
1
+ # AvoidArea Type Error
2
+
3
+ ## 错误描述
4
+
5
+ 在使用 `window.AvoidArea` 类型时,如果缺少 `visible` 属性,会导致类型错误。
6
+
7
+ ## 错误示例
8
+
9
+ ```typescript
10
+ @State avoidArea: window.AvoidArea = {
11
+ topRect: { left: 0, top: 0, width: 0, height: 0 },
12
+ bottomRect: { left: 0, top: 0, width: 0, height: 0 },
13
+ leftRect: { left: 0, top: 0, width: 0, height: 0 },
14
+ rightRect: { left: 0, top: 0, width: 0, height: 0 }
15
+ };
16
+ ```
17
+
18
+ **错误信息:**
19
+ ```
20
+ Type '{ topRect: { left: number; top: number; width: number; height: number; }; bottomRect: { left: number; top: number; width: number; height: number; }; leftRect: { left: number; top: number; width: number; height: number; }; rightRect: { left: number; top: number; width: number; height: number; }; }' is missing the following properties from type 'AvoidArea': visible
21
+ ```
22
+
23
+ ## 解决方案
24
+
25
+ 在 `AvoidArea` 对象中添加 `visible: false` 属性。
26
+
27
+ ```typescript
28
+ @State avoidArea: window.AvoidArea = {
29
+ topRect: { left: 0, top: 0, width: 0, height: 0 },
30
+ bottomRect: { left: 0, top: 0, width: 0, height: 0 },
31
+ leftRect: { left: 0, top: 0, width: 0, height: 0 },
32
+ rightRect: { left: 0, top: 0, width: 0, height: 0 },
33
+ visible: false
34
+ };
35
+ ```
36
+
37
+ ## 简单示例
38
+
39
+ ```typescript
40
+ @Entry
41
+ @Component
42
+ struct SimpleExample {
43
+ @State avoidArea: window.AvoidArea = {
44
+ topRect: { left: 0, top: 0, width: 0, height: 0 },
45
+ bottomRect: { left: 0, top: 0, width: 0, height: 0 },
46
+ leftRect: { left: 0, top: 0, width: 0, height: 0 },
47
+ rightRect: { left: 0, top: 0, width: 0, height: 0 },
48
+ visible: false
49
+ };
50
+
51
+ build() {
52
+ Text(`顶部高度: ${this.avoidArea.topRect.height}`)
53
+ }
54
+ }
55
+ ```
56
+
57
+ ## 详细代码示例
58
+
59
+ - [AvoidAreaTypeError.ets](../assets/AvoidAreaTypeError.ets) - 完整的 AvoidArea 类型使用示例,包含窗口获取和避让区域监听
@@ -0,0 +1,122 @@
1
+ # BreakpointType 类型错误
2
+
3
+ ## 错误描述
4
+
5
+ 在使用 GridRow 组件时,直接使用 `BreakpointType` 类型会导致类型不匹配错误。`BreakpointType` 是一个枚举类型,不能直接与字符串类型进行类型转换。
6
+
7
+ ## 错误示例
8
+
9
+ ```typescript
10
+ import { mediaquery, UIContext } from '@kit.ArkUI';
11
+
12
+ @Entry
13
+ @Component
14
+ struct BreakpointTypeError {
15
+ @State currentBreakpoint: string = 'sm';
16
+ private smListener: mediaquery.MediaQueryListener | null = null;
17
+ private mdListener: mediaquery.MediaQueryListener | null = null;
18
+ private lgListener: mediaquery.MediaQueryListener | null = null;
19
+
20
+ aboutToAppear() {
21
+ const mediaQuery = this.getUIContext().getMediaQuery();
22
+
23
+ this.smListener = mediaQuery.matchMediaSync('(0vp<=width<600vp)');
24
+ this.mdListener = mediaQuery.matchMediaSync('(600vp<=width<840vp)');
25
+ this.lgListener = mediaQuery.matchMediaSync('(840vp<=width)');
26
+
27
+ const smCallback = (result: mediaquery.MediaQueryResult): void => {
28
+ if (result.matches) {
29
+ this.currentBreakpoint = 'sm';
30
+ }
31
+ };
32
+ const mdCallback = (result: mediaquery.MediaQueryResult): void => {
33
+ if (result.matches) {
34
+ this.currentBreakpoint = 'md';
35
+ }
36
+ };
37
+ const lgCallback = (result: mediaquery.MediaQueryResult): void => {
38
+ if (result.matches) {
39
+ this.currentBreakpoint = 'lg';
40
+ }
41
+ };
42
+
43
+ if (this.smListener) {
44
+ this.smListener.on('change', smCallback);
45
+ }
46
+ if (this.mdListener) {
47
+ this.mdListener.on('change', mdCallback);
48
+ }
49
+ if (this.lgListener) {
50
+ this.lgListener.on('change', lgCallback);
51
+ }
52
+ }
53
+
54
+ aboutToDisappear() {
55
+ if (this.smListener) {
56
+ this.smListener.off('change');
57
+ }
58
+ if (this.mdListener) {
59
+ this.mdListener.off('change');
60
+ }
61
+ if (this.lgListener) {
62
+ this.lgListener.off('change');
63
+ }
64
+ }
65
+
66
+ build() {
67
+ Column() {
68
+ Text(`当前断点: ${this.currentBreakpoint}`)
69
+ }
70
+ }
71
+ }
72
+ ```
73
+
74
+ ## 解决方案
75
+
76
+ ### 方案一:使用字符串类型
77
+
78
+ 直接使用字符串类型来表示断点,而不是使用 `BreakpointType` 枚举类型。
79
+
80
+ ```typescript
81
+ @State currentBreakpoint: string = 'sm';
82
+ ```
83
+
84
+ ### 方案二:使用 SimpleBreakpointType
85
+
86
+ 如果需要使用类型定义,可以使用 `SimpleBreakpointType` 类型别名。
87
+
88
+ ```typescript
89
+ type SimpleBreakpointType = 'sm' | 'md' | 'lg';
90
+
91
+ @State currentBreakpoint: SimpleBreakpointType = 'sm';
92
+ ```
93
+
94
+ ## 简单示例
95
+
96
+ ```typescript
97
+ @Entry
98
+ @Component
99
+ struct BreakpointExample {
100
+ @State currentBreakpoint: string = 'sm';
101
+
102
+ build() {
103
+ if (this.currentBreakpoint === 'lg') {
104
+ Row() {
105
+ Text('lg断点布局')
106
+ }
107
+ } else if (this.currentBreakpoint === 'md') {
108
+ Column() {
109
+ Text('md断点布局')
110
+ }
111
+ } else {
112
+ Column() {
113
+ Text('sm断点布局')
114
+ }
115
+ }
116
+ }
117
+ }
118
+ ```
119
+
120
+ ## 详细代码示例
121
+
122
+ - [BreakpointTypeError.ets](../assets/BreakpointTypeError.ets) - 完整的断点类型错误修复示例,包含媒体查询监听和断点判断逻辑
@@ -0,0 +1,89 @@
1
+ # Catch Clause Variable Type Annotation Error
2
+
3
+ ## 错误描述
4
+
5
+ 在 ArkTS 中,catch 子句的变量类型注解只能使用 `any` 或 `unknown`,不能使用其他具体类型。
6
+
7
+ ## 错误示例
8
+
9
+ ```typescript
10
+ try {
11
+ await someAsyncOperation();
12
+ } catch (error: Error) {
13
+ console.error('发生错误:', error);
14
+ }
15
+ ```
16
+
17
+ **错误信息:**
18
+ ```
19
+ Catch clause variable type annotation must be 'any' or 'unknown' if specified.
20
+ ```
21
+
22
+ ## 解决方案
23
+
24
+ ### 方案1:移除类型注解(推荐)
25
+
26
+ ```typescript
27
+ try {
28
+ await someAsyncOperation();
29
+ } catch (error) {
30
+ console.error('发生错误:', error);
31
+ }
32
+ ```
33
+
34
+ ### 方案2:使用 `any` 类型
35
+
36
+ ```typescript
37
+ try {
38
+ await someAsyncOperation();
39
+ } catch (error: any) {
40
+ console.error('发生错误:', error);
41
+ }
42
+ ```
43
+
44
+ ### 方案3:使用 `unknown` 类型(更安全)
45
+
46
+ ```typescript
47
+ try {
48
+ await someAsyncOperation();
49
+ } catch (error: unknown) {
50
+ console.error('发生错误:', error);
51
+ }
52
+ ```
53
+
54
+ ## 详细说明
55
+
56
+ ArkTS 限制了 catch 子句中变量的类型注解,这是为了确保类型安全和代码的一致性。推荐的做法是:
57
+
58
+ 1. **不使用类型注解**:让 TypeScript 自动推断类型
59
+ 2. **使用 `unknown`**:如果必须使用类型注解,`unknown` 是最安全的选择,因为它要求在使用前进行类型检查
60
+ 3. **避免使用 `any`**:虽然允许,但会失去类型安全
61
+
62
+ ## 简单示例
63
+
64
+ ```typescript
65
+ import { camera } from '@kit.CameraKit';
66
+
67
+ @Entry
68
+ @Component
69
+ struct CameraExample {
70
+ private cameraManager: camera.CameraManager | null = null;
71
+
72
+ async aboutToAppear() {
73
+ try {
74
+ const context = this.getUIContext().getHostContext() as common.UIAbilityContext;
75
+ this.cameraManager = camera.getCameraManager(context);
76
+ } catch (error) {
77
+ console.error('初始化相机失败:', error);
78
+ }
79
+ }
80
+
81
+ build() {
82
+ Text('Camera Example')
83
+ }
84
+ }
85
+ ```
86
+
87
+ ## 详细代码示例
88
+
89
+ > [CatchClauseTypeError.ets](../assets/CatchClauseTypeError.ets) - 完整的 catch 子句类型注解错误示例和修复方案
@@ -0,0 +1,209 @@
1
+ # 颜色一致性错误解决方案
2
+
3
+ ## 问题描述
4
+
5
+ 在 HarmonyOS ArkUI 开发中,使用硬编码的颜色值(如 `#FFFFFF`、`#F5F5F5`)会触发编译警告:
6
+
7
+ ```
8
+ It is recommended that you use layered parameters for easier color mode switching and theme color changing.
9
+ ```
10
+
11
+ 这个警告建议使用系统颜色资源,以便更好地支持深色模式切换和主题颜色变化。
12
+
13
+ ## 问题示例
14
+
15
+ ```typescript
16
+ // ❌ 不推荐:硬编码颜色
17
+ Column() {
18
+ Text('内容')
19
+ .backgroundColor('#FFFFFF') // 警告
20
+ .fontColor('#333333') // 警告
21
+ }
22
+ ```
23
+
24
+ ## 推荐解决方案
25
+
26
+ 使用系统颜色资源 `$r('sys.color.ohos_id_color_*')` 替代硬编码颜色:
27
+
28
+ ```typescript
29
+ // ✅ 推荐:使用系统颜色资源
30
+ Column() {
31
+ Text('内容')
32
+ .backgroundColor($r('sys.color.ohos_id_color_background'))
33
+ .fontColor($r('sys.color.ohos_id_color_text_primary'))
34
+ }
35
+ ```
36
+
37
+ ## 常用系统颜色资源
38
+
39
+ | 系统颜色资源 | 用途 | 对应硬编码颜色 |
40
+ |------------|------|--------------|
41
+ | `ohos_id_color_background` | 背景色 | `#FFFFFF` |
42
+ | `ohos_id_color_sub_background` | 次级背景色 | `#F5F5F5` |
43
+ | `ohos_id_color_text_primary` | 主要文字颜色 | `#333333` |
44
+ | `ohos_id_color_text_secondary` | 次要文字颜色 | `#666666` |
45
+ | `ohos_id_color_text_tertiary` | 第三级文字颜色 | `#999999` |
46
+ | `ohos_id_color_list_separator` | 列表分割线 | `#E5E5E5` |
47
+ | `ohos_id_color_primary` | 主题主色 | `#007DFF` |
48
+ | `ohos_id_color_emphasize` | 强调色 | `#FF0000` |
49
+
50
+ ## 迁移步骤
51
+
52
+ ### 1. 识别硬编码颜色
53
+
54
+ ```typescript
55
+ // 查找代码中的硬编码颜色
56
+ .backgroundColor('#FFFFFF')
57
+ .backgroundColor('#F5F5F5')
58
+ .backgroundColor('#007DFF')
59
+ ```
60
+
61
+ ### 2. 替换为系统颜色资源
62
+
63
+ ```typescript
64
+ // 替换为对应的系统颜色
65
+ .backgroundColor($r('sys.color.ohos_id_color_background'))
66
+ .backgroundColor($r('sys.color.ohos_id_color_sub_background'))
67
+ .backgroundColor($r('sys.color.ohos_id_color_primary'))
68
+ ```
69
+
70
+ ### 3. 处理特殊颜色
71
+
72
+ 对于没有直接对应的系统颜色,可以使用 `ResourceColor` 类型:
73
+
74
+ ```typescript
75
+ // 自定义颜色
76
+ .backgroundColor('#FF5722')
77
+
78
+ // 或使用资源引用
79
+ .backgroundColor($r('app.color.custom_background'))
80
+ ```
81
+
82
+ ## 完整示例
83
+
84
+ ```typescript
85
+ @Entry
86
+ @Component
87
+ struct ColorConsistencyExample {
88
+ build() {
89
+ Column() {
90
+ // 卡片容器
91
+ Column() {
92
+ Text('标题')
93
+ .fontSize(18)
94
+ .fontWeight(FontWeight.Bold)
95
+ .fontColor($r('sys.color.ohos_id_color_text_primary'))
96
+
97
+ Text('这是内容描述')
98
+ .fontSize(14)
99
+ .fontColor($r('sys.color.ohos_id_color_text_secondary'))
100
+ .margin({ top: 8 })
101
+
102
+ Button('操作按钮')
103
+ .backgroundColor($r('sys.color.ohos_id_color_primary'))
104
+ .fontColor($r('sys.color.ohos_id_color_text_primary_contrast'))
105
+ .margin({ top: 16 })
106
+ }
107
+ .width('100%')
108
+ .padding(16)
109
+ .backgroundColor($r('sys.color.ohos_id_color_background'))
110
+ .borderRadius(8)
111
+ }
112
+ .width('100%')
113
+ .height('100%')
114
+ .padding(16)
115
+ .backgroundColor($r('sys.color.ohos_id_color_sub_background'))
116
+ }
117
+ }
118
+ ```
119
+
120
+ > [查看完整示例](../assets/ColorConsistencyError.ets)
121
+
122
+ ## 自定义颜色资源
123
+
124
+ 如果需要使用自定义颜色,可以在 `resources/base/element/color.json` 中定义:
125
+
126
+ ```json
127
+ {
128
+ "color": [
129
+ {
130
+ "name": "custom_primary",
131
+ "value": "#007DFF"
132
+ },
133
+ {
134
+ "name": "custom_background",
135
+ "value": "#F5F5F5"
136
+ }
137
+ ]
138
+ }
139
+ ```
140
+
141
+ 然后在代码中使用:
142
+
143
+ ```typescript
144
+ .backgroundColor($r('app.color.custom_primary'))
145
+ .backgroundColor($r('app.color.custom_background'))
146
+ ```
147
+
148
+ ## 深色模式适配
149
+
150
+ 使用系统颜色资源会自动适配深色模式:
151
+
152
+ ```typescript
153
+ // 浅色模式:#FFFFFF
154
+ // 深色模式:#1A1A1A
155
+ .backgroundColor($r('sys.color.ohos_id_color_background'))
156
+
157
+ // 浅色模式:#333333
158
+ // 深色模式:#E5E5E5
159
+ .fontColor($r('sys.color.ohos_id_color_text_primary'))
160
+ ```
161
+
162
+ ## 注意事项
163
+
164
+ 1. **资源引用语法**:使用 `$r('sys.color.资源名')` 或 `$r('app.color.资源名')`
165
+
166
+ 2. **系统 vs 应用**:系统颜色使用 `sys.color.*`,应用自定义颜色使用 `app.color.*`
167
+
168
+ 3. **深色模式**:系统颜色会自动适配深色模式,无需手动处理
169
+
170
+ 4. **主题切换**:系统颜色会跟随系统主题变化,提供更好的用户体验
171
+
172
+ 5. **兼容性**:系统颜色资源从 API 9 开始支持
173
+
174
+ ## 相关 API 参考
175
+
176
+ - [系统颜色资源](https://developer.harmonyos.com/cn/docs/documentation/references/arkui-ts-resource-color)
177
+ - [资源管理](https://developer.harmonyos.com/cn/docs/documentation/references/arkui-ts-resource-manager)
178
+ - [深色模式适配](https://developer.harmonyos.com/cn/docs/documentation/guides/arkui-ts-dark-mode)
179
+
180
+ ## 迁移检查清单
181
+
182
+ - [ ] 识别所有硬编码颜色值
183
+ - [ ] 将硬编码颜色替换为系统颜色资源
184
+ - [ ] 测试浅色模式下的显示效果
185
+ - [ ] 测试深色模式下的显示效果
186
+ - [ ] 验证主题切换是否正常
187
+ - [ ] 确认编译警告已消失
188
+
189
+ ## 常见问题
190
+
191
+ ### Q: 为什么要使用系统颜色资源?
192
+
193
+ A: 系统颜色资源可以自动适配深色模式和主题切换,提供更好的用户体验,同时减少维护成本。
194
+
195
+ ### Q: 所有颜色都必须使用系统资源吗?
196
+
197
+ A: 不是。对于品牌色等特殊颜色,可以使用自定义颜色资源或硬编码值。但对于通用UI元素,建议使用系统颜色。
198
+
199
+ ### Q: 如何在深色模式下使用不同的颜色?
200
+
201
+ A: 使用系统颜色资源会自动处理深色模式。如果需要自定义深色模式颜色,可以在 `resources/dark/element/color.json` 中定义。
202
+
203
+ ### Q: 可以混合使用系统颜色和硬编码颜色吗?
204
+
205
+ A: 可以,但不推荐。建议统一使用系统颜色资源以保持一致性。
206
+
207
+ ### Q: 如何查看所有可用的系统颜色资源?
208
+
209
+ A: 参考 HarmonyOS 官方文档中的系统颜色资源列表,或使用 DevEco Studio 的代码提示查看可用资源。
@@ -0,0 +1,136 @@
1
+ # Color Property Errors
2
+
3
+ ## Error: `Property 'XXX' does not exist on type 'typeof Color'`
4
+
5
+ ### Error Message
6
+ ```
7
+ Property 'LightBlue' does not exist on type 'typeof Color'
8
+ ```
9
+
10
+ ### Cause
11
+ The `Color` class in ArkTS does not have all of the color properties that might be expected. Some color names like `LightBlue`, `DarkGray`, etc. are not available. Using these properties will cause compilation errors.
12
+
13
+ ### Solution
14
+ Use hex color values (`#RRGGBB` or `#AARRGGBB`) instead of non-existent `Color` properties.
15
+
16
+ ### Key Points
17
+ - Use hex color values instead of non-existent Color properties
18
+ - Hex format: `#RRGGBB` for RGB, `#AARRGGBB` for ARGB
19
+ - Common colors: `#FF0000` (red), `#00FF00` (green), `#0000FF` (blue)
20
+ - Use layered parameters for theme-aware colors
21
+
22
+ ### Basic Pattern
23
+ ```typescript
24
+ // ❌ Wrong: Using non-existent Color property
25
+ Text('Hello')
26
+ .fontColor(Color.LightBlue)
27
+
28
+ // ✅ Correct: Using hex color value
29
+ Text('Hello')
30
+ .fontColor('#ADD8E6')
31
+ ```
32
+
33
+ ### Common Color Replacements
34
+ ```typescript
35
+ // Light colors
36
+ Color.LightBlue -> '#ADD8E6'
37
+ Color.LightGreen -> '#90EE90'
38
+ Color.LightGray -> '#D3D3D3'
39
+ Color.LightCyan -> '#E0FFFF'
40
+
41
+ // Dark colors
42
+ Color.DarkBlue -> '#00008B'
43
+ Color.DarkGreen -> '#006400'
44
+ Color.DarkGray -> '#A9A9A9'
45
+ Color.DarkCyan -> '#008B8B'
46
+
47
+ // Other colors
48
+ Color.Pink -> '#FFC0CB'
49
+ Color.Orange -> '#FFA500'
50
+ Color.Purple -> '#800080'
51
+ Color.Brown -> '#A52A2A'
52
+ Color.Gold -> '#FFD700'
53
+ Color.Silver -> '#C0C0C0'
54
+ ```
55
+
56
+ ### Common Hex Colors
57
+ ```typescript
58
+ // Primary colors
59
+ '#FF0000' // Red
60
+ '#00FF00' // Green
61
+ '#0000FF' // Blue
62
+
63
+ // Secondary colors
64
+ '#FFFF00' // Yellow
65
+ '#FF00FF' // Magenta
66
+ '#00FFFF' // Cyan
67
+
68
+ // Grayscale
69
+ '#FFFFFF' // White
70
+ '#F5F5F5' // Light gray
71
+ '#CCCCCC' // Medium gray
72
+ '#999999' // Dark gray
73
+ '#666666' // Darker gray
74
+ '#333333' // Very dark gray
75
+ '#000000' // Black
76
+
77
+ // UI colors
78
+ '#007DFF' // Primary blue
79
+ '#FF6B00' // Orange
80
+ '#00C853' // Green
81
+ '#FF1744' // Red
82
+ '#651FFF' // Purple
83
+ '#00B0FF' // Light blue
84
+ ```
85
+
86
+ ### Color Properties
87
+ ```typescript
88
+ // Text color
89
+ .fontColor('#FF0000')
90
+
91
+ // Background color
92
+ .backgroundColor('#00FF00')
93
+
94
+ // Border color
95
+ .borderColor('#0000FF')
96
+
97
+ // Shadow color
98
+ .shadow({ radius: 10, color: '#FF0000' })
99
+ ```
100
+
101
+ ### Detailed Examples
102
+ For more detailed code examples, see:
103
+ - [Basic Color Usage](../assets/ColorPropertyError.ets#L8-L12)
104
+ - [Text Color Pattern](../assets/ColorPropertyError.ets#L14-L18)
105
+ - [Background Color Pattern](../assets/ColorPropertyError.ets#L20-L24)
106
+ - [Theme Switching](../assets/ColorPropertyError.ets#L26-L36)
107
+
108
+ ### Best Practices
109
+ 1. **Use hex values**: Always use hex color values instead of non-existent Color properties
110
+ 2. **Define constants**: Create color constants for reuse
111
+ 3. **Use resources**: Use resource references for theme-aware colors
112
+ 4. **Document colors**: Add comments explaining color choices
113
+ 5. **Test contrast**: Ensure text has sufficient contrast with background
114
+
115
+ ### Common Mistakes
116
+ ```typescript
117
+ // ❌ Wrong: Using non-existent Color property
118
+ Text('Hello')
119
+ .fontColor(Color.LightBlue)
120
+
121
+ // ❌ Wrong: Using non-existent Color property
122
+ Text('Hello')
123
+ .fontColor(Color.DarkGray)
124
+
125
+ // ✅ Correct: Using hex color value
126
+ Text('Hello')
127
+ .fontColor('#ADD8E6')
128
+
129
+ // ✅ Correct: Using hex color value
130
+ Text('Hello')
131
+ .fontColor('#A9A9A9')
132
+ ```
133
+
134
+ ### Related Files
135
+ - [Code Example](../assets/ColorPropertyError.ets)
136
+ - [ArkTS UI Components](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/arkts-uicomponent)