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