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