• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * Copyright (c) 2022-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 { WidthPercent } from '../common/util/ConfigData';
17import HeadComponent from '../common/component/headComponent';
18import CmShowSysCaPresenter from '../presenter/CmShowSysCaPresenter';
19import CMShowUserCaPresenter from '../presenter/CmShowUserCaPresenter';
20import CmFaPresenter from '../presenter/CmFaPresenter';
21import { GlobalContext } from '../common/GlobalContext';
22import { CertAbstractVo } from '../model/CertManagerVo/CertAbstractVo';
23import ComponentConfig from '../common/component/ComponentConfig';
24import router from '@ohos.router';
25import { CustomContentDialog } from '@ohos.arkui.advanced.Dialog';
26import { NavEntryKey } from '../common/NavEntryKey';
27import { CaUserDetailParam } from './picker/CaUserDetailPage';
28
29const COPIES_NUM: number = 12;
30
31@Component
32export struct DialogSubjectComponent {
33  private map?: Map<string, string>;
34  private subjectNameCN: string = '';
35  private subjectNameO: string = '';
36  private subjectNameOU: string = '';
37  private serial: string = '';
38
39  aboutToAppear() {
40    if (this.map != null) {
41      let subjectNameCN = this.map.get('常用名称:');
42      if (subjectNameCN !== undefined) {
43        this.subjectNameCN = subjectNameCN;
44      }
45
46      let subjectNameO = this.map.get('组织:');
47      if (subjectNameO !== undefined) {
48        this.subjectNameO = subjectNameO;
49      }
50
51      let subjectNameOU = this.map.get('组织单位:');
52      if (subjectNameOU !== undefined) {
53        this.subjectNameOU = subjectNameOU;
54      }
55
56      let serial = this.map.get('序列号:');
57      if (serial !== undefined) {
58        this.serial = serial;
59      }
60    }
61  }
62
63  build() {
64    Column() {
65      Text($r('app.string.DialogSubjectComponent_firText'))
66        .fontSize($r('sys.float.ohos_id_text_size_body2'))
67        .fontColor($r('sys.color.ohos_id_color_text_primary'))
68        .fontWeight(FontWeight.Regular)
69        .margin({
70          top: $r('app.float.sys_elements_margin_vertical_l')
71        })
72      Text(this.subjectNameCN)
73        .fontSize($r('sys.float.ohos_id_text_size_body2'))
74        .fontColor($r('sys.color.ohos_id_color_text_primary'))
75        .fontWeight(FontWeight.Regular)
76      Text($r('app.string.DialogSubjectComponent_secText'))
77        .fontSize($r('sys.float.ohos_id_text_size_body2'))
78        .fontColor($r('sys.color.ohos_id_color_text_primary'))
79        .fontWeight(FontWeight.Regular)
80        .margin({
81          top: $r('app.float.sys_elements_margin_vertical_m')
82        })
83      Text(this.subjectNameO)
84        .fontSize($r('sys.float.ohos_id_text_size_body2'))
85        .fontColor($r('sys.color.ohos_id_color_text_primary'))
86        .fontWeight(FontWeight.Regular)
87      Text($r('app.string.DialogSubjectComponent_thdText'))
88        .fontSize($r('sys.float.ohos_id_text_size_body2'))
89        .fontColor($r('sys.color.ohos_id_color_text_primary'))
90        .fontWeight(FontWeight.Regular)
91        .margin({
92          top: $r('app.float.sys_elements_margin_vertical_m')
93        })
94      Text(this.subjectNameOU)
95        .fontSize($r('sys.float.ohos_id_text_size_body2'))
96        .fontColor($r('sys.color.ohos_id_color_text_primary'))
97        .fontWeight(FontWeight.Regular)
98      Text($r('app.string.DialogSubjectComponent_fouText'))
99        .fontSize($r('sys.float.ohos_id_text_size_body2'))
100        .fontColor($r('sys.color.ohos_id_color_text_primary'))
101        .fontWeight(FontWeight.Regular)
102        .margin({
103          top: $r('app.float.sys_elements_margin_vertical_m')
104        })
105      Text(this.serial)
106        .fontSize($r('sys.float.ohos_id_text_size_body2'))
107        .fontColor($r('sys.color.ohos_id_color_text_primary'))
108        .fontWeight(FontWeight.Regular)
109    }.alignItems(HorizontalAlign.Start);
110  }
111}
112
113@Component
114export struct DialogIssuerComponent {
115  private map?: Map<string, string>;
116  private issuerNameCN: string = '';
117  private issuerNameO: string = '';
118  private issuerNameOU: string = '';
119
120  aboutToAppear() {
121    if (this.map != null) {
122      let issuerNameCN = this.map.get('常用名称:');
123      if (issuerNameCN !== undefined) {
124        this.issuerNameCN = issuerNameCN;
125      }
126
127      let issuerNameO = this.map.get('组织:');
128      if (issuerNameO !== undefined) {
129        this.issuerNameO = issuerNameO;
130      }
131
132      let issuerNameOU = this.map.get('组织单位:');
133      if (issuerNameOU !== undefined) {
134        this.issuerNameOU = issuerNameOU;
135      }
136    }
137  }
138
139  build() {
140    Column() {
141      Text($r('app.string.DialogSubjectComponent_firText'))
142        .fontSize($r('sys.float.ohos_id_text_size_body2'))
143        .fontColor($r('sys.color.ohos_id_color_text_primary'))
144        .fontWeight(FontWeight.Regular)
145        .margin({
146          top: $r('app.float.sys_elements_margin_vertical_l')
147        })
148      Text(this.issuerNameCN)
149        .fontSize($r('sys.float.ohos_id_text_size_body2'))
150        .fontColor($r('sys.color.ohos_id_color_text_primary'))
151        .fontWeight(FontWeight.Regular)
152      Text($r('app.string.DialogSubjectComponent_secText'))
153        .fontSize($r('sys.float.ohos_id_text_size_body2'))
154        .fontColor($r('sys.color.ohos_id_color_text_primary'))
155        .fontWeight(FontWeight.Regular)
156        .margin({
157          top: $r('app.float.sys_elements_margin_vertical_m')
158        })
159      Text(this.issuerNameO)
160        .fontSize($r('sys.float.ohos_id_text_size_body2'))
161        .fontColor($r('sys.color.ohos_id_color_text_primary'))
162        .fontWeight(FontWeight.Regular)
163      Text($r('app.string.DialogSubjectComponent_thdText'))
164        .fontSize($r('sys.float.ohos_id_text_size_body2'))
165        .fontColor($r('sys.color.ohos_id_color_text_primary'))
166        .fontWeight(FontWeight.Regular)
167        .margin({
168          top: $r('app.float.sys_elements_margin_vertical_m')
169        })
170      Text(this.issuerNameOU)
171        .fontSize($r('sys.float.ohos_id_text_size_body2'))
172        .fontColor($r('sys.color.ohos_id_color_text_primary'))
173        .fontWeight(FontWeight.Regular)
174    }.alignItems(HorizontalAlign.Start);
175  }
176}
177
178@Component
179export struct DialogDateComponent {
180  private map?: Map<string, string>;
181  private notBefore: string = '';
182  private notAfter: string = '';
183
184  aboutToAppear() {
185    if (this.map != null) {
186      let notBefore = this.map.get('颁发时间:');
187      if (notBefore != undefined) {
188        this.notBefore = notBefore;
189      }
190
191      let notAfter = this.map.get('有效期至:');
192      if (notAfter != undefined) {
193        this.notAfter = notAfter;
194      }
195    }
196  }
197
198  build() {
199    Column() {
200      Text($r('app.string.DialogSubjectComponent_fifText'))
201        .fontSize($r('sys.float.ohos_id_text_size_body2'))
202        .fontColor($r('sys.color.ohos_id_color_text_primary'))
203        .fontWeight(FontWeight.Regular)
204        .margin({
205          top: $r('app.float.sys_elements_margin_vertical_l')
206        })
207      Text(this.notBefore)
208        .fontSize($r('sys.float.ohos_id_text_size_body2'))
209        .fontColor($r('sys.color.ohos_id_color_text_primary'))
210        .fontWeight(FontWeight.Regular)
211      Text($r('app.string.DialogSubjectComponent_sixText'))
212        .fontSize($r('sys.float.ohos_id_text_size_body2'))
213        .fontColor($r('sys.color.ohos_id_color_text_primary'))
214        .fontWeight(FontWeight.Regular)
215        .margin({
216          top: $r('app.float.sys_elements_margin_vertical_m')
217        })
218      Text(this.notAfter)
219        .fontSize($r('sys.float.ohos_id_text_size_body2'))
220        .fontColor($r('sys.color.ohos_id_color_text_primary'))
221        .fontWeight(FontWeight.Regular)
222    }.alignItems(HorizontalAlign.Start);
223  }
224}
225
226@Component
227export struct DialogFingerPrintComponent {
228  private fingerprintSha256: string = '';
229
230  build() {
231    Column() {
232      Text($r('app.string.CustomDialogExample_FingerPrint_text'))
233        .fontSize($r('sys.float.ohos_id_text_size_body2'))
234        .fontColor($r('sys.color.ohos_id_color_text_primary'))
235        .fontWeight(FontWeight.Regular)
236        .margin({
237          top: $r('app.float.sys_elements_margin_vertical_l')
238        })
239      Text(this.fingerprintSha256)
240        .fontSize($r('sys.float.ohos_id_text_size_body2'))
241        .fontColor($r('sys.color.ohos_id_color_text_primary'))
242        .fontWeight(FontWeight.Regular)
243        .margin({
244          right: $r('app.float.wh_value_24')
245        })
246    }.alignItems(HorizontalAlign.Start);
247  }
248}
249
250@Component
251struct ComponentSystem {
252  private certAlias: string = '';
253  private subjectName: string = '';
254  private uri: string = '';
255  @Link setStatus: CmShowSysCaPresenter;
256  private sysCaScroller: Scroller = new Scroller();
257
258  onItemClicked?: () => void;
259
260  @State isHoverBackgroundColor: ResourceColor = '';
261  @Styles pressedStyles(): void {
262    .backgroundColor($r('sys.color.ohos_id_color_click_effect'))
263  }
264  @Styles normalStyles(): void {
265    .backgroundColor(this.isHoverBackgroundColor)
266  }
267
268  systemDetailsDialog: CustomDialogController = new CustomDialogController({
269    alignment: DialogAlignment.Center,
270    builder: CustomContentDialog({
271      contentBuilder: () => {
272        this.systemDetailContent();
273      },
274      contentAreaPadding: { right: $r('app.float.wh_value_0') },
275      buttons: [{
276        value: $r('app.string.CustomDialogExample_Button_text'),
277        buttonStyle: ButtonStyleMode.TEXTUAL,
278        action: () => {
279          this.systemDetailsDialog?.close();
280        }
281      }]
282    })
283  })
284
285  @Builder
286  systemDetailContent(): void {
287    Column() {
288      Text($r('app.string.CustomDialogExample_firText'))
289        .fontSize($r('sys.float.ohos_id_text_size_dialog_tittle'))
290        .fontColor($r('sys.color.ohos_id_color_text_primary'))
291        .fontWeight(FontWeight.Medium)
292        .height($r('app.float.wh_value_56'))
293        .margin({
294          bottom: $r('app.float.wh_value_8'),
295          right: $r('app.float.wh_value_24')
296        })
297        .alignSelf(ItemAlign.Start)
298
299      Text(this.setStatus.certInfo.certAlias)
300        .fontSize($r('sys.float.ohos_id_text_size_body1'))
301        .fontColor($r('sys.color.ohos_id_color_text_primary'))
302        .fontWeight(FontWeight.Medium)
303        .margin({
304          bottom: $r('app.float.wh_value_24'),
305          right: $r('app.float.wh_value_24')
306        })
307        .alignSelf(ItemAlign.Start)
308
309      Scroll(this.sysCaScroller) {
310        List() {
311          ListItem() {
312            Text($r('app.string.CustomDialogExample_firListItem_text'))
313              .fontSize($r('sys.float.ohos_id_text_size_body1'))
314              .fontColor($r('sys.color.ohos_id_color_text_primary'))
315              .fontWeight(FontWeight.Medium)
316          }.width(ComponentConfig.WH_100_100).align(Alignment.Start)
317
318          ListItem() {
319            DialogSubjectComponent({ map: this.setStatus.certInfo.subjectNameMap });
320          }.width(ComponentConfig.WH_100_100).align(Alignment.Start)
321
322          ListItem() {
323            Text($r('app.string.CustomDialogExample_secListItem_text'))
324              .fontSize($r('sys.float.ohos_id_text_size_body1'))
325              .fontColor($r('sys.color.ohos_id_color_text_primary'))
326              .fontWeight(FontWeight.Medium)
327          }.width(ComponentConfig.WH_100_100).align(Alignment.Start)
328          .margin({
329            top: $r('app.float.wh_value_24')
330          })
331
332          ListItem() {
333            DialogIssuerComponent({ map: this.setStatus.certInfo.issuerNameMap });
334          }.width(ComponentConfig.WH_100_100).align(Alignment.Start)
335
336          ListItem() {
337            Text($r('app.string.CustomDialogExample_thdListItem_text'))
338              .fontSize($r('sys.float.ohos_id_text_size_body1'))
339              .fontColor($r('sys.color.ohos_id_color_text_primary'))
340              .fontWeight(FontWeight.Medium)
341          }.width(ComponentConfig.WH_100_100).align(Alignment.Start)
342          .margin({
343            top: $r('app.float.wh_value_24')
344          })
345
346          ListItem() {
347            DialogDateComponent({ map: this.setStatus.certInfo.dateMap });
348          }.width(ComponentConfig.WH_100_100).align(Alignment.Start)
349
350          ListItem() {
351            Text($r('app.string.CustomDialogExample_fouListItem_text'))
352              .fontSize($r('sys.float.ohos_id_text_size_body1'))
353              .fontColor($r('sys.color.ohos_id_color_text_primary'))
354              .fontWeight(FontWeight.Medium)
355          }.width(ComponentConfig.WH_100_100).align(Alignment.Start)
356          .margin({
357            top: $r('app.float.wh_value_24')
358          })
359
360          ListItem() {
361            DialogFingerPrintComponent({ fingerprintSha256: this.setStatus.certInfo.fingerprintSha256 });
362          }.width(ComponentConfig.WH_100_100).align(Alignment.Start)
363        }
364        .margin({ right: $r('app.float.wh_value_24') })
365        .scrollBar(BarState.Off)
366      }
367      .scrollable(ScrollDirection.Vertical)
368      .scrollBarWidth('3vp')
369      .height($r('app.float.CustomDialogExample_list_height_value'))
370    }
371    .padding({
372      left: $r('app.float.wh_value_24'),
373    })
374    .width(WidthPercent.WH_100_100)
375    .borderRadius($r('app.float.user_list_divider_borderRadius_value'))
376    .backgroundColor($r('sys.color.ohos_id_color_dialog_bg'))
377  }
378
379  build() {
380    Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) {
381      Column() {
382        Text(this.certAlias)
383          .fontSize($r('sys.float.ohos_id_text_size_body1'))
384          .fontColor($r('sys.color.ohos_id_color_text_primary'))
385          .fontWeight(FontWeight.Medium)
386          .textAlign(TextAlign.Start)
387          .margin({ top: $r('app.float.wh_value_10') });
388        Text(this.subjectName)
389          .fontSize($r('sys.float.ohos_id_text_size_body2'))
390          .fontColor($r('sys.color.ohos_id_color_text_secondary'))
391          .fontWeight(FontWeight.Regular)
392          .textAlign(TextAlign.Start)
393          .margin({ top: $r('app.float.wh_value_2'), bottom: $r('app.float.wh_value_11') });
394      }.alignItems(HorizontalAlign.Start);
395    }
396    .onHover((isHover?: boolean) => {
397      this.isHoverBackgroundColor = isHover ? $r('sys.color.ohos_id_color_hover') : ''
398    })
399    .backgroundColor(this.isHoverBackgroundColor)
400    .stateStyles({
401      pressed: this.pressedStyles,
402      normal: this.normalStyles
403    })
404    .padding({
405      left: $r('app.float.wh_value_8'),
406      right: $r('app.float.wh_value_8')
407    })
408    .borderRadius($r('app.float.wh_value_20'))
409    .onClick(() => {
410      this.setStatus.getSystemTrustedCertificate(this.uri, () => {
411        if (this.onItemClicked !== undefined) {
412          this.onItemClicked();
413        } else {
414          this.systemDetailsDialog.open();
415        }
416      });
417    })
418  }
419}
420
421@Component
422struct ComponentUser {
423  private certAlias: string = '';
424  private subjectName: string = '';
425  private indexNum: number = -1;
426  private uri: string = '';
427  @State statusText: Resource = $r('app.string.CustomDialogExampleUser_Status_false');
428  @Link setStatus: CMShowUserCaPresenter;
429  @State mUserCaPresenterDetail: CMShowUserCaPresenter = CMShowUserCaPresenter.getInstance();
430  private userCaScroller: Scroller = new Scroller();
431
432  onItemClicked?: () => void;
433
434  @State isHoverBackgroundColor: ResourceColor = '';
435  @Styles pressedStyles(): void {
436    .backgroundColor($r('sys.color.ohos_id_color_click_effect'))
437  }
438  @Styles normalStyles(): void {
439    .backgroundColor(this.isHoverBackgroundColor)
440  }
441
442  rootCertificateDialog: CustomDialogController = new CustomDialogController({
443    alignment: DialogAlignment.Center,
444    builder: CustomContentDialog({
445      contentBuilder: () => {
446        this.rootCertificateContent();
447      },
448      contentAreaPadding: { right: $r('app.float.wh_value_0') },
449      buttons: [
450        {
451          value: $r('app.string.root_certificate_cancel'),
452          buttonStyle: ButtonStyleMode.TEXTUAL,
453          action: () => {
454            this.setStatus.updateUserTrustedCertificateList();
455          }
456        },
457        {
458          value: $r('app.string.root_certificate_continue'),
459          buttonStyle: ButtonStyleMode.TEXTUAL,
460          action: () => {
461            this.setStatus.setUserCertificateStatus(this.mUserCaPresenterDetail.certInfo.uri, true).then(result => {
462              if (result) {
463                this.setStatus.updateUserTrustedCertificateList();
464              }
465            });
466          }
467        }
468      ]
469    })
470  })
471
472  userDetailsDialog: CustomDialogController = new CustomDialogController({
473    alignment: DialogAlignment.Center,
474    builder: CustomContentDialog({
475      contentBuilder: () => {
476        this.userDetailContent(this.setStatus.certList[this.indexNum].status);
477      },
478      contentAreaPadding: { right: $r('app.float.wh_value_0') },
479      buttons: [
480        {
481          value: $r('app.string.CustomDialogExampleUser_Flex_firButton_text'),
482          buttonStyle: ButtonStyleMode.TEXTUAL,
483          action: () => {
484            this.setStatus.updateUserTrustedCertificateList();
485            this.userDetailsDialog?.close();
486          }
487        },
488        {
489          value: $r('app.string.CustomDialogExampleUser_Flex_secButton_text'),
490          buttonStyle: ButtonStyleMode.TEXTUAL,
491          action: () => {
492            this.setStatus.updateUserTrustedCertificateList();
493            this.onShowDeleteWarnDialog();
494          },
495          role: ButtonRole.ERROR
496        }
497      ]
498    })
499  })
500
501  deleteCertWarnDialog: CustomDialogController = new CustomDialogController({
502    builder: CustomContentDialog({
503      contentBuilder: () => {
504        this.deleteWarnContent();
505      },
506      contentAreaPadding: { right: $r('app.float.wh_value_0') },
507      buttons: [
508        {
509          value: $r('app.string.deleteAllCredCancel'),
510          buttonStyle: ButtonStyleMode.TEXTUAL,
511          action: () => {
512            this.setStatus.updateUserTrustedCertificateList();
513            this.deleteCertWarnDialog?.close();
514          }
515        },
516        {
517          value: $r('app.string.deleteAllCredDelete'),
518          buttonStyle: ButtonStyleMode.TEXTUAL,
519          action: () => {
520            this.setStatus.deleteUserCertificate(this.mUserCaPresenterDetail.certInfo.uri, () => {
521              this.setStatus.updateUserTrustedCertificateList();
522              this.deleteCertWarnDialog?.close();
523            })
524          },
525          role: ButtonRole.ERROR
526        }
527      ]
528    })
529  })
530
531  @Builder
532  rootCertificateContent(): void {
533    Column() {
534      Text($r('app.string.root_certificate'))
535        .height($r('app.float.wh_value_56'))
536        .fontSize($r('sys.float.ohos_id_text_size_dialog_tittle'))
537        .fontColor($r('sys.color.ohos_id_color_text_primary'))
538        .fontWeight(FontWeight.Medium)
539        .margin({
540          left: $r('app.float.wh_value_24'),
541          right: $r('app.float.wh_value_24')
542        })
543        .alignSelf(ItemAlign.Start)
544
545      Text($r('app.string.root_certificate_message'))
546        .fontSize($r('sys.float.ohos_id_text_size_body1'))
547        .fontWeight(FontWeight.Regular)
548        .fontColor($r('sys.color.ohos_id_color_primary'))
549        .margin({
550          left: $r('app.float.wh_value_24'),
551          right: $r('app.float.wh_value_24')
552        })
553        .alignSelf(ItemAlign.Start)
554    }
555    .width(WidthPercent.WH_100_100)
556    .borderRadius($r('app.float.user_list_divider_borderRadius_value'))
557    .backgroundColor($r('sys.color.ohos_id_color_dialog_bg'))
558  }
559
560  @Builder
561  deleteWarnContent(): void {
562    Column() {
563      Text($r('app.string.CustomDialogExampleUser_warning_Button_title_text'))
564        .height($r('app.float.wh_value_56'))
565        .fontSize($r('sys.float.ohos_id_text_size_dialog_tittle'))
566        .fontColor($r('sys.color.ohos_id_color_text_primary'))
567        .fontWeight(FontWeight.Medium)
568        .margin({
569          left: $r('app.float.wh_value_24'),
570          right: $r('app.float.wh_value_24')
571        })
572        .alignSelf(ItemAlign.Start)
573
574      Text($r('app.string.CustomDialogExampleUser_warning_Button_message_text'))
575        .fontSize($r('sys.float.ohos_id_text_size_body1'))
576        .fontWeight(FontWeight.Regular)
577        .fontColor($r('sys.color.ohos_id_color_primary'))
578        .margin({
579          left: $r('app.float.wh_value_24'),
580          right: $r('app.float.wh_value_24')
581        })
582        .alignSelf(ItemAlign.Start)
583    }
584    .width(WidthPercent.WH_100_100)
585    .borderRadius($r('app.float.user_list_divider_borderRadius_value'))
586    .backgroundColor($r('sys.color.ohos_id_color_dialog_bg'))
587  }
588
589  @Builder
590  userDetailContent($$: boolean): void {
591    Column() {
592      Text($r('app.string.CustomDialogExample_firText'))
593        .fontSize($r('sys.float.ohos_id_text_size_dialog_tittle'))
594        .fontColor($r('sys.color.ohos_id_color_text_primary'))
595        .fontWeight(FontWeight.Medium)
596        .height($r('app.float.wh_value_56'))
597        .margin({
598          bottom: $r('app.float.wh_value_8'),
599          right: $r('app.float.wh_value_24')
600        })
601        .alignSelf(ItemAlign.Start)
602
603      Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) {
604        Column() {
605          Text(this.mUserCaPresenterDetail.certInfo.certAlias)
606            .fontSize($r('sys.float.ohos_id_text_size_body1'))
607            .fontColor($r('sys.color.ohos_id_color_text_primary'))
608            .fontWeight(FontWeight.Medium)
609        }.alignItems(HorizontalAlign.Start);
610
611        Toggle({ type: ToggleType.Switch, isOn: $$ })
612          .margin({
613            left: $r('app.float.wh_value_16'),
614            right: $r('app.float.wh_value_24')
615          })
616          .flexShrink(0)
617          .width($r('app.float.CustomDialogExampleUser_Flex_Toggle_width_value'))
618          .height($r('app.float.CustomDialogExampleUser_Flex_Toggle_height_value'))
619          .selectedColor($r('app.color.CustomDialogExampleUser_Flex_Toggle_selectedColor_007DFF'))
620          .onChange((isOn: boolean) => {
621            if (isOn) {
622              this.onShowRootCertificateDialog();
623            } else {
624              this.setStatus.setUserCertificateStatus(this.mUserCaPresenterDetail.certInfo.uri, false);
625            }
626          });
627      }
628
629      Scroll(this.userCaScroller) {
630        List() {
631          ListItem() {
632            Text($r('app.string.CustomDialogExample_firListItem_text'))
633              .fontSize($r('sys.float.ohos_id_text_size_body1'))
634              .fontColor($r('sys.color.ohos_id_color_text_primary'))
635              .fontWeight(FontWeight.Medium)
636              .margin({
637                top: $r('app.float.wh_value_24')
638              })
639          }.width(ComponentConfig.WH_100_100).align(Alignment.Start)
640
641          ListItem() {
642            DialogSubjectComponent({ map: this.mUserCaPresenterDetail.certInfo.subjectNameMap });
643          }.width(ComponentConfig.WH_100_100).align(Alignment.Start)
644
645          ListItem() {
646            Text($r('app.string.CustomDialogExample_secListItem_text'))
647              .fontSize($r('sys.float.ohos_id_text_size_body1'))
648              .fontColor($r('sys.color.ohos_id_color_text_primary'))
649              .fontWeight(FontWeight.Medium)
650              .margin({
651                top: $r('app.float.wh_value_24')
652              })
653          }.width(ComponentConfig.WH_100_100).align(Alignment.Start)
654
655          ListItem() {
656            DialogIssuerComponent({ map: this.mUserCaPresenterDetail.certInfo.issuerNameMap });
657          }.width(ComponentConfig.WH_100_100).align(Alignment.Start)
658
659          ListItem() {
660            Text($r('app.string.CustomDialogExample_thdListItem_text'))
661              .fontSize($r('sys.float.ohos_id_text_size_body1'))
662              .fontColor($r('sys.color.ohos_id_color_text_primary'))
663              .fontWeight(FontWeight.Medium)
664              .margin({
665                top: $r('app.float.wh_value_24')
666              })
667          }.width(ComponentConfig.WH_100_100).align(Alignment.Start)
668
669          ListItem() {
670            DialogDateComponent({ map: this.mUserCaPresenterDetail.certInfo.dateMap });
671          }.width(ComponentConfig.WH_100_100).align(Alignment.Start)
672
673          ListItem() {
674            Text($r('app.string.CustomDialogExample_fouListItem_text'))
675              .fontSize($r('sys.float.ohos_id_text_size_body1'))
676              .fontColor($r('sys.color.ohos_id_color_text_primary'))
677              .fontWeight(FontWeight.Medium)
678              .margin({
679                top: $r('app.float.wh_value_24')
680              })
681          }.width(ComponentConfig.WH_100_100).align(Alignment.Start)
682
683          ListItem() {
684            DialogFingerPrintComponent({
685              fingerprintSha256: this.mUserCaPresenterDetail.certInfo.fingerprintSha256
686            });
687          }.width(ComponentConfig.WH_100_100).align(Alignment.Start)
688        }
689        .margin({
690          right: $r('app.float.wh_value_24')
691        })
692        .scrollBar(BarState.Off)
693      }
694      .height($r('app.float.CustomDialogExample_list_height_value'))
695      .scrollable(ScrollDirection.Vertical)
696      .scrollBarWidth('3vp')
697    }
698    .padding({
699      left: $r('app.float.wh_value_24')
700    })
701    .width(WidthPercent.WH_100_100)
702    .borderRadius($r('app.float.user_list_divider_borderRadius_value'))
703    .backgroundColor($r('sys.color.ohos_id_color_dialog_bg'))
704  }
705
706  onShowRootCertificateDialog() {
707    this.userDetailsDialog?.close();
708    this.rootCertificateDialog.open();
709  }
710
711  onShowDeleteWarnDialog() {
712    this.deleteCertWarnDialog.open();
713    this.userDetailsDialog?.close();
714  }
715
716  aboutToAppear() {
717    console.info('in ComponentUser aboutToAppear');
718    if (this.setStatus.certList[this.indexNum].status == true) {
719      this.statusText = $r('app.string.CustomDialogExampleUser_Status_true');
720    } else {
721      this.statusText = $r('app.string.CustomDialogExampleUser_Status_false');
722    }
723  }
724
725  build() {
726    Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) {
727      Column() {
728        Text(this.certAlias)
729          .fontSize($r('sys.float.ohos_id_text_size_body1'))
730          .fontColor($r('sys.color.ohos_id_color_text_primary'))
731          .fontWeight(FontWeight.Medium)
732          .textAlign(TextAlign.Start)
733          .margin({ top: $r('app.float.wh_value_10') })
734        Text(this.subjectName)
735          .fontSize($r('sys.float.ohos_id_text_size_body2'))
736          .fontColor($r('sys.color.ohos_id_color_text_primary'))
737          .fontWeight(FontWeight.Regular)
738          .textAlign(TextAlign.Start)
739          .margin({ top: $r('app.float.wh_value_2'), bottom: $r('app.float.wh_value_11') });
740      }
741      .alignItems(HorizontalAlign.Start);
742      Row() {
743        Text(this.statusText)
744          .fontSize($r('sys.float.ohos_id_text_size_body2'))
745          .fontColor($r('sys.color.ohos_id_color_text_secondary'))
746          .textAlign(TextAlign.End)
747          .margin({
748            right: $r('app.float.componentUser_thdText_margin_value')
749          })
750        Image($r('app.media.ic_settings_arrow'))
751          .width($r('app.float.componentUser_image_width_value'))
752          .height($r('app.float.componentUser_image_height_value'))
753          .fillColor($r('sys.color.ohos_id_color_primary'))
754          .opacity($r('app.float.componentUser_image_opacity_value'));
755      }
756      .flexShrink(0)
757      .margin($r('app.float.wh_value_12'))
758    }
759    .onHover((isHover?: boolean) => {
760      this.isHoverBackgroundColor = isHover ? $r('sys.color.ohos_id_color_hover') : ''
761    })
762    .backgroundColor(this.isHoverBackgroundColor)
763    .stateStyles({
764      pressed: this.pressedStyles,
765      normal: this.normalStyles
766    })
767    .padding({
768      left: $r('app.float.wh_value_8'),
769      right: $r('app.float.wh_value_8')
770    })
771    .borderRadius($r('app.float.wh_value_20'))
772    .onClick(() => {
773      this.mUserCaPresenterDetail.getUserTrustedCertificate(this.uri, () => {
774        if (this.onItemClicked !== undefined) {
775          this.onItemClicked();
776        } else {
777          this.userDetailsDialog.open();
778        }
779      });
780    });
781  }
782}
783
784@Entry
785@Component
786export struct TrustedEvidence {
787  @State mShowSysCaPresenter: CmShowSysCaPresenter = CmShowSysCaPresenter.getInstance();
788  @State mShowUserCaPresenter: CMShowUserCaPresenter = CMShowUserCaPresenter.getInstance();
789  @State mFaPresenter: CmFaPresenter = CmFaPresenter.getInstance();
790  @State currentIndex: number = 0;
791  @State fontColor: Resource = $r('app.color.TrustedEvidence_TabBuilder_fontColor_182431');
792  @State selectedFontColor: Resource = $r('app.color.font_color_007DFF');
793  private controller: TabsController = new TabsController();
794  private sysCaScroller: Scroller = new Scroller();
795  private userCaScroller: Scroller = new Scroller();
796  @State animationDurationNum: number = 400;
797
798  isStartBySheetFirst: boolean = false;
799  isStartBySheet: boolean = false;
800  selected?: (path: string, param?: Object) => void;
801
802  @Builder
803  TabBuilder(index: number) {
804    Column() {
805      Text(index == 0 ? $r('app.string.system') : $r('app.string.user'))
806        .fontColor(this.currentIndex === index ? this.selectedFontColor : this.fontColor)
807        .fontSize($r('app.float.TrustedEvidence_TabBuilder_Text_fontSize_value'))
808        .fontWeight(this.currentIndex === index ? FontWeight.Medium : FontWeight.Regular)
809        .alignSelf(ItemAlign.Center)
810        .margin({
811          top: $r('app.float.TrustedEvidence_TabBuilder_Text_padding_top_value')
812        })
813      if (this.currentIndex === index) {
814        Divider()
815          .width($r('app.float.TrustedEvidence_TabBuilder_Divider_width_value'))
816          .margin({ top: $r('app.float.TrustedEvidence_TabBuilder_Divider_padding_top_value') })
817          .color(this.selectedFontColor)
818          .alignSelf(ItemAlign.Center)
819      }
820    }
821    .width(WidthPercent.WH_100_100)
822  }
823
824  aboutToAppear() {
825    this.mShowSysCaPresenter.updateSystemTrustedCertificateList();
826    this.mShowUserCaPresenter.updateUserTrustedCertificateList();
827  }
828
829  onPageShow() {
830    let uri = GlobalContext.getContext().getAbilityWant().uri;
831    GlobalContext.getContext().clearAbilityWantUri();
832
833    if (uri === 'certInstall') {
834      router.pushUrl({
835        url: 'pages/certInstallFromStorage'
836      })
837    } else if (uri === 'requestAuthorize') {
838      this.mFaPresenter.startRequestAuth(GlobalContext.getContext().getAbilityWant().parameters?.appUid as string);
839    } else {
840      console.error('The want type is not supported');
841    }
842  }
843
844  build() {
845    Column() {
846      GridRow({ columns: COPIES_NUM, gutter: vp2px(1) === 2 ? $r('app.float.wh_value_12') : $r('app.float.wh_value_0') }) {
847        GridCol({ span: COPIES_NUM }) {
848          Row() {
849            Column() {
850              HeadComponent({ headName: $r('app.string.CA_cert'), isStartBySheet: this.isStartBySheet,
851                icBackIsVisibility: !this.isStartBySheetFirst,
852                onBackClicked: () => {
853                  this.selected?.(NavEntryKey.POP);
854                }})
855                .margin({
856                  left: $r('app.float.wh_value_12'),
857                  top: this.isStartBySheet ? 8 : 0
858                })
859
860              Column() {
861                Tabs({ barPosition: BarPosition.Start, index: 0, controller: this.controller }) {
862                  TabContent() {
863                    Stack({ alignContent: Alignment.End }) {
864                      Scroll(this.sysCaScroller) {
865                        List() {
866                          ForEach(this.mShowSysCaPresenter.certList, (item: CertAbstractVo) => {
867                            ListItem() {
868                              ComponentSystem({
869                                certAlias: item.certAlias,
870                                subjectName: item.subjectNameCN,
871                                uri: item.uri,
872                                setStatus: $mShowSysCaPresenter,
873                                onItemClicked: this.isStartBySheet ? () => {
874                                  this.selected?.(NavEntryKey.CA_SYSTEM_DETAIL_ENTRY);
875                                } : undefined
876                              })
877                            }
878                          }, (item: CertAbstractVo) => JSON.stringify(item))
879                        }
880                        .borderRadius($r('sys.float.padding_level10'))
881                        .backgroundColor($r('sys.color.ohos_id_color_card_bg'))
882                        .scrollBar(BarState.Off)
883                        .padding({
884                          right: $r('app.float.wh_value_4'),
885                          left: $r('app.float.wh_value_4'),
886                          top: $r('app.float.wh_value_4'),
887                          bottom: $r('app.float.wh_value_4')
888                        })
889                        .divider({
890                          strokeWidth: $r('app.float.sys_list_divider_strokeWidth_value'),
891                          color: $r('sys.color.ohos_id_color_list_separator'),
892                          startMargin: $r('app.float.wh_value_8'),
893                          endMargin: $r('app.float.wh_value_8')
894                        })
895                        .visibility(this.mShowSysCaPresenter.certList.length > 0
896                          ? Visibility.Visible : Visibility.None)
897                      }
898                      .position({ y: $r('app.float.wh_value_0') })
899                      .width(WidthPercent.WH_100_100)
900                      .height(WidthPercent.WH_100_100)
901                      .align(Alignment.Top)
902                      .edgeEffect(EdgeEffect.Spring)
903                      .scrollable(ScrollDirection.Vertical)
904                      .scrollBar(BarState.Auto)
905                      .padding({
906                        left: $r('app.float.wh_value_12'),
907                        right: $r('app.float.wh_value_12'),
908                        bottom: $r('app.float.wh_value_24')
909                      })
910                    }
911                    .backgroundColor($r('sys.color.ohos_id_color_sub_background'))
912                  }
913                  .tabBar(this.TabBuilder(0))
914
915                  TabContent() {
916                    Stack({ alignContent: Alignment.End }) {
917                      Scroll(this.userCaScroller) {
918                        List() {
919                          ForEach(this.mShowUserCaPresenter.certList, (item: CertAbstractVo, index) => {
920                            ListItem() {
921                              ComponentUser({
922                                certAlias: item.certAlias,
923                                subjectName: item.subjectNameCN,
924                                uri: item.uri,
925                                setStatus: $mShowUserCaPresenter,
926                                indexNum: index,
927                                onItemClicked: this.isStartBySheet ? () => {
928                                  this.selected?.(NavEntryKey.CA_USER_DETAIL_ENTRY,
929                                    new CaUserDetailParam(this.mShowUserCaPresenter));
930                                } : undefined
931                              })
932                            }
933                          }, (item: CertAbstractVo) => JSON.stringify(item))
934                        }
935                        .borderRadius($r('sys.float.padding_level10'))
936                        .backgroundColor($r('sys.color.ohos_id_color_card_bg'))
937                        .divider({
938                          strokeWidth: $r('app.float.sys_list_divider_strokeWidth_value'),
939                          color: $r('sys.color.ohos_id_color_list_separator'),
940                          startMargin: $r('app.float.wh_value_8'),
941                          endMargin: $r('app.float.wh_value_8')
942                        })
943                        .scrollBar(BarState.Off)
944                        .padding({
945                          left: $r('app.float.wh_value_4'),
946                          right: $r('app.float.wh_value_4'),
947                          top: $r('app.float.wh_value_4'),
948                          bottom: $r('app.float.wh_value_4')
949                        })
950                        .visibility(this.mShowUserCaPresenter.certList.length > 0
951                          ? Visibility.Visible : Visibility.None)
952                      }
953                      .position({ y: $r('app.float.wh_value_0') })
954                      .width(WidthPercent.WH_100_100)
955                      .height(WidthPercent.WH_100_100)
956                      .align(Alignment.Top)
957                      .edgeEffect(EdgeEffect.Spring)
958                      .scrollable(ScrollDirection.Vertical)
959                      .scrollBar(BarState.Auto)
960                      .padding({
961                        left: $r('app.float.wh_value_12'),
962                        right: $r('app.float.wh_value_12'),
963                        bottom: $r('app.float.wh_value_24')
964                      })
965                    }
966                    .backgroundColor($r('sys.color.ohos_id_color_sub_background'))
967                  }
968                  .tabBar(this.TabBuilder(1))
969                }
970                .vertical(false)
971                .scrollable(true)
972                .barMode(BarMode.Fixed)
973                .barWidth($r('app.float.tabs_barWidth_value'))
974                .barHeight($r('app.float.tabs_barHeight_value'))
975                .animationDuration(this.animationDurationNum)
976                .width(WidthPercent.WH_100_100)
977                .margin({
978                  bottom: $r('app.float.wh_value_24')
979                })
980                .backgroundColor($r('sys.color.ohos_id_color_sub_background'))
981                .onChange((index: number) => {
982                  this.currentIndex = index;
983                });
984              }
985              .height(WidthPercent.WH_94_100)
986              .width(WidthPercent.WH_100_100)
987            }
988            .backgroundColor($r('sys.color.ohos_id_color_sub_background'))
989            .width(WidthPercent.WH_100_100)
990            .height(WidthPercent.WH_100_100)
991          }
992          .width(WidthPercent.WH_100_100)
993          .height(WidthPercent.WH_100_100);
994        }
995      }
996      .margin(vp2px(1) === 2 ? $r('app.float.item_common_horizontal_margin') : $r('app.float.wh_value_0'))
997      .backgroundColor($r('sys.color.ohos_id_color_sub_background'))
998      .width(WidthPercent.WH_100_100)
999      .height(WidthPercent.WH_100_100);
1000    }
1001  }
1002}