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.
- package/README.en.md +71 -0
- package/README.md +71 -0
- package/deveco-harness.example.jsonc +32 -0
- package/dist/index.js +758 -0
- package/package.json +48 -0
- package/prompts/build.txt +164 -0
- package/prompts/plan.txt +118 -0
- package/skills/arkts-error-fixes/README.md +151 -0
- package/skills/arkts-error-fixes/SKILL.md +150 -0
- package/skills/arkts-error-fixes/assets/AnyTypeError.ets +269 -0
- package/skills/arkts-error-fixes/assets/AppStorageError.ets +22 -0
- package/skills/arkts-error-fixes/assets/ArrowFunctionConversionError.ets +42 -0
- package/skills/arkts-error-fixes/assets/AvoidAreaTypeError.ets +43 -0
- package/skills/arkts-error-fixes/assets/BreakpointTypeError.ets +71 -0
- package/skills/arkts-error-fixes/assets/CatchClauseTypeError.ets +54 -0
- package/skills/arkts-error-fixes/assets/ColorConsistencyError.ets +88 -0
- package/skills/arkts-error-fixes/assets/ColorPropertyError.ets +39 -0
- package/skills/arkts-error-fixes/assets/ContextTypeError.ets +105 -0
- package/skills/arkts-error-fixes/assets/DecoratorStateError.ets +64 -0
- package/skills/arkts-error-fixes/assets/DisplayListenerTypeError.ets +129 -0
- package/skills/arkts-error-fixes/assets/DuplicateEntryError.ets +35 -0
- package/skills/arkts-error-fixes/assets/ESObjectTypeError.ets +137 -0
- package/skills/arkts-error-fixes/assets/FontColorPropertyError.ets +42 -0
- package/skills/arkts-error-fixes/assets/FunctionReturnTypeError.ets +41 -0
- package/skills/arkts-error-fixes/assets/IDataSourceError.ets +79 -0
- package/skills/arkts-error-fixes/assets/ImplementationNotAllowedError.ets +38 -0
- package/skills/arkts-error-fixes/assets/InterfaceMethodSignatureError.ets +43 -0
- package/skills/arkts-error-fixes/assets/NotificationError.ets +34 -0
- package/skills/arkts-error-fixes/assets/ObjectLiteralInterfaceError.ets +49 -0
- package/skills/arkts-error-fixes/assets/ObjectLiteralTypeError.ets +54 -0
- package/skills/arkts-error-fixes/assets/ObjectSpreadError.ets +29 -0
- package/skills/arkts-error-fixes/assets/PossiblyNullError.ets +32 -0
- package/skills/arkts-error-fixes/assets/ResourceConversionError.ets +159 -0
- package/skills/arkts-error-fixes/assets/StandaloneFunctionContext.ets +116 -0
- package/skills/arkts-error-fixes/assets/StandaloneFunctionError.ets +85 -0
- package/skills/arkts-error-fixes/assets/StorageLinkDefaultError.ets +41 -0
- package/skills/arkts-error-fixes/assets/TitleButtonRectTypeError.ets +86 -0
- package/skills/arkts-error-fixes/assets/UnusedVariableWarning.ets +102 -0
- package/skills/arkts-error-fixes/assets/UtilityTypeError.ets +176 -0
- package/skills/arkts-error-fixes/assets/WindowRectSizeError.ets +65 -0
- package/skills/arkts-error-fixes/assets/WindowTypeError.ets +37 -0
- package/skills/arkts-error-fixes/reference/any_type_errors.md +433 -0
- package/skills/arkts-error-fixes/reference/appstorage_errors.md +95 -0
- package/skills/arkts-error-fixes/reference/arrow_function_conversion_errors.md +163 -0
- package/skills/arkts-error-fixes/reference/avoid_area_type_errors.md +59 -0
- package/skills/arkts-error-fixes/reference/breakpoint_type_errors.md +122 -0
- package/skills/arkts-error-fixes/reference/catch_clause_type_errors.md +89 -0
- package/skills/arkts-error-fixes/reference/color_consistency_errors.md +209 -0
- package/skills/arkts-error-fixes/reference/color_property_errors.md +136 -0
- package/skills/arkts-error-fixes/reference/context_type_errors.md +260 -0
- package/skills/arkts-error-fixes/reference/decorator_state_errors.md +109 -0
- package/skills/arkts-error-fixes/reference/display_listener_type_errors.md +149 -0
- package/skills/arkts-error-fixes/reference/duplicate_entry_errors.md +193 -0
- package/skills/arkts-error-fixes/reference/esobject_type_errors.md +110 -0
- package/skills/arkts-error-fixes/reference/fontcolor_property_errors.md +104 -0
- package/skills/arkts-error-fixes/reference/function_return_type_errors.md +194 -0
- package/skills/arkts-error-fixes/reference/idata_source_errors.md +77 -0
- package/skills/arkts-error-fixes/reference/implementation_not_allowed_errors.md +191 -0
- package/skills/arkts-error-fixes/reference/interface_method_signature_errors.md +143 -0
- package/skills/arkts-error-fixes/reference/notification_errors.md +110 -0
- package/skills/arkts-error-fixes/reference/object_literal_interface_errors.md +156 -0
- package/skills/arkts-error-fixes/reference/object_literal_type_errors.md +110 -0
- package/skills/arkts-error-fixes/reference/object_spread_errors.md +105 -0
- package/skills/arkts-error-fixes/reference/possibly_null_errors.md +156 -0
- package/skills/arkts-error-fixes/reference/resource_conversion_errors.md +154 -0
- package/skills/arkts-error-fixes/reference/standalone_function_errors.md +68 -0
- package/skills/arkts-error-fixes/reference/storage_link_default_errors.md +124 -0
- package/skills/arkts-error-fixes/reference/title_button_rect_type_errors.md +167 -0
- package/skills/arkts-error-fixes/reference/unused_variable_warnings.md +295 -0
- package/skills/arkts-error-fixes/reference/utility_type_errors.md +290 -0
- package/skills/arkts-error-fixes/reference/window_rect_size_errors.md +70 -0
- package/skills/arkts-error-fixes/reference/window_type_errors.md +95 -0
- package/skills/arkts-grammar-standards/SKILL.md +71 -0
- package/skills/arkts-grammar-standards/references/basic-syntax.md +103 -0
- package/skills/arkts-grammar-standards/references/restrictions.md +100 -0
- package/skills/arkts-grammar-standards/references/topic-aliases.json +93 -0
- package/skills/arkts-grammar-standards/references/ts-diff.md +108 -0
- package/skills/arkts-runtime-fix/SKILL.md +152 -0
- package/skills/arkts-runtime-fix/SKILL_CN.md +123 -0
- package/skills/arkts-runtime-fix/evals/evals.json +17 -0
- package/skills/arkts-runtime-fix/scripts/collect-hilog.mjs +116 -0
- package/skills/arkts-runtime-fix/scripts/collect-hilog.ts +115 -0
- package/skills/arkts-runtime-fix/scripts/fetch-faultlog.mjs +117 -0
- package/skills/arkts-runtime-fix/scripts/fetch-faultlog.ts +116 -0
- package/skills/arkts-runtime-fix/scripts/jscrash-report.mjs +149 -0
- package/skills/arkts-runtime-fix/scripts/parse-jscrash-log.mjs +126 -0
- package/skills/arkts-runtime-fix/scripts/parse-jscrash-log.ts +126 -0
- package/skills/arkts-runtime-fix/scripts/probe-faultlogger.mjs +160 -0
- package/skills/arkts-runtime-fix/scripts/probe-faultlogger.ts +160 -0
- package/skills/arkts-runtime-fix/scripts/shared/hdc.mjs +107 -0
- package/skills/arkts-runtime-fix/scripts/shared/hdc.ts +58 -0
- package/skills/arkts-runtime-fix/scripts/shared/jscrash-faultlogger.mjs +143 -0
- package/skills/arkts-runtime-fix/scripts/shared/jscrash-faultlogger.ts +148 -0
- package/skills/arkts-runtime-fix/scripts/shared/jscrash-parse.mjs +389 -0
- package/skills/arkts-runtime-fix/scripts/shared/jscrash-parse.ts +409 -0
- package/skills/arkts-runtime-fix/scripts/shared/utils.mjs +27 -0
- package/skills/arkts-runtime-fix/scripts/shared/utils.ts +27 -0
- package/skills/arkui-knowledge/SKILL.md +90 -0
- package/skills/arkui-knowledge/references/api-guardrails.md +60 -0
- package/skills/arkui-knowledge/references/common-mistakes.md +119 -0
- package/skills/arkui-knowledge/references/component-cookbook.md +135 -0
- package/skills/arkui-knowledge/references/ui-quality-checklist.md +36 -0
- package/skills/deveco-create-project/SKILL.md +144 -0
- package/skills/deveco-create-project/application/AppScope/app.json5 +10 -0
- package/skills/deveco-create-project/application/AppScope/resources/base/element/string.json +8 -0
- package/skills/deveco-create-project/application/AppScope/resources/base/media/background.png +0 -0
- package/skills/deveco-create-project/application/AppScope/resources/base/media/foreground.png +0 -0
- package/skills/deveco-create-project/application/AppScope/resources/base/media/layered_image.json +7 -0
- package/skills/deveco-create-project/application/build-profile.json5 +42 -0
- package/skills/deveco-create-project/application/code-linter.json5 +32 -0
- package/skills/deveco-create-project/application/entry/build-profile.json5 +33 -0
- package/skills/deveco-create-project/application/entry/hvigorfile.ts +7 -0
- package/skills/deveco-create-project/application/entry/obfuscation-rules.txt +23 -0
- package/skills/deveco-create-project/application/entry/oh-package.json5 +10 -0
- package/skills/deveco-create-project/application/entry/src/main/ets/entryability/EntryAbility.ets +63 -0
- package/skills/deveco-create-project/application/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +31 -0
- package/skills/deveco-create-project/application/entry/src/main/ets/pages/Index.ets +38 -0
- package/skills/deveco-create-project/application/entry/src/main/module.json5 +50 -0
- package/skills/deveco-create-project/application/entry/src/main/resources/base/element/color.json +8 -0
- package/skills/deveco-create-project/application/entry/src/main/resources/base/element/float.json +8 -0
- package/skills/deveco-create-project/application/entry/src/main/resources/base/element/string.json +16 -0
- package/skills/deveco-create-project/application/entry/src/main/resources/base/media/background.png +0 -0
- package/skills/deveco-create-project/application/entry/src/main/resources/base/media/foreground.png +0 -0
- package/skills/deveco-create-project/application/entry/src/main/resources/base/media/layered_image.json +7 -0
- package/skills/deveco-create-project/application/entry/src/main/resources/base/media/startIcon.png +0 -0
- package/skills/deveco-create-project/application/entry/src/main/resources/base/profile/backup_config.json +3 -0
- package/skills/deveco-create-project/application/entry/src/main/resources/base/profile/main_pages.json +5 -0
- package/skills/deveco-create-project/application/entry/src/main/resources/dark/element/color.json +8 -0
- package/skills/deveco-create-project/application/hvigor/hvigor-config.json5 +23 -0
- package/skills/deveco-create-project/application/hvigorfile.ts +7 -0
- package/skills/deveco-create-project/application/oh-package.json5 +10 -0
- package/skills/deveco-create-project/scripts/copy-template.mjs +216 -0
- package/skills/deveco-create-project/scripts/copy-template.ts +214 -0
- package/skills/deveco-create-project/scripts/detect-sdk.mjs +82 -0
- package/skills/deveco-create-project/scripts/detect-sdk.ts +95 -0
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ❌ 错误示例:使用 any 类型
|
|
3
|
+
*
|
|
4
|
+
* 错误原因:ArkTS 不允许使用 any 类型
|
|
5
|
+
* 错误信息:Use explicit types instead of "any", "unknown" (arkts-no-any-unknown)
|
|
6
|
+
*/
|
|
7
|
+
// @Entry
|
|
8
|
+
// @Component
|
|
9
|
+
// struct AnyTypeError {
|
|
10
|
+
// @State data: any = { name: 'John', age: 30 };
|
|
11
|
+
//
|
|
12
|
+
// // ❌ 错误:使用 any 类型
|
|
13
|
+
// private processData(input: any): void {
|
|
14
|
+
// console.info(input.name);
|
|
15
|
+
// console.info(input.age);
|
|
16
|
+
// }
|
|
17
|
+
//
|
|
18
|
+
// // ❌ 错误:使用 any 类型
|
|
19
|
+
// private handleEvent(event: any): void {
|
|
20
|
+
// console.info(event.target);
|
|
21
|
+
// console.info(event.value);
|
|
22
|
+
// }
|
|
23
|
+
//
|
|
24
|
+
// build() {
|
|
25
|
+
// Column() {
|
|
26
|
+
// Text('Any Type Error')
|
|
27
|
+
// .fontSize(20)
|
|
28
|
+
// .margin({ bottom: 20 })
|
|
29
|
+
//
|
|
30
|
+
// Button('Process Data')
|
|
31
|
+
// .onClick(() => {
|
|
32
|
+
// this.processData(this.data);
|
|
33
|
+
// })
|
|
34
|
+
// }
|
|
35
|
+
// }
|
|
36
|
+
// }
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* ✅ 正确示例:使用明确的类型
|
|
40
|
+
*/
|
|
41
|
+
@Entry
|
|
42
|
+
@Component
|
|
43
|
+
struct ExplicitTypeCorrect {
|
|
44
|
+
@State data: UserData = { name: 'John', age: 30 };
|
|
45
|
+
|
|
46
|
+
// ✅ 正确:使用明确的类型
|
|
47
|
+
private processData(input: UserData): void {
|
|
48
|
+
console.info(input.name);
|
|
49
|
+
console.info(input.age.toString());
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// ✅ 正确:使用明确的类型
|
|
53
|
+
private handleEvent(event: ClickEvent): void {
|
|
54
|
+
console.info(event.target.toString());
|
|
55
|
+
console.info(event.timestamp.toString());
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
build() {
|
|
59
|
+
Column() {
|
|
60
|
+
Text('Explicit Type Correct')
|
|
61
|
+
.fontSize(20)
|
|
62
|
+
.margin({ bottom: 20 })
|
|
63
|
+
|
|
64
|
+
Button('Process Data')
|
|
65
|
+
.onClick(() => {
|
|
66
|
+
this.processData(this.data);
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* ✅ 正确示例:使用接口定义类型
|
|
74
|
+
*/
|
|
75
|
+
interface UserData {
|
|
76
|
+
name: string;
|
|
77
|
+
age: number;
|
|
78
|
+
email?: string;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@Entry
|
|
82
|
+
@Component
|
|
83
|
+
struct InterfaceTypeCorrect {
|
|
84
|
+
@State data: UserData = { name: 'John', age: 30 };
|
|
85
|
+
|
|
86
|
+
// ✅ 正确:使用接口定义类型
|
|
87
|
+
private processData(input: UserData): void {
|
|
88
|
+
console.info(input.name);
|
|
89
|
+
console.info(input.age.toString());
|
|
90
|
+
if (input.email) {
|
|
91
|
+
console.info(input.email);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
build() {
|
|
96
|
+
Column() {
|
|
97
|
+
Text('Interface Type Correct')
|
|
98
|
+
.fontSize(20)
|
|
99
|
+
.margin({ bottom: 20 })
|
|
100
|
+
|
|
101
|
+
Button('Process Data')
|
|
102
|
+
.onClick(() => {
|
|
103
|
+
this.processData(this.data);
|
|
104
|
+
})
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* ✅ 正确示例:使用联合类型
|
|
111
|
+
*/
|
|
112
|
+
type StringOrNumber = string | number;
|
|
113
|
+
|
|
114
|
+
@Entry
|
|
115
|
+
@Component
|
|
116
|
+
struct UnionTypeCorrect {
|
|
117
|
+
@State value: StringOrNumber = 'Hello';
|
|
118
|
+
|
|
119
|
+
// ✅ 正确:使用联合类型
|
|
120
|
+
private displayValue(value: StringOrNumber): string {
|
|
121
|
+
if (typeof value === 'string') {
|
|
122
|
+
return value;
|
|
123
|
+
} else {
|
|
124
|
+
return value.toString();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
build() {
|
|
129
|
+
Column() {
|
|
130
|
+
Text(this.displayValue(this.value))
|
|
131
|
+
.fontSize(20)
|
|
132
|
+
.margin({ bottom: 20 })
|
|
133
|
+
|
|
134
|
+
Button('Toggle Value')
|
|
135
|
+
.onClick(() => {
|
|
136
|
+
if (typeof this.value === 'string') {
|
|
137
|
+
this.value = 42;
|
|
138
|
+
} else {
|
|
139
|
+
this.value = 'Hello';
|
|
140
|
+
}
|
|
141
|
+
})
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* ✅ 正确示例:使用泛型
|
|
148
|
+
*/
|
|
149
|
+
@Entry
|
|
150
|
+
@Component
|
|
151
|
+
struct GenericTypeCorrect {
|
|
152
|
+
@State items: number[] = [1, 2, 3, 4, 5];
|
|
153
|
+
|
|
154
|
+
// ✅ 正确:使用泛型
|
|
155
|
+
private findItem<T>(array: T[], predicate: (item: T) => boolean): T | undefined {
|
|
156
|
+
for (const item of array) {
|
|
157
|
+
if (predicate(item)) {
|
|
158
|
+
return item;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return undefined;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
build() {
|
|
165
|
+
Column() {
|
|
166
|
+
Text('Generic Type Correct')
|
|
167
|
+
.fontSize(20)
|
|
168
|
+
.margin({ bottom: 20 })
|
|
169
|
+
|
|
170
|
+
Button('Find Item')
|
|
171
|
+
.onClick(() => {
|
|
172
|
+
const found = this.findItem(this.items, (item) => item > 3);
|
|
173
|
+
console.info(`Found: ${found}`);
|
|
174
|
+
})
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* ✅ 正确示例:使用 Object 类型
|
|
181
|
+
*/
|
|
182
|
+
interface Config {
|
|
183
|
+
width: number;
|
|
184
|
+
height: number;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
interface LogArg {
|
|
188
|
+
key: string;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
@Entry
|
|
192
|
+
@Component
|
|
193
|
+
struct ObjectTypeCorrect {
|
|
194
|
+
@State config: Config = { width: 100, height: 200 };
|
|
195
|
+
|
|
196
|
+
// ✅ 正确:使用 Object 类型
|
|
197
|
+
private applyConfig(config: Object): void {
|
|
198
|
+
console.info(JSON.stringify(config));
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// ✅ 正确:使用 Object[] 作为参数类型
|
|
202
|
+
private logArgs(...args: Object[]): void {
|
|
203
|
+
args.forEach(arg => {
|
|
204
|
+
console.info(JSON.stringify(arg));
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
build() {
|
|
209
|
+
Column() {
|
|
210
|
+
Text('Object Type Correct')
|
|
211
|
+
.fontSize(20)
|
|
212
|
+
.margin({ bottom: 20 })
|
|
213
|
+
|
|
214
|
+
Button('Apply Config')
|
|
215
|
+
.onClick(() => {
|
|
216
|
+
this.applyConfig(this.config);
|
|
217
|
+
const logArg: LogArg = { key: 'value' };
|
|
218
|
+
this.logArgs('arg1', 42, logArg);
|
|
219
|
+
})
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* ✅ 正确示例:使用类型守卫
|
|
226
|
+
*/
|
|
227
|
+
interface StringData {
|
|
228
|
+
type: 'string';
|
|
229
|
+
value: string;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
interface NumberData {
|
|
233
|
+
type: 'number';
|
|
234
|
+
value: number;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
type Data = StringData | NumberData;
|
|
238
|
+
|
|
239
|
+
@Entry
|
|
240
|
+
@Component
|
|
241
|
+
struct TypeGuardCorrect {
|
|
242
|
+
@State data: Data = { type: 'string', value: 'Hello' };
|
|
243
|
+
|
|
244
|
+
// ✅ 正确:使用类型守卫
|
|
245
|
+
private processData(data: Data): string {
|
|
246
|
+
if (data.type === 'string') {
|
|
247
|
+
return data.value;
|
|
248
|
+
} else {
|
|
249
|
+
return data.value.toString();
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
build() {
|
|
254
|
+
Column() {
|
|
255
|
+
Text(this.processData(this.data))
|
|
256
|
+
.fontSize(20)
|
|
257
|
+
.margin({ bottom: 20 })
|
|
258
|
+
|
|
259
|
+
Button('Toggle Data')
|
|
260
|
+
.onClick(() => {
|
|
261
|
+
if (this.data.type === 'string') {
|
|
262
|
+
this.data = { type: 'number', value: 42 };
|
|
263
|
+
} else {
|
|
264
|
+
this.data = { type: 'string', value: 'Hello' };
|
|
265
|
+
}
|
|
266
|
+
})
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
@Entry
|
|
2
|
+
@Component
|
|
3
|
+
struct AppStorageError {
|
|
4
|
+
@StorageLink('myValue') myValue: number = 0;
|
|
5
|
+
|
|
6
|
+
aboutToAppear() {
|
|
7
|
+
AppStorage.setOrCreate('myValue', 0);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
build() {
|
|
11
|
+
Column() {
|
|
12
|
+
Text(`Value: ${this.myValue}`)
|
|
13
|
+
.fontSize(20)
|
|
14
|
+
.margin({ bottom: 20 })
|
|
15
|
+
|
|
16
|
+
Button('Increment')
|
|
17
|
+
.onClick(() => {
|
|
18
|
+
this.myValue += 1;
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { mediaquery } from '@kit.ArkUI';
|
|
2
|
+
|
|
3
|
+
@Entry
|
|
4
|
+
@Component
|
|
5
|
+
struct ArrowFunctionConversionError {
|
|
6
|
+
@State isWideScreen: boolean = false;
|
|
7
|
+
private mediaListener: mediaquery.MediaQueryListener | null = null;
|
|
8
|
+
|
|
9
|
+
aboutToAppear() {
|
|
10
|
+
const mediaQuery = this.getUIContext().getMediaQuery();
|
|
11
|
+
this.mediaListener = mediaQuery.matchMediaSync('(min-width: 600vp)');
|
|
12
|
+
|
|
13
|
+
if (this.mediaListener) {
|
|
14
|
+
this.isWideScreen = this.mediaListener.matches;
|
|
15
|
+
|
|
16
|
+
this.mediaListener.on('change', (result: mediaquery.MediaQueryResult) => {
|
|
17
|
+
this.isWideScreen = result.matches;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
aboutToDisappear() {
|
|
23
|
+
if (this.mediaListener) {
|
|
24
|
+
this.mediaListener.off('change');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
build() {
|
|
29
|
+
Column() {
|
|
30
|
+
Text('Function.bind 错误示例')
|
|
31
|
+
.fontSize(20)
|
|
32
|
+
.fontWeight(FontWeight.Bold)
|
|
33
|
+
.margin({ bottom: 16 })
|
|
34
|
+
|
|
35
|
+
Text(`屏幕宽度: ${this.isWideScreen ? '宽屏' : '窄屏'}`)
|
|
36
|
+
.fontSize(16)
|
|
37
|
+
.fontColor('#333333')
|
|
38
|
+
}
|
|
39
|
+
.width('100%')
|
|
40
|
+
.padding(16)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { window } from '@kit.ArkUI';
|
|
2
|
+
import { common } from '@kit.AbilityKit';
|
|
3
|
+
|
|
4
|
+
@Entry
|
|
5
|
+
@Component
|
|
6
|
+
struct AvoidAreaTypeError {
|
|
7
|
+
@State avoidArea: window.AvoidArea = {
|
|
8
|
+
topRect: { left: 0, top: 0, width: 0, height: 0 },
|
|
9
|
+
bottomRect: { left: 0, top: 0, width: 0, height: 0 },
|
|
10
|
+
leftRect: { left: 0, top: 0, width: 0, height: 0 },
|
|
11
|
+
rightRect: { left: 0, top: 0, width: 0, height: 0 },
|
|
12
|
+
visible: false
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
aboutToAppear() {
|
|
16
|
+
const context = this.getUIContext().getHostContext() as common.UIAbilityContext;
|
|
17
|
+
|
|
18
|
+
window.getLastWindow(context, (err, win) => {
|
|
19
|
+
if (err.code !== 0) {
|
|
20
|
+
console.error('获取窗口失败:', err);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
this.avoidArea = win.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM);
|
|
25
|
+
|
|
26
|
+
win.on('avoidAreaChange', (data) => {
|
|
27
|
+
if (data.type === window.AvoidAreaType.TYPE_SYSTEM) {
|
|
28
|
+
this.avoidArea = data.area;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
build() {
|
|
35
|
+
Column() {
|
|
36
|
+
Text(`Top height: ${this.avoidArea.topRect.height}`)
|
|
37
|
+
Text(`Bottom height: ${this.avoidArea.bottomRect.height}`)
|
|
38
|
+
Text(`Left width: ${this.avoidArea.leftRect.width}`)
|
|
39
|
+
Text(`Right width: ${this.avoidArea.rightRect.width}`)
|
|
40
|
+
Text(`Visible: ${this.avoidArea.visible}`)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { mediaquery } from '@kit.ArkUI';
|
|
2
|
+
|
|
3
|
+
@Entry
|
|
4
|
+
@Component
|
|
5
|
+
struct BreakpointTypeError {
|
|
6
|
+
@State currentBreakpoint: string = 'sm';
|
|
7
|
+
private smListener: mediaquery.MediaQueryListener | null = null;
|
|
8
|
+
private mdListener: mediaquery.MediaQueryListener | null = null;
|
|
9
|
+
private lgListener: mediaquery.MediaQueryListener | null = null;
|
|
10
|
+
|
|
11
|
+
aboutToAppear() {
|
|
12
|
+
const mediaQuery = this.getUIContext().getMediaQuery();
|
|
13
|
+
|
|
14
|
+
this.smListener = mediaQuery.matchMediaSync('(0vp<=width<600vp)');
|
|
15
|
+
this.mdListener = mediaQuery.matchMediaSync('(600vp<=width<840vp)');
|
|
16
|
+
this.lgListener = mediaQuery.matchMediaSync('(840vp<=width)');
|
|
17
|
+
|
|
18
|
+
const smCallback = (result: mediaquery.MediaQueryResult): void => {
|
|
19
|
+
if (result.matches) {
|
|
20
|
+
this.currentBreakpoint = 'sm';
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const mdCallback = (result: mediaquery.MediaQueryResult): void => {
|
|
24
|
+
if (result.matches) {
|
|
25
|
+
this.currentBreakpoint = 'md';
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const lgCallback = (result: mediaquery.MediaQueryResult): void => {
|
|
29
|
+
if (result.matches) {
|
|
30
|
+
this.currentBreakpoint = 'lg';
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
if (this.smListener) {
|
|
35
|
+
this.smListener.on('change', smCallback);
|
|
36
|
+
}
|
|
37
|
+
if (this.mdListener) {
|
|
38
|
+
this.mdListener.on('change', mdCallback);
|
|
39
|
+
}
|
|
40
|
+
if (this.lgListener) {
|
|
41
|
+
this.lgListener.on('change', lgCallback);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
aboutToDisappear() {
|
|
46
|
+
if (this.smListener) {
|
|
47
|
+
this.smListener.off('change');
|
|
48
|
+
}
|
|
49
|
+
if (this.mdListener) {
|
|
50
|
+
this.mdListener.off('change');
|
|
51
|
+
}
|
|
52
|
+
if (this.lgListener) {
|
|
53
|
+
this.lgListener.off('change');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
build() {
|
|
58
|
+
Column() {
|
|
59
|
+
Text('断点类型错误示例')
|
|
60
|
+
.fontSize(20)
|
|
61
|
+
.fontWeight(FontWeight.Bold)
|
|
62
|
+
.margin({ bottom: 16 })
|
|
63
|
+
|
|
64
|
+
Text(`当前断点: ${this.currentBreakpoint}`)
|
|
65
|
+
.fontSize(16)
|
|
66
|
+
.fontColor('#333333')
|
|
67
|
+
}
|
|
68
|
+
.width('100%')
|
|
69
|
+
.padding(16)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { camera } from '@kit.CameraKit';
|
|
2
|
+
import { common } from '@kit.AbilityKit';
|
|
3
|
+
|
|
4
|
+
@Entry
|
|
5
|
+
@Component
|
|
6
|
+
struct CatchClauseTypeError {
|
|
7
|
+
private cameraManager: camera.CameraManager | null = null;
|
|
8
|
+
|
|
9
|
+
async aboutToAppear() {
|
|
10
|
+
await this.initCamera();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async initCamera() {
|
|
14
|
+
try {
|
|
15
|
+
const context = this.getUIContext().getHostContext() as common.UIAbilityContext;
|
|
16
|
+
this.cameraManager = camera.getCameraManager(context);
|
|
17
|
+
console.log('相机管理器初始化成功');
|
|
18
|
+
} catch (error) {
|
|
19
|
+
console.error('初始化相机失败:', error);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async releaseCamera() {
|
|
24
|
+
if (this.cameraManager) {
|
|
25
|
+
try {
|
|
26
|
+
console.log('相机管理器已释放');
|
|
27
|
+
} catch (error) {
|
|
28
|
+
console.error('释放相机失败:', error);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
build() {
|
|
34
|
+
Column() {
|
|
35
|
+
Text('Catch Clause Type Error Example')
|
|
36
|
+
.fontSize(20)
|
|
37
|
+
.margin(20)
|
|
38
|
+
|
|
39
|
+
Button('初始化相机')
|
|
40
|
+
.onClick(() => {
|
|
41
|
+
this.initCamera();
|
|
42
|
+
})
|
|
43
|
+
.margin(10)
|
|
44
|
+
|
|
45
|
+
Button('释放相机')
|
|
46
|
+
.onClick(() => {
|
|
47
|
+
this.releaseCamera();
|
|
48
|
+
})
|
|
49
|
+
.margin(10)
|
|
50
|
+
}
|
|
51
|
+
.width('100%')
|
|
52
|
+
.height('100%')
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
@Entry
|
|
2
|
+
@Component
|
|
3
|
+
struct ColorConsistencyExample {
|
|
4
|
+
@State useSystemColor: boolean = false;
|
|
5
|
+
|
|
6
|
+
build() {
|
|
7
|
+
Column() {
|
|
8
|
+
Text('颜色一致性示例')
|
|
9
|
+
.fontSize(20)
|
|
10
|
+
.fontWeight(FontWeight.Bold)
|
|
11
|
+
.margin({ bottom: 20 })
|
|
12
|
+
|
|
13
|
+
Text('使用硬编码颜色(不推荐)')
|
|
14
|
+
.fontSize(14)
|
|
15
|
+
.fontColor('#666666')
|
|
16
|
+
.margin({ bottom: 8 })
|
|
17
|
+
|
|
18
|
+
Column() {
|
|
19
|
+
Text('白色背景')
|
|
20
|
+
.fontSize(16)
|
|
21
|
+
.padding(12)
|
|
22
|
+
.margin({ bottom: 8 })
|
|
23
|
+
.width('100%')
|
|
24
|
+
.backgroundColor('#FFFFFF')
|
|
25
|
+
.borderRadius(8)
|
|
26
|
+
|
|
27
|
+
Text('灰色背景')
|
|
28
|
+
.fontSize(16)
|
|
29
|
+
.padding(12)
|
|
30
|
+
.margin({ bottom: 8 })
|
|
31
|
+
.width('100%')
|
|
32
|
+
.backgroundColor('#F5F5F5')
|
|
33
|
+
.borderRadius(8)
|
|
34
|
+
|
|
35
|
+
Text('蓝色背景')
|
|
36
|
+
.fontSize(16)
|
|
37
|
+
.padding(12)
|
|
38
|
+
.width('100%')
|
|
39
|
+
.backgroundColor('#007DFF')
|
|
40
|
+
.fontColor('#FFFFFF')
|
|
41
|
+
.borderRadius(8)
|
|
42
|
+
}
|
|
43
|
+
.width('100%')
|
|
44
|
+
.padding(16)
|
|
45
|
+
.backgroundColor('#F0F0F0')
|
|
46
|
+
.borderRadius(8)
|
|
47
|
+
.margin({ bottom: 20 })
|
|
48
|
+
|
|
49
|
+
Text('使用系统颜色资源(推荐)')
|
|
50
|
+
.fontSize(14)
|
|
51
|
+
.fontColor('#666666')
|
|
52
|
+
.margin({ bottom: 8 })
|
|
53
|
+
|
|
54
|
+
Column() {
|
|
55
|
+
Text('系统背景色')
|
|
56
|
+
.fontSize(16)
|
|
57
|
+
.padding(12)
|
|
58
|
+
.margin({ bottom: 8 })
|
|
59
|
+
.width('100%')
|
|
60
|
+
.backgroundColor($r('sys.color.ohos_id_color_background'))
|
|
61
|
+
.borderRadius(8)
|
|
62
|
+
|
|
63
|
+
Text('系统分割线色')
|
|
64
|
+
.fontSize(16)
|
|
65
|
+
.padding(12)
|
|
66
|
+
.margin({ bottom: 8 })
|
|
67
|
+
.width('100%')
|
|
68
|
+
.backgroundColor($r('sys.color.ohos_id_color_list_separator'))
|
|
69
|
+
.borderRadius(8)
|
|
70
|
+
|
|
71
|
+
Text('系统主色调')
|
|
72
|
+
.fontSize(16)
|
|
73
|
+
.padding(12)
|
|
74
|
+
.width('100%')
|
|
75
|
+
.backgroundColor($r('sys.color.ohos_id_color_primary'))
|
|
76
|
+
.fontColor($r('sys.color.ohos_id_color_text_primary'))
|
|
77
|
+
.borderRadius(8)
|
|
78
|
+
}
|
|
79
|
+
.width('100%')
|
|
80
|
+
.padding(16)
|
|
81
|
+
.backgroundColor($r('sys.color.ohos_id_color_sub_background'))
|
|
82
|
+
.borderRadius(8)
|
|
83
|
+
}
|
|
84
|
+
.width('100%')
|
|
85
|
+
.height('100%')
|
|
86
|
+
.padding(20)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
@Entry
|
|
2
|
+
@Component
|
|
3
|
+
struct ColorPropertyError {
|
|
4
|
+
@State isDarkMode: boolean = false;
|
|
5
|
+
|
|
6
|
+
build() {
|
|
7
|
+
Column() {
|
|
8
|
+
Text('Color Property Example')
|
|
9
|
+
.fontSize(20)
|
|
10
|
+
.fontWeight(FontWeight.Bold)
|
|
11
|
+
.margin({ bottom: 20 })
|
|
12
|
+
|
|
13
|
+
Text('Primary Color')
|
|
14
|
+
.fontSize(16)
|
|
15
|
+
.fontColor('#007DFF')
|
|
16
|
+
.margin({ bottom: 10 })
|
|
17
|
+
|
|
18
|
+
Text('Secondary Color')
|
|
19
|
+
.fontSize(16)
|
|
20
|
+
.fontColor('#FF6B00')
|
|
21
|
+
.margin({ bottom: 10 })
|
|
22
|
+
|
|
23
|
+
Text('Background Color')
|
|
24
|
+
.fontSize(16)
|
|
25
|
+
.backgroundColor('#F5F5F5')
|
|
26
|
+
.padding(10)
|
|
27
|
+
.margin({ bottom: 20 })
|
|
28
|
+
|
|
29
|
+
Button('Toggle Theme')
|
|
30
|
+
.onClick(() => {
|
|
31
|
+
this.isDarkMode = !this.isDarkMode;
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
.width('100%')
|
|
35
|
+
.height('100%')
|
|
36
|
+
.backgroundColor(this.isDarkMode ? '#1A1A1A' : '#FFFFFF')
|
|
37
|
+
.padding(20)
|
|
38
|
+
}
|
|
39
|
+
}
|