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