• 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 */
15import ComponentConfig from './ComponentConfig';
16import Router from '@ohos.router';
17import { GlobalContext } from '../GlobalContext';
18
19const TAG = 'CertManager HeadComponent: ';
20
21/**
22 * head custom component
23 */
24@Component
25export default struct HeadComponent {
26  private icBackIsVisibility: boolean = true;
27  private headName: string | Resource = '';
28  @State isTouch: boolean = false;
29
30  isStartBySheet: boolean = false;
31  onBackClicked?: () => void;
32
33  build() {
34    Row() {
35      Stack({ alignContent: Alignment.Center }) {
36        Image($r('app.media.ic_back'))
37          .width($r('app.float.wh_value_24'))
38          .height($r('app.float.wh_value_24'))
39          .fillColor($r('sys.color.ohos_id_color_primary'))
40      }
41      .margin({ right: $r('app.float.wh_value_16') })
42      .backgroundColor(this.isTouch ? $r('sys.color.ohos_id_color_click_effect')
43        : $r('sys.color.ohos_id_color_sub_background'))
44      .visibility(this.icBackIsVisibility ? Visibility.Visible : Visibility.None)
45      .onClick(() => {
46        if (this.isStartBySheet) {
47          this.onBackClicked?.();
48          return;
49        }
50        let length = Router.getLength();
51        console.info(TAG + 'router length: ' + Number(length));
52        if (GlobalContext.getContext().getFlag()) {
53          Number(length) == 1 ? GlobalContext.getContext().getSession().sendData({'action': 'exit'}) : Router.back();
54        } else {
55          Number(length) == 1 ? GlobalContext.getContext().getCmContext().terminateSelf() : Router.back();
56        }
57      })
58      .onTouch((event?: TouchEvent) => {
59        if (event?.type === TouchType.Down) {
60          this.isTouch = true;
61        }
62        if (event?.type === TouchType.Up) {
63          this.isTouch = false;
64        }
65      });
66
67      Text(this.headName)
68        .fontSize($r('app.float.head_font_20'))
69        .lineHeight($r('app.float.wh_value_33'))
70        .fontFamily('HarmonyHeiTi-Bold')
71        .fontWeight(FontWeight.Regular)
72        .maxFontScale(1)
73        .fontColor($r('sys.color.ohos_id_color_text_primary'))
74        .maxLines(ComponentConfig.MAX_LINES_1)
75        .textOverflow({ overflow: TextOverflow.Ellipsis })
76        .textAlign(TextAlign.Start)
77        .margin({ top: $r('app.float.wh_value_13'), bottom: $r('app.float.wh_value_15') });
78    }
79    .width(ComponentConfig.WH_100_100)
80    .padding({ left: $r('app.float.wh_value_12') })
81    .height($r('app.float.wh_value_56'))
82    .alignItems(VerticalAlign.Center)
83    .align(Alignment.Start)
84  }
85}
86