• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-2023 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 { backBar } from "../common/components/backBar";
17import { permissionGroups, groups } from "../common/model/permissionGroup";
18import router from '@ohos.router';
19import Constants from '../common/utils/constant';
20import { CalendarObj, routerParams_1, permissionApplications } from '../common/utils/typedef';
21
22@Entry
23@Component
24struct appNamePage {
25  private backTitle: ResourceStr = (router.getParams() as routerParams_1).backTitle;
26
27  build() {
28    GridRow({ gutter: Constants.GUTTER, columns: {
29      xs: Constants.XS_COLUMNS, sm: Constants.SM_COLUMNS, md: Constants.MD_COLUMNS, lg: Constants.LG_COLUMNS } }) {
30      GridCol({ span: { xs: Constants.XS_SPAN, sm: Constants.SM_SPAN, md: Constants.MD_SPAN, lg: Constants.LG_SPAN },
31        offset: { xs: Constants.XS_OFFSET, sm: Constants.SM_OFFSET, md: Constants.MD_OFFSET, lg: Constants.LG_OFFSET } }) {
32        Row() {
33          Column() {
34            Row() {
35              backBar({ title: JSON.stringify(this.backTitle), recordable: false })
36            }
37            Row() {
38              Column() {
39                Scroll() {
40                  appNameItem()
41                }
42              }
43            }.layoutWeight(Constants.LAYOUT_WEIGHT)
44          }
45        }
46        .height(Constants.FULL_HEIGHT)
47        .width(Constants.FULL_WIDTH)
48        .backgroundColor($r("sys.color.ohos_id_color_sub_background"))
49      }
50    }.backgroundColor($r("sys.color.ohos_id_color_sub_background"))
51  }
52}
53
54@Component
55struct appNameItem {
56  @State calendarListItem: CalendarObj[] = []; // Permission management secondary interface data array
57  private list: permissionApplications[] = (router.getParams() as routerParams_1).list; // Routing jump data
58  private group: string = (router.getParams() as routerParams_1).group;
59  @State isTouch: string = '';
60
61  @Builder ListItemLayout(item: CalendarObj) {
62    ListItem() {
63      Row() {
64        Column() {
65          Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) {
66            Row() {
67              Text(item.label)
68                .fontSize(Constants.TEXT_MIDDLE_FONT_SIZE)
69                .fontColor($r('sys.color.ohos_id_color_text_primary'))
70                .fontWeight(FontWeight.Medium)
71                .flexGrow(Constants.FLEX_GROW)
72              Image($r('app.media.ic_public_arrow_right'))
73                .fillColor($r('sys.color.ohos_id_color_tertiary'))
74                .objectFit(ImageFit.Contain)
75                .height(Constants.IMAGE_HEIGHT)
76                .width(Constants.IMAGE_WIDTH)
77            }
78            .width(Constants.FULL_WIDTH)
79            .height(Constants.LISTITEM_ROW_HEIGHT)
80          }
81        }.onClick(() => {
82          let dataList = this.list.filter((ele) => {
83            return ele.permission === item.permissionName;
84          })
85          router.pushUrl({
86            url: 'pages/authority-tertiary',
87            params: { list: dataList, backTitle: item.label, permissionName: item.permissionName }
88          });
89        })
90      }
91    }.padding({ left: $r('sys.float.ohos_id_card_margin_start'), right: $r('sys.float.ohos_id_card_margin_end') })
92    .borderRadius($r("sys.float.ohos_id_corner_radius_default_l"))
93    .linearGradient((this.isTouch === item.permissionName) ? {
94         angle: 90,
95         direction: GradientDirection.Right,
96         colors: [['#DCEAF9', 0.0], ['#FAFAFA', 1.0]]
97       } : {
98         angle: 90,
99         direction: GradientDirection.Right,
100         colors: [[$r("sys.color.ohos_id_color_list_card_bg"), 1], [$r("sys.color.ohos_id_color_list_card_bg"), 1]]
101       })
102    .onTouch(event => {
103      if (event === undefined) {
104        return;
105      }
106      if (event.type === TouchType.Down) {
107        this.isTouch = item.permissionName;
108      }
109      if (event.type === TouchType.Up) {
110        this.isTouch = '';
111      }
112    })
113  }
114
115  /**
116   * Lifecycle function, executed when the page is initialized
117   */
118  aboutToAppear() {
119    let permissionsList = groups.filter((item) => {
120      return item.name === this.group;
121    })
122    for (let i = 0; i < permissionsList[0].permissions.length; i++) {
123      permissionGroups.forEach((item) => {
124        if (item.permissionName === permissionsList[0].permissions[i]) {
125          this.calendarListItem.push(
126            new CalendarObj(item.permissionName, item.groupName, item.label, i)
127          )
128        }
129      })
130    }
131  }
132
133  build() {
134    Row() {
135      Column() {
136        Row() {
137            List() {
138              if (this.calendarListItem.length > 0) {
139                ForEach(this.calendarListItem, (item: CalendarObj) => {
140                  this.ListItemLayout(item)
141                }, (item: CalendarObj) => JSON.stringify(item))
142              } else {
143                ListItem() {
144                  Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) {
145                    Text($r('app.string.no_permission'))
146                      .fontSize(Constants.TEXT_MIDDLE_FONT_SIZE)
147                      .fontColor($r('sys.color.ohos_id_color_text_primary'))
148                  }
149                }
150                .width(Constants.FULL_WIDTH)
151                .height(Constants.LISTITEM_ROW_HEIGHT)
152                .padding({ left: Constants.DEFAULT_PADDING_START, right: Constants.DEFAULT_PADDING_END })
153              }
154            }.backgroundColor($r('sys.color.ohos_id_color_list_card_bg'))
155            .borderRadius($r('sys.float.ohos_id_corner_radius_card'))
156            .padding(Constants.LIST_PADDING_TOP)
157            .divider({
158              strokeWidth: Constants.DIVIDER,
159              color: $r('sys.color.ohos_id_color_list_separator'),
160              startMargin: Constants.DEFAULT_MARGIN_START,
161              endMargin: Constants.DEFAULT_MARGIN_END
162            })
163          }.margin({ top: Constants.ROW_MARGIN_TOP })
164        .padding({ left: Constants.LIST_PADDING_LEFT, right: Constants.LISTITEM_PADDING_RIGHT })
165      }
166      .width(Constants.FULL_WIDTH)
167      .height(Constants.FULL_HEIGHT)
168    }
169  }
170}
171