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 } from '@ohos.arkui.advanced.Dialog'; 19import { BusinessError } from '@ohos.base'; 20import CmShowAppCredPresenter from '../../presenter/CmShowAppCredPresenter'; 21import { NavEntryKey } from '../../common/NavEntryKey'; 22import { AuthorizedAppManagementParam } from './AuthorizedAppManagementPage'; 23import { SheetParam } from '../../common/util/SheetParam'; 24 25const TAG: string = 'CredUserDetailPage: '; 26 27export class CredUserDetailParam { 28 public presenter: CmShowAppCredPresenter; 29 30 constructor(presenter: CmShowAppCredPresenter) { 31 this.presenter = presenter; 32 } 33} 34 35@Component 36export struct CredUserDetailPage { 37 private presenter: CmShowAppCredPresenter = CmShowAppCredPresenter.getInstance(); 38 39 private stack?: NavPathStack; 40 41 @State private bottomRectHeight: number = 80; 42 @State private headRectHeight: number = 64; 43 @State private headRectHeightReal: number = 0; 44 @Prop private sheetParam: SheetParam; 45 46 @State private itemBackgroundColor: ResourceColor = ''; 47 48 @Styles pressedStyles(): void { .backgroundColor($r('sys.color.ohos_id_color_click_effect')) } 49 50 @Styles normalStyles(): void { .backgroundColor(this.itemBackgroundColor) } 51 52 deleteWarnDialog: CustomDialogController = new CustomDialogController({ 53 builder: AlertDialog({ 54 primaryTitle: $r('app.string.warning_title'), 55 content: $r('app.string.warning_message'), 56 primaryButton: { 57 value: $r('app.string.cancelAuthApp'), 58 buttonStyle: ButtonStyleMode.TEXTUAL, 59 action: () => { 60 } 61 }, 62 secondaryButton: { 63 value: $r('app.string.deleteAllCredDelete'), 64 buttonStyle: ButtonStyleMode.TEXTUAL, 65 action: () => { 66 this.presenter.deleteAppCred(this.presenter.credInfo.keyUri); 67 this.stack?.pop(); 68 }, 69 role: ButtonRole.ERROR 70 } 71 }), 72 }) 73 74 build() { 75 NavDestination() { 76 Stack({ alignContent: Alignment.Bottom }) { 77 Stack({ alignContent: Alignment.Top }) { 78 Column() { 79 HeadComponent({ headName: $r('app.string.evidenceDetails'), isStartBySheet: true, onBackClicked: () => { 80 this.stack?.pop(); 81 } }) 82 .margin({ 83 left: $r('app.float.wh_value_12'), 84 top: 8 85 }) 86 }.onAreaChange((oldArea, newArea) => { 87 this.headRectHeight = newArea.height as number; 88 this.headRectHeightReal = newArea.height as number; 89 }).zIndex(1) 90 91 Column() { 92 Scroll() { 93 this.buildContent() 94 } 95 .align(Alignment.Top) 96 .scrollable(ScrollDirection.Vertical) 97 .scrollBar(BarState.Auto) 98 .edgeEffect(EdgeEffect.Spring) 99 .width(WidthPercent.WH_100_100) 100 .height(WidthPercent.WH_AUTO) 101 .constraintSize({ 102 minHeight: this.getScrollMinHeight() 103 }) 104 }.padding({ 105 top: this.headRectHeight 106 }) 107 } 108 .width(WidthPercent.WH_100_100) 109 .height(WidthPercent.WH_AUTO) 110 .padding({ 111 bottom: this.bottomRectHeight 112 }) 113 114 Column() { 115 Button($r('app.string.warning_title')) 116 .onClick(() => { 117 this.deleteWarnDialog.open(); 118 }) 119 .role(ButtonRole.ERROR) 120 .buttonStyle(ButtonStyleMode.NORMAL) 121 .margin({ 122 top: $r('app.float.distance_16'), 123 bottom: $r('app.float.distance_24') 124 }) 125 .width(WidthPercent.WH_100_100) 126 .constraintSize({ 127 minHeight: $r('app.float.wh_value_40') 128 }) 129 }.onAreaChange((oldArea: Area, newArea: Area) => { 130 this.bottomRectHeight = newArea.height as number; 131 }) 132 .padding({ 133 left: 16, right: 16 134 }) 135 } 136 } 137 .hideTitleBar(true) 138 .width(WidthPercent.WH_100_100) 139 .height(this.sheetParam?.lastSheetPage === NavEntryKey.CRED_USER_DETAIL_ENTRY ? 140 WidthPercent.WH_AUTO : this.sheetParam?.sheetMinHeight) 141 .backgroundColor($r('sys.color.background_secondary')) 142 .onReady((ctx: NavDestinationContext) => { 143 this.stack = ctx.pathStack; 144 try { 145 this.presenter = (ctx.pathInfo.param as CredUserDetailParam).presenter; 146 } catch (err) { 147 let error = err as BusinessError; 148 console.error(TAG + 'Get presenter failed: ' + error?.code + ', message: ' + error?.message); 149 } 150 }) 151 } 152 153 @Builder 154 private buildContent() { 155 Column() { 156 Text(this.presenter.credInfo.alias) 157 .fontSize($r('sys.float.ohos_id_text_size_body1')) 158 .fontColor($r('sys.color.ohos_id_color_text_primary')) 159 .fontWeight(FontWeight.Medium) 160 .margin({ 161 left: $r('app.float.wh_value_24'), 162 right: $r('app.float.wh_value_24') 163 }) 164 .alignSelf(ItemAlign.Start) 165 166 Text($r('app.string.entryContains')) 167 .fontSize($r('sys.float.ohos_id_text_size_body2')) 168 .fontColor($r('sys.color.ohos_id_color_text_primary')) 169 .fontWeight(FontWeight.Regular) 170 .margin({ 171 top: $r('app.float.wh_value_24'), 172 left: $r('app.float.wh_value_24'), 173 right: $r('app.float.wh_value_24') 174 }) 175 .alignSelf(ItemAlign.Start) 176 177 Text($r('app.string.keyNum', String(this.presenter.credInfo.keyNum))) 178 .fontSize($r('sys.float.ohos_id_text_size_body2')) 179 .fontColor($r('sys.color.ohos_id_color_text_primary')) 180 .fontWeight(FontWeight.Regular) 181 .margin({ 182 left: $r('app.float.wh_value_10'), 183 right: $r('app.float.wh_value_10') 184 }) 185 .opacity($r('app.float.opacity_100_60')) 186 .alignSelf(ItemAlign.Start) 187 188 Text($r('app.string.userCerNum', String(this.presenter.credInfo.certNum))) 189 .fontSize($r('sys.float.ohos_id_text_size_body2')) 190 .fontColor($r('sys.color.ohos_id_color_text_primary')) 191 .fontWeight(FontWeight.Regular) 192 .margin({ 193 left: $r('app.float.wh_value_10'), 194 right: $r('app.float.wh_value_10') 195 }) 196 .opacity($r('app.float.opacity_100_60')) 197 .alignSelf(ItemAlign.Start) 198 199 Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { 200 Column() { 201 Text($r('app.string.managerAuthApp')) 202 .fontSize($r('sys.float.ohos_id_text_size_body1')) 203 .fontColor($r('sys.color.ohos_id_color_text_primary')) 204 .fontWeight(FontWeight.Medium) 205 } 206 207 Row() { 208 Image($r('app.media.ic_settings_arrow')) 209 .width($r('app.float.managerAuthApp_image_wh')) 210 .height($r('app.float.managerAuthApp_image_hg')) 211 .fillColor($r('sys.color.ohos_id_color_primary')) 212 .opacity($r('app.float.managerAuthApp_image_opacity')) 213 } 214 } 215 .onClick(() => { 216 this.stack?.pushPath(new NavPathInfo(NavEntryKey.AUTHORIZED_APP_ENTRY, 217 new AuthorizedAppManagementParam(this.presenter))); 218 }) 219 .margin({ 220 top: $r('app.float.wh_value_12'), 221 left: $r('app.float.wh_value_16'), 222 right: $r('app.float.wh_value_16') 223 }) 224 .borderRadius($r('sys.float.corner_radius_level8')) 225 .backgroundColor(this.itemBackgroundColor) 226 .onHover((isHover?: boolean) => { 227 this.itemBackgroundColor = isHover ? $r('sys.color.ohos_id_color_hover') : ''; 228 }) 229 .stateStyles({ 230 pressed: this.pressedStyles, 231 normal: this.normalStyles 232 }) 233 .padding($r('app.float.wh_value_8')) 234 .constraintSize({ 235 minHeight: $r('app.float.wh_value_48') 236 }) 237 } 238 .width(WidthPercent.WH_100_100) 239 .alignItems(HorizontalAlign.Start) 240 } 241 242 getScrollMinHeight() { 243 if (this.sheetParam === undefined || this.headRectHeightReal === 0 || 244 this.sheetParam.sheetMinHeight < (this.headRectHeightReal + this.bottomRectHeight)) { 245 return 0; 246 } 247 return this.sheetParam.sheetMinHeight - this.headRectHeightReal - this.bottomRectHeight; 248 } 249}