1/* 2 * Copyright (c) 2022-2025 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 16import promptAction from '@ohos.promptAction'; 17import testNapi from 'libentry.so'; 18import Logger from '../model/Logger'; 19 20const INDEX: number = 0; // 初始索引值 21const DURATION: number = 100; // 定时器时间 22 23@Preview 24@CustomDialog 25export struct FaultDialog { 26 private controller: CustomDialogController; 27 private faultTypes: string[] = ['JS_CRASH', 'CPP_CRASH', 'FREEZE_CRASH']; 28 @State selectIndex: number = INDEX; 29 30 addFaultLog() { 31 switch (this.selectIndex) { 32 case 0: 33 promptAction.showToast({ message: $r('app.string.js_crash_building') }); 34 setTimeout(() => { 35 let tempList = ['0', '1']; 36 Logger.info(tempList[3].toString()); 37 }, DURATION); 38 break; 39 case 1: 40 promptAction.showToast({ message: $r('app.string.cpp_crash_building') }); 41 testNapi.add(2, 3); 42 break; 43 case 2: 44 promptAction.showToast({ message: $r('app.string.app_freeze_building') }); 45 setTimeout(() => { 46 let index = 0; // 循环初始值 47 while (true) { 48 index++; 49 this.selectIndex = index % 2; 50 } 51 }, DURATION); 52 break; 53 default: 54 break; 55 } 56 } 57 58 build() { 59 Column() { 60 Text($r('app.string.select_fault_type')) 61 .textAlign(TextAlign.Start) 62 .width('100%') 63 .fontSize(22) 64 65 Column() { 66 ForEach(this.faultTypes, (item: string, index) => { 67 Row() { 68 Image(this.selectIndex === index ? $r('app.media.checked') : $r('app.media.uncheck')) 69 .height(30).width(30) 70 .objectFit(ImageFit.Contain) 71 72 Text(item) 73 .padding(10) 74 .fontSize(20) 75 .fontColor(Color.Black) 76 } 77 .id(item) 78 .width('100%') 79 .onClick(() => { 80 this.selectIndex = index 81 }) 82 }, (item: string) => item) 83 84 Row() { 85 Button() { 86 Text($r('app.string.sure')) 87 .fontColor(Color.Red) 88 .width('90%') 89 .textAlign(TextAlign.Center) 90 .fontSize(20) 91 } 92 .id('OK') 93 .type(ButtonType.Capsule) 94 .backgroundColor(Color.White) 95 .layoutWeight(1) 96 .onClick(() => { 97 this.controller.close() 98 this.addFaultLog() 99 }) 100 101 Divider().size({ width: 1, height: 40 }).backgroundColor(Color.Gray) 102 103 Button() { 104 Text($r('app.string.cancel')) 105 .fontColor('#0D9FFB') 106 .width('90%') 107 .textAlign(TextAlign.Center) 108 .fontSize(20) 109 } 110 .id('cancel') 111 .type(ButtonType.Capsule) 112 .backgroundColor(Color.White) 113 .layoutWeight(1) 114 .onClick(() => { 115 this.controller.close() 116 }) 117 } 118 .width('100%') 119 } 120 } 121 .padding(16) 122 } 123}