• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-2022 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 router from '@ohos.router';
17import Constants from '../utils/constant';
18
19@Component
20export struct backBar {
21  @Prop title: string; // return title name
22  @Prop recordable: boolean
23  @State record: string = ''
24
25  build() {
26    Column() {
27      Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) {
28        Image($r('app.media.ic_public_back'))
29          .objectFit(ImageFit.Contain)
30          .height(Constants.BACKBAR_IMAGE_HEIGHT)
31          .width(Constants.BACKBAR_IMAGE_WIDTH)
32          .margin({
33            top: Constants.BACKBAR_IMAGE_MARGIN_TOP,
34            left: Constants.BACKBAR_IMAGE_MARGIN_LEFT,
35            right: Constants.BACKBAR_IMAGE_MARGIN_RIGHT
36          })
37          .onClick(() => {
38            var length = router.getLength()
39            Number(length) == 1 ? globalThis.context.terminateSelf() : router.back()
40          })
41        Text(JSON.parse(this.title))
42          .align(Alignment.Start)
43          .fontColor($r('app.color.text_color'))
44          .fontSize(Constants.BACKBAR_TEXT_FONT_SIZE)
45          .flexGrow(Constants.BACKBAR_TEXT_FLEX_GROW)
46          .fontWeight(FontWeight.Bold)
47          .margin({ top: Constants.BACKBAR_TEXT_MARGIN_TOP })
48        if(this.recordable) {
49          Image($r("app.media.gongneng_dian"))
50            .objectFit(ImageFit.Contain)
51            .height(Constants.BACKBAR_IMAGE_HEIGHT)
52            .width(Constants.BACKBAR_IMAGE_WIDTH)
53            .margin({ top: Constants.BACKBAR_TEXT_MARGIN_TOP, right: Constants.BACKBAR_IMAGE_MARGIN_RIGHT })
54            .bindMenu([
55              {
56                value: this.record,
57                action: () => {
58                  router.pushUrl({ url: 'pages/permission-access-record' })
59                }
60              }
61            ])
62        }
63      }
64    }
65    .height(Constants.BACKBAR_HEIGHT)
66    .constraintSize({ minHeight: Constants.BACKBAR_MINHEIGHT })
67    .alignItems(HorizontalAlign.Start)
68    .backgroundColor($r("sys.color.ohos_id_color_sub_background"))
69  }
70
71  aboutToAppear() {
72    globalThis.context.resourceManager.getString($r("app.string.permission_access_record").id).then(val => {
73      this.record = val
74    })
75  }
76}