• 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 { backBar } from "../common/components/backBar";
17import { permissionGroups, groups } from "../common/model/permissionGroup";
18import router from '@ohos.router';
19import Constants from '../common/utils/constant';
20
21
22class CalendarObj {
23  permissionName: string
24  groupName: string
25  label: string
26  index: number
27  constructor(permissionName: string, groupName: string, label: string, index: number) {
28    this.permissionName = permissionName
29    this.groupName = groupName
30    this.label = label
31    this.index = index
32  }
33} // Permission management secondary interface data class
34
35@Entry
36@Component
37struct appNamePage {
38  private backTitle = router.getParams()['backTitle']; // return title name
39
40  build() {
41    GridContainer({ gutter: Constants.GUTTER, margin: Constants.GRID_MARGIN }) {
42      Row() {
43        Row()
44          .useSizeType({
45            xs: { span: Constants.LEFT_XS_SPAN, offset: Constants.LEFT_XS_OFFSET },
46            sm: { span: Constants.LEFT_SM_SPAN, offset: Constants.LEFT_SM_OFFSET },
47            md: { span: Constants.LEFT_MD_SPAN, offset: Constants.LEFT_MD_OFFSET },
48            lg: { span: Constants.LEFT_LG_SPAN, offset: Constants.LEFT_LG_OFFSET }
49          })
50          .height(Constants.FULL_HEIGHT)
51        Row() {
52          Column() {
53            Row() {
54              backBar({ title: JSON.stringify(this.backTitle), recordable: false })
55            }
56            Row() {
57              Column() {
58                Scroll() {
59                  appNameItem()
60                }
61              }
62            }.layoutWeight(Constants.LAYOUT_WEIGHT)
63          }
64        }
65        .useSizeType({
66          xs: { span: Constants.MIDDLE_XS_SPAN, offset: Constants.MIDDLE_XS_OFFSET },
67          sm: { span: Constants.MIDDLE_SM_SPAN, offset: Constants.MIDDLE_SM_OFFSET },
68          md: { span: Constants.MIDDLE_MD_SPAN, offset: Constants.MIDDLE_MD_OFFSET },
69          lg: { span: Constants.MIDDLE_LG_SPAN, offset: Constants.MIDDLE_LG_OFFSET }
70        })
71        .height(Constants.FULL_HEIGHT)
72        Row()
73          .useSizeType({
74            xs: { span: Constants.RIGHT_XS_SPAN, offset: Constants.RIGHT_XS_OFFSET },
75            sm: { span: Constants.RIGHT_SM_SPAN, offset: Constants.RIGHT_SM_OFFSET },
76            md: { span: Constants.RIGHT_MD_SPAN, offset: Constants.RIGHT_MD_OFFSET },
77            lg: { span: Constants.RIGHT_LG_SPAN, offset: Constants.RIGHT_LG_OFFSET }
78          })
79          .height(Constants.FULL_HEIGHT)
80      }
81      .height(Constants.FULL_HEIGHT)
82      .width(Constants.FULL_WIDTH)
83      .backgroundColor($r("sys.color.ohos_id_color_sub_background"))
84    }
85  }
86}
87
88@Component
89struct appNameItem {
90  @State calendarListItem: CalendarObj[] = []; // Permission management secondary interface data array
91  private routerData: any = router.getParams()['routerData']; // Routing jump data
92  private group = router.getParams()['group'];
93
94  @Builder ListItemLayout(item, index) {
95    ListItem() {
96      Row() {
97        Column() {
98          Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) {
99            Row() {
100              Text(item.label)
101                .fontSize(Constants.TEXT_MIDDLE_FONT_SIZE)
102                .fontColor($r('app.color.label_color'))
103                .fontWeight(FontWeight.Medium)
104                .flexGrow(Constants.FLEX_GROW)
105              Image($r('app.media.ic_public_arrow_right'))
106                .objectFit(ImageFit.Contain)
107                .height(Constants.IMAGE_HEIGHT)
108                .width(Constants.IMAGE_WIDTH)
109            }
110            .width(Constants.FULL_WIDTH)
111            .height(Constants.LISTITEM_ROW_HEIGHT)
112          }
113          if (!index) {
114            Row() {
115              Column()
116                .backgroundColor($r('app.color.text_decoration_color'))
117                .width(Constants.FULL_WIDTH)
118                .height(Constants.TEXT_DECORATION_HEIGHT)
119            }
120          }
121        }.onClick(() => {
122          var dataList = this.routerData.filter((ele) => {
123            return ele.permission === item.permissionName;
124          })
125          router.pushUrl({
126            url: 'pages/authority-tertiary',
127            params: { routerData: dataList, backTitle: item.label }
128          });
129        })
130      }
131    }.padding({ left: Constants.DEFAULT_PADDING_START, right: Constants.DEFAULT_PADDING_END })
132  }
133
134  /**
135   * Lifecycle function, executed when the page is initialized
136   */
137  aboutToAppear() {
138    var permissionsList = groups.filter((item) => {
139      return item.name === this.group
140    })
141    for (let i = 0; i < permissionsList[0].permissions.length; i++) {
142      permissionGroups.forEach((item) => {
143        if (item.permissionName === permissionsList[0].permissions[i]) {
144          this.calendarListItem.push(
145            new CalendarObj(item.permissionName, item.groupName, item.label, i)
146          )
147        }
148      })
149    }
150  }
151
152  build() {
153    Row() {
154      Column() {
155        Row() {
156            List() {
157              ForEach(this.calendarListItem.slice(Constants.SLICE_START, this.calendarListItem.length - 1), (item) => {
158                this.ListItemLayout(item, Constants.SLICE_START_INDEX)
159              }, item => item.toString())
160              ForEach(this.calendarListItem.slice(Constants.SLICE_END), (item) => {
161                this.ListItemLayout(item, Constants.SLICE_END_INDEX)
162              }, item => item.toString())
163            }.backgroundColor($r('app.color.default_background_color')).borderRadius(Constants.BORDER_RADIUS)
164            .padding({ top: Constants.LIST_PADDING_TOP, bottom: Constants.LIST_PADDING_BOTTOM })
165          }.margin({ top: Constants.ROW_MARGIN_TOP })
166        .padding({ left: Constants.LIST_PADDING_LEFT, right: Constants.LISTITEM_PADDING_RIGHT })
167      }
168      .width(Constants.FULL_WIDTH)
169      .height(Constants.FULL_HEIGHT)
170    }
171  }
172}
173