Open
AI问题扫描修改 #4
AI问题扫描修改 #4
Open
得鹿梦鱼Add on 1 day ago
Total: 11 files changed+91-81
@@ -1,5 +1,7 @@
1{1{
2 "apiType": "stageMode",2 "apiType": "stageMode",
3+ "buildOption": {
4+ },
3 "buildOptionSet": [5 "buildOptionSet": [
4 {6 {
5 "name": "release",7 "name": "release",
@@ -12,12 +14,7 @@
12 ]14 ]
13 }15 }
14 }16 }
15- },"nativeLib": {17+ },
16- "debugSymbol": {
17- "strip": true,
18- "exclude": []
19- }
20- }
21 },18 },
22 ],19 ],
23 "targets": [20 "targets": [
@@ -1,6 +1,21 @@
1+/*
2+ * Copyright (c) 2026 Huawei Device Co., Ltd.
3+ * Licensed under the Apache License, Version 2.0 (the 'License');
4+ * you may not use this file except in compliance with the License.
5+ * You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an 'AS IS' BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ */
15+ 
1import { hapTasks } from '@ohos/hvigor-ohos-plugin';16import { hapTasks } from '@ohos/hvigor-ohos-plugin';
2 17 
3export default {18export default {
4- system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */19+ system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
5- plugins:[] /* Custom plugin to extend the functionality of Hvigor. */20+ plugins:[], /* Custom plugin to extend the functionality of Hvigor. */
6-}21+};
@@ -89,12 +89,12 @@ export class KeyboardController {
89 return this.text;89 return this.text;
90 }90 }
91 91 
92- public onPaste(value: string) {92+ public onPaste(value: string): void {
93 this.text = this.text.substring(0, this.leftCaretPos) + value + this.text.substring(this.rightCaretPos);93 this.text = this.text.substring(0, this.leftCaretPos) + value + this.text.substring(this.rightCaretPos);
94 this.targetCaretPos = this.leftCaretPos + value.length;94 this.targetCaretPos = this.leftCaretPos + value.length;
95 }95 }
96 96 
97- public onChange(value: string) {97+ public onChange(value: string): void {
98 this.text = value;98 this.text = value;
99 if (this.keyboardType !== 'System') {99 if (this.keyboardType !== 'System') {
100 this.textInputController?.caretPosition(this.targetCaretPos);100 this.textInputController?.caretPosition(this.targetCaretPos);
@@ -103,16 +103,16 @@ export class KeyboardController {
103 103 
104 // After the text is updated, actively sync the cursor position to ensure the cursor moves right after104 // After the text is updated, actively sync the cursor position to ensure the cursor moves right after
105 // entering a character (a fallback safeguard on 2in1/PC devices)105 // entering a character (a fallback safeguard on 2in1/PC devices)
106- public syncCaretPosition() {106+ public syncCaretPosition(): void {
107 this.textInputController?.caretPosition(this.targetCaretPos);107 this.textInputController?.caretPosition(this.targetCaretPos);
108 }108 }
109 109 
110- public setCaretPosition(start: number, end: number) {110+ public setCaretPosition(start: number, end: number): void {
111 this.leftCaretPos = start;111 this.leftCaretPos = start;
112 this.rightCaretPos = end;112 this.rightCaretPos = end;
113 }113 }
114 114 
115- public onCut() {115+ public onCut(): void {
116 this.text = this.text.substring(0, this.leftCaretPos) + this.text.substring(this.rightCaretPos);116 this.text = this.text.substring(0, this.leftCaretPos) + this.text.substring(this.rightCaretPos);
117 this.targetCaretPos = this.leftCaretPos;117 this.targetCaretPos = this.leftCaretPos;
118 }118 }
@@ -13,6 +13,7 @@
13 * limitations under the License.13 * limitations under the License.
14 */14 */
15 15 
16+import { common } from '@kit.AbilityKit';
16import { KeyboardController } from '../model/KeyboardController';17import { KeyboardController } from '../model/KeyboardController';
17import { WindowInfo } from '../model/WindowInfo';18import { WindowInfo } from '../model/WindowInfo';
18import Logger from '../utils/Logger';19import Logger from '../utils/Logger';
@@ -26,6 +27,25 @@ import {
26} from '../viewmodel/ChatModel';27} from '../viewmodel/ChatModel';
27import { TextInputComponent } from './TextInputComponent';28import { TextInputComponent } from './TextInputComponent';
28 29 
30+function getString(context: common.Context | undefined, res: ResourceStr): string {
31+ if (typeof res === 'string') {
32+ return res as string;
33+ }
34+ if (context === undefined) {
35+ return '';
36+ }
37+ try {
38+ return context.resourceManager.getStringSync((res as Resource).id);
39+ } catch (error) {
40+ Logger.error(`getStringSync failed: ${JSON.stringify(error)}`);
41+ return '';
42+ }
43+}
44+ 
45+function getAvatarColor(conversation: Conversation): Resource {
46+ return AVATAR_COLORS[conversation.id % AVATAR_COLORS.length];
47+}
48+ 
29@Component49@Component
30// eslint-disable-next-line @performance/avoid-overusing-custom-component-check50// eslint-disable-next-line @performance/avoid-overusing-custom-component-check
31export struct ConversationListView {51export struct ConversationListView {
@@ -33,26 +53,6 @@ export struct ConversationListView {
33 public onClickItem: (id: number) => void = () => {53 public onClickItem: (id: number) => void = () => {
34 };54 };
35 55 
36- private getString(res: ResourceStr): string {
37- if (typeof res === 'string') {
38- return res as string;
39- }
40- const context = this.getUIContext().getHostContext();
41- if (context === undefined) {
42- return '';
43- }
44- try {
45- return context.resourceManager.getStringSync((res as Resource).id);
46- } catch (error) {
47- Logger.error(`getStringSync failed: ${JSON.stringify(error)}`);
48- return '';
49- }
50- }
51- 
52- private avatarColor(conversation: Conversation): Resource {
53- return AVATAR_COLORS[conversation.id % AVATAR_COLORS.length];
54- }
55- 
56 build() {56 build() {
57 Column() {57 Column() {
58 Row() {58 Row() {
@@ -75,14 +75,14 @@ export struct ConversationListView {
75 Column() {75 Column() {
76 Row({ space: 12 }) {76 Row({ space: 12 }) {
77 Stack() {77 Stack() {
78- Text(this.getString(conversation.name).charAt(0))78+ Text(getString(this.getUIContext().getHostContext(), conversation.name).charAt(0))
79 .fontSize(20)79 .fontSize(20)
80 .fontColor(Color.White)80 .fontColor(Color.White)
81 }81 }
82 .width(48)82 .width(48)
83 .height(48)83 .height(48)
84 .borderRadius(24)84 .borderRadius(24)
85- .backgroundColor(this.avatarColor(conversation))85+ .backgroundColor(getAvatarColor(conversation))
86 86 
87 Column({ space: 4 }) {87 Column({ space: 4 }) {
88 Row() {88 Row() {
@@ -158,26 +158,6 @@ export struct ChatDetailView {
158 private scroller: Scroller = new Scroller();158 private scroller: Scroller = new Scroller();
159 private scrollerScrollTimerId: number = -1;159 private scrollerScrollTimerId: number = -1;
160 160 
161- private getString(res: ResourceStr): string {
162- if (typeof res === 'string') {
163- return res as string;
164- }
165- const context = this.getUIContext().getHostContext();
166- if (context === undefined) {
167- return '';
168- }
169- try {
170- return context.resourceManager.getStringSync((res as Resource).id);
171- } catch (error) {
172- Logger.error(`getStringSync failed: ${JSON.stringify(error)}`);
173- return '';
174- }
175- }
176- 
177- private avatarColor(conversation: Conversation): Resource {
178- return AVATAR_COLORS[conversation.id % AVATAR_COLORS.length];
179- }
180- 
181 private loadConversation(id: number): void {161 private loadConversation(id: number): void {
182 let target: Conversation = CONVERSATIONS_DATA[0];162 let target: Conversation = CONVERSATIONS_DATA[0];
183 for (let i = 0; i < CONVERSATIONS_DATA.length; i++) {163 for (let i = 0; i < CONVERSATIONS_DATA.length; i++) {
@@ -199,7 +179,7 @@ export struct ChatDetailView {
199 id: Date.now(),179 id: Date.now(),
200 conversationId: this.conversation.id,180 conversationId: this.conversation.id,
201 content: content,181 content: content,
202- time: this.getString($r('app.string.chat_time_just_now')),182+ time: getString(this.getUIContext().getHostContext(), $r('app.string.chat_time_just_now')),
203 isMine: true183 isMine: true
204 };184 };
205 this.messages = this.messages.concat(newMessage);185 this.messages = this.messages.concat(newMessage);
@@ -247,9 +227,10 @@ export struct ChatDetailView {
247 227 
248 private buildRenderList(): ChatRenderItem[] {228 private buildRenderList(): ChatRenderItem[] {
249 let items: ChatRenderItem[] = [];229 let items: ChatRenderItem[] = [];
230+ const context = this.getUIContext().getHostContext();
250 for (let i = 0; i < this.messages.length; i++) {231 for (let i = 0; i < this.messages.length; i++) {
251 let msg: MessageItem = this.messages[i];232 let msg: MessageItem = this.messages[i];
252- if (i === 0 || this.getString(msg.time) !== this.getString(this.messages[i - 1].time)) {233+ if (i === 0 || getString(context, msg.time) !== getString(context, this.messages[i - 1].time)) {
253 items.push({ type: 'time', time: msg.time });234 items.push({ type: 'time', time: msg.time });
254 }235 }
255 items.push({ type: 'message', message: msg });236 items.push({ type: 'message', message: msg });
@@ -309,14 +290,14 @@ export struct ChatDetailView {
309 Row({ space: 12 }) {290 Row({ space: 12 }) {
310 if (!message.isMine) {291 if (!message.isMine) {
311 Stack() {292 Stack() {
312- Text(this.getString(this.conversation.name).charAt(0))293+ Text(getString(this.getUIContext().getHostContext(), this.conversation.name).charAt(0))
313 .fontSize(15)294 .fontSize(15)
314 .fontColor(Color.White)295 .fontColor(Color.White)
315 }296 }
316 .width(36)297 .width(36)
317 .height(36)298 .height(36)
318 .borderRadius(18)299 .borderRadius(18)
319- .backgroundColor(this.avatarColor(this.conversation))300+ .backgroundColor(getAvatarColor(this.conversation))
320 Column() {301 Column() {
321 Text(message.content)302 Text(message.content)
322 .fontSize(15)303 .fontSize(15)
@@ -391,9 +372,10 @@ export struct ChatDetailView {
391 .width('100%')372 .width('100%')
392 .height('100%')373 .height('100%')
393 .expandSafeArea([SafeAreaType.KEYBOARD], [SafeAreaEdge.BOTTOM])374 .expandSafeArea([SafeAreaType.KEYBOARD], [SafeAreaEdge.BOTTOM])
394- .padding({ bottom: this.isCustomKeyboardAttach ?375+ .padding({
395- this.customKeyboardHeight - this.windowInfo.bottomRectHeight :376+ bottom: Math.max(0, (this.isCustomKeyboardAttach ?
396- this.keyboardHeight - this.windowInfo.bottomRectHeight })377+ this.customKeyboardHeight : this.keyboardHeight) - this.windowInfo.bottomRectHeight)
378+ })
397 }379 }
398 .title(this.titleBuilder)380 .title(this.titleBuilder)
399 .hideBackButton(true)381 .hideBackButton(true)
@@ -14,6 +14,7 @@
14 */14 */
15 15 
16import { window, uiMaterial } from '@kit.ArkUI';16import { window, uiMaterial } from '@kit.ArkUI';
17+import { BusinessError } from '@kit.BasicServicesKit';
17import { Constants } from '../constants/Constants';18import { Constants } from '../constants/Constants';
18import { KeyboardController } from '../model/KeyboardController';19import { KeyboardController } from '../model/KeyboardController';
19import Logger from '../utils/Logger';20import Logger from '../utils/Logger';
@@ -39,6 +40,7 @@ export struct KeyboardMenuPanel {
39 @Consume('windowHeightBp') heightBp: HeightBreakpoint = HeightBreakpoint.HEIGHT_SM;40 @Consume('windowHeightBp') heightBp: HeightBreakpoint = HeightBreakpoint.HEIGHT_SM;
40 41 
41 private refreshTimerId: number = -1;42 private refreshTimerId: number = -1;
43+ private focusTimerId: number = -1;
42 private useBlurFallback: boolean = false;44 private useBlurFallback: boolean = false;
43 45 
44 aboutToAppear(): void {46 aboutToAppear(): void {
@@ -81,6 +83,7 @@ export struct KeyboardMenuPanel {
81 83 
82 aboutToDisappear(): void {84 aboutToDisappear(): void {
83 clearTimeout(this.refreshTimerId);85 clearTimeout(this.refreshTimerId);
86+ clearTimeout(this.focusTimerId);
84 }87 }
85 88 
86 @Builder89 @Builder
@@ -119,7 +122,9 @@ export struct KeyboardMenuPanel {
119 // only refresh the key layout and keep the keyboard resident, avoiding flicker from bringing it up again122 // only refresh the key layout and keep the keyboard resident, avoiding flicker from bringing it up again
120 if ((isCustomKeyboard && !wasCustomKeyboard) || isOuterScreen) {123 if ((isCustomKeyboard && !wasCustomKeyboard) || isOuterScreen) {
121 this.keyboardController.textInputController?.stopEditing();124 this.keyboardController.textInputController?.stopEditing();
122- setTimeout(() => {125+ clearTimeout(this.focusTimerId);
126+ this.focusTimerId = setTimeout(() => {
127+ this.focusTimerId = -1;
123 focusControl.requestFocus('chatTextInput');128 focusControl.requestFocus('chatTextInput');
124 }, 200);129 }, 200);
125 }130 }
@@ -48,7 +48,7 @@ export struct TextInputComponent {
48 .id('chatTextInput')48 .id('chatTextInput')
49 // In system keyboard mode, null must be passed; otherwise, the customKeyboard binding will49 // In system keyboard mode, null must be passed; otherwise, the customKeyboard binding will
50 // suppress the system soft keyboard from popping up50 // suppress the system soft keyboard from popping up
51- .customKeyboard(this.isCustomKeyboardAttach ? this.customKeyboard() : null)51+ .customKeyboard(this.isCustomKeyboardAttach ? this.customKeyboard() : null)
52 .onKeyPreIme((event: KeyEvent) => {52 .onKeyPreIme((event: KeyEvent) => {
53 // Block physical keyboard input when using a custom keyboard (2in1/PC devices)53 // Block physical keyboard input when using a custom keyboard (2in1/PC devices)
54 if (!this.isCustomKeyboardAttach) {54 if (!this.isCustomKeyboardAttach) {
@@ -4,10 +4,6 @@
4 "name": "keyboard_margin_top",4 "name": "keyboard_margin_top",
5 "value": "0vp"5 "value": "0vp"
6 },6 },
7- {
8- "name": "english_keyboard_padding_top",
9- "value": "11vp"
10- },
11 {7 {
12 "name": "english_keyboard_padding_left",8 "name": "english_keyboard_padding_left",
13 "value": "18vp"9 "value": "18vp"
@@ -78,11 +78,11 @@
78 },78 },
79 {79 {
80 "name": "conv_0_name",80 "name": "conv_0_name",
81- "value": "华为开发者"81+ "value": "开发者"
82 },82 },
83 {83 {
84 "name": "conv_1_name",84 "name": "conv_1_name",
85- "value": "鸿蒙学堂"85+ "value": "学堂"
86 },86 },
87 {87 {
88 "name": "conv_0_last",88 "name": "conv_0_last",
@@ -102,7 +102,7 @@
102 },102 },
103 {103 {
104 "name": "msg_0_content",104 "name": "msg_0_content",
105- "value": "你好,欢迎加入鸿蒙开发者社区。"105+ "value": "你好,欢迎加入开发者社区。"
106 },106 },
107 {107 {
108 "name": "msg_1_content",108 "name": "msg_1_content",
@@ -78,11 +78,11 @@
78 },78 },
79 {79 {
80 "name": "conv_0_name",80 "name": "conv_0_name",
81- "value": "Huawei Developer"81+ "value": "Developer"
82 },82 },
83 {83 {
84 "name": "conv_1_name",84 "name": "conv_1_name",
85- "value": "HarmonyOS Academy"85+ "value": "Academy"
86 },86 },
87 {87 {
88 "name": "conv_0_last",88 "name": "conv_0_last",
@@ -102,7 +102,7 @@
102 },102 },
103 {103 {
104 "name": "msg_0_content",104 "name": "msg_0_content",
105- "value": "Hello, welcome to the HarmonyOS developer community."105+ "value": "Hello, welcome to the developer community."
106 },106 },
107 {107 {
108 "name": "msg_1_content",108 "name": "msg_1_content",
@@ -78,11 +78,11 @@
78 },78 },
79 {79 {
80 "name": "conv_0_name",80 "name": "conv_0_name",
81- "value": "华为开发者"81+ "value": "开发者"
82 },82 },
83 {83 {
84 "name": "conv_1_name",84 "name": "conv_1_name",
85- "value": "鸿蒙学堂"85+ "value": "学堂"
86 },86 },
87 {87 {
88 "name": "conv_0_last",88 "name": "conv_0_last",
@@ -102,7 +102,7 @@
102 },102 },
103 {103 {
104 "name": "msg_0_content",104 "name": "msg_0_content",
105- "value": "你好,欢迎加入鸿蒙开发者社区。"105+ "value": "你好,欢迎加入开发者社区。"
106 },106 },
107 {107 {
108 "name": "msg_1_content",108 "name": "msg_1_content",
@@ -1,6 +1,21 @@
1+/*
2+ * Copyright (c) 2026 Huawei Device Co., Ltd.
3+ * Licensed under the Apache License, Version 2.0 (the 'License');
4+ * you may not use this file except in compliance with the License.
5+ * You may obtain a copy of the License at
6+ *
7+ * http://www.apache.org/licenses/LICENSE-2.0
8+ *
9+ * Unless required by applicable law or agreed to in writing, software
10+ * distributed under the License is distributed on an 'AS IS' BASIS,
11+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ * See the License for the specific language governing permissions and
13+ * limitations under the License.
14+ */
15+ 
1import { appTasks } from '@ohos/hvigor-ohos-plugin';16import { appTasks } from '@ohos/hvigor-ohos-plugin';
2 17 
3export default {18export default {
4- system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */19+ system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
5- plugins:[] /* Custom plugin to extend the functionality of Hvigor. */20+ plugins:[], /* Custom plugin to extend the functionality of Hvigor. */
6-}21+};