1/** 2 * Copyright (c) 2024-2024 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 HeadComponent from '../../common/component/headComponent'; 17import { WidthPercent } from '../../common/util/ConfigData'; 18import { AlertDialog, CustomContentDialog } from '@ohos.arkui.advanced.Dialog'; 19import { BusinessError } from '@ohos.base'; 20import CmShowSysCredPresenter from '../../presenter/CmShowSysCredPresenter'; 21import { SheetParam } from '../../common/util/SheetParam'; 22import { NavEntryKey } from '../../common/NavEntryKey'; 23 24const TAG: string = 'CredSystemDetailPage: '; 25 26export class CredSystemDetailParam { 27 public presenter: CmShowSysCredPresenter; 28 29 constructor(presenter: CmShowSysCredPresenter) { 30 this.presenter = presenter; 31 } 32} 33 34@Component 35export struct CredSystemDetailPage { 36 private presenter: CmShowSysCredPresenter = CmShowSysCredPresenter.getInstance(); 37 38 private stack?: NavPathStack; 39 40 @State private bottomRectHeight: number = 80; 41 @State private headRectHeight: number = 64; 42 @State private headRectHeightReal: number = 0; 43 @Prop private sheetParam: SheetParam; 44 45 deleteWarnDialog: CustomDialogController = new CustomDialogController({ 46 builder: AlertDialog({ 47 primaryTitle: $r('app.string.warning_title'), 48 content: $r('app.string.warning_message'), 49 primaryButton: { 50 value: $r('app.string.cancelAuthApp'), 51 buttonStyle: ButtonStyleMode.TEXTUAL, 52 action: () => { 53 } 54 }, 55 secondaryButton: { 56 value: $r('app.string.deleteAllCredDelete'), 57 buttonStyle: ButtonStyleMode.TEXTUAL, 58 action: () => { 59 this.presenter.deleteSystemCred(this.presenter.credInfo.keyUri); 60 this.presenter.updateSystemCredList(); 61 this.stack?.pop(); 62 }, 63 role: ButtonRole.ERROR 64 } 65 }), 66 }) 67 68 build() { 69 NavDestination() { 70 Stack({ alignContent: Alignment.Bottom }) { 71 Stack({ alignContent: Alignment.Top }) { 72 Column() { 73 HeadComponent({ headName: $r('app.string.evidenceDetails'), isStartBySheet: true, onBackClicked: () => { 74 this.stack?.pop(); 75 } }) 76 .margin({ 77 left: $r('app.float.wh_value_12'), 78 top: 8 79 }) 80 }.zIndex(1) 81 .onAreaChange((oldArea, newArea) => { 82 this.headRectHeight = newArea.height as number; 83 this.headRectHeightReal = newArea.height as number; 84 }) 85 86 Column() { 87 Scroll() { 88 this.buildContent() 89 } 90 .align(Alignment.Top) 91 .scrollable(ScrollDirection.Vertical) 92 .scrollBar(BarState.Auto) 93 .edgeEffect(EdgeEffect.Spring) 94 .width(WidthPercent.WH_100_100) 95 .height(WidthPercent.WH_AUTO) 96 .constraintSize({ 97 minHeight: this.getScrollMinHeight() 98 }) 99 }.padding({ 100 top: this.headRectHeight 101 }) 102 } 103 .width(WidthPercent.WH_100_100) 104 .height(WidthPercent.WH_AUTO) 105 .padding({ 106 bottom: this.bottomRectHeight 107 }) 108 109 Column() { 110 Button($r('app.string.warning_title')) 111 .onClick(() => { 112 this.deleteWarnDialog.open(); 113 }) 114 .role(ButtonRole.ERROR) 115 .buttonStyle(ButtonStyleMode.NORMAL) 116 .margin({ 117 top: $r('app.float.distance_16'), 118 bottom: $r('app.float.distance_24') 119 }) 120 .width(WidthPercent.WH_100_100) 121 .constraintSize({ 122 minHeight: $r('app.float.wh_value_40') 123 }) 124 }.onAreaChange((oldArea: Area, newArea: Area) => { 125 this.bottomRectHeight = newArea.height as number; 126 }) 127 .padding({ 128 left: 16, right: 16 129 }) 130 } 131 } 132 .hideTitleBar(true) 133 .width(WidthPercent.WH_100_100) 134 .height(this.sheetParam?.lastSheetPage === NavEntryKey.CRED_SYSTEM_DETAIL_ENTRY ? 135 WidthPercent.WH_AUTO : this.sheetParam?.sheetMinHeight) 136 .backgroundColor($r('sys.color.background_secondary')) 137 .onReady((ctx: NavDestinationContext) => { 138 this.stack = ctx.pathStack; 139 try { 140 this.presenter = (ctx.pathInfo.param as CredSystemDetailParam).presenter; 141 } catch (err) { 142 let error = err as BusinessError; 143 console.error(TAG + 'Get presenter failed: ' + error?.code + ', message: ' + error?.message); 144 } 145 }) 146 } 147 148 @Builder 149 private buildContent() { 150 Column() { 151 Text(this.presenter.credInfo.alias) 152 .fontSize($r('sys.float.ohos_id_text_size_body1')) 153 .fontColor($r('sys.color.ohos_id_color_text_primary')) 154 .fontWeight(FontWeight.Medium) 155 .margin({ 156 left: $r('app.float.wh_value_24'), 157 right: $r('app.float.wh_value_24') 158 }) 159 .alignSelf(ItemAlign.Start) 160 161 Text($r('app.string.entryContains')) 162 .fontSize($r('sys.float.ohos_id_text_size_body2')) 163 .fontColor($r('sys.color.ohos_id_color_text_primary')) 164 .fontWeight(FontWeight.Regular) 165 .margin({ 166 top: $r('app.float.wh_value_24'), 167 left: $r('app.float.wh_value_24'), 168 right: $r('app.float.wh_value_24') 169 }) 170 .alignSelf(ItemAlign.Start) 171 172 Text($r('app.string.keyNum', String(this.presenter.credInfo.keyNum))) 173 .fontSize($r('sys.float.ohos_id_text_size_body2')) 174 .fontColor($r('sys.color.ohos_id_color_text_primary')) 175 .fontWeight(FontWeight.Regular) 176 .margin({ 177 left: $r('app.float.wh_value_10'), 178 right: $r('app.float.wh_value_10') 179 }) 180 .opacity($r('app.float.opacity_100_60')) 181 .alignSelf(ItemAlign.Start) 182 183 Text($r('app.string.userCerNum', String(this.presenter.credInfo.certNum))) 184 .fontSize($r('sys.float.ohos_id_text_size_body2')) 185 .fontColor($r('sys.color.ohos_id_color_text_primary')) 186 .fontWeight(FontWeight.Regular) 187 .margin({ 188 left: $r('app.float.wh_value_10'), 189 right: $r('app.float.wh_value_10') 190 }) 191 .opacity($r('app.float.opacity_100_60')) 192 .alignSelf(ItemAlign.Start) 193 } 194 .width(WidthPercent.WH_100_100) 195 .alignItems(HorizontalAlign.Start) 196 } 197 198 getScrollMinHeight() { 199 if (this.sheetParam === undefined || this.headRectHeightReal === 0 || 200 this.sheetParam.sheetMinHeight < (this.headRectHeightReal + this.bottomRectHeight)) { 201 return 0; 202 } 203 return this.sheetParam.sheetMinHeight - this.headRectHeightReal - this.bottomRectHeight; 204 } 205}