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 .draggable(false) 78 } 79 .width(Constants.FULL_WIDTH) 80 .height(Constants.LISTITEM_ROW_HEIGHT) 81 } 82 }.onClick(() => { 83 let dataList = this.list.filter((ele) => { 84 return ele.permission === item.permissionName; 85 }) 86 router.pushUrl({ 87 url: 'pages/authority-tertiary', 88 params: { list: dataList, backTitle: item.label, permissionName: item.permissionName } 89 }); 90 }) 91 } 92 }.padding({ left: $r('sys.float.ohos_id_card_margin_start'), right: $r('sys.float.ohos_id_card_margin_end') }) 93 .borderRadius($r("sys.float.ohos_id_corner_radius_default_l")) 94 .linearGradient((this.isTouch === item.permissionName) ? { 95 angle: 90, 96 direction: GradientDirection.Right, 97 colors: [['#DCEAF9', 0.0], ['#FAFAFA', 1.0]] 98 } : { 99 angle: 90, 100 direction: GradientDirection.Right, 101 colors: [[$r("sys.color.ohos_id_color_list_card_bg"), 1], [$r("sys.color.ohos_id_color_list_card_bg"), 1]] 102 }) 103 .onTouch(event => { 104 if (event === undefined) { 105 return; 106 } 107 if (event.type === TouchType.Down) { 108 this.isTouch = item.permissionName; 109 } 110 if (event.type === TouchType.Up) { 111 this.isTouch = ''; 112 } 113 }) 114 } 115 116 /** 117 * Lifecycle function, executed when the page is initialized 118 */ 119 aboutToAppear() { 120 let permissionsList = groups.filter((item) => { 121 return item.name === this.group; 122 }) 123 for (let i = 0; i < permissionsList[0].permissions.length; i++) { 124 permissionGroups.forEach((item) => { 125 if (item.permissionName === permissionsList[0].permissions[i]) { 126 this.calendarListItem.push( 127 new CalendarObj(item.permissionName, item.groupName, item.label, i) 128 ) 129 } 130 }) 131 } 132 } 133 134 build() { 135 Row() { 136 Column() { 137 Row() { 138 List() { 139 if (this.calendarListItem.length > 0) { 140 ForEach(this.calendarListItem, (item: CalendarObj) => { 141 this.ListItemLayout(item) 142 }, (item: CalendarObj) => JSON.stringify(item)) 143 } else { 144 ListItem() { 145 Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { 146 Text($r('app.string.no_permission')) 147 .fontSize(Constants.TEXT_MIDDLE_FONT_SIZE) 148 .fontColor($r('sys.color.ohos_id_color_text_primary')) 149 } 150 } 151 .width(Constants.FULL_WIDTH) 152 .height(Constants.LISTITEM_ROW_HEIGHT) 153 .padding({ left: Constants.DEFAULT_PADDING_START, right: Constants.DEFAULT_PADDING_END }) 154 } 155 }.backgroundColor($r('sys.color.ohos_id_color_list_card_bg')) 156 .borderRadius($r('sys.float.ohos_id_corner_radius_card')) 157 .padding(Constants.LIST_PADDING_TOP) 158 .divider({ 159 strokeWidth: Constants.DIVIDER, 160 color: $r('sys.color.ohos_id_color_list_separator'), 161 startMargin: Constants.DEFAULT_MARGIN_START, 162 endMargin: Constants.DEFAULT_MARGIN_END 163 }) 164 }.margin({ top: Constants.ROW_MARGIN_TOP }) 165 .padding({ left: Constants.LIST_PADDING_LEFT, right: Constants.LISTITEM_PADDING_RIGHT }) 166 } 167 .width(Constants.FULL_WIDTH) 168 .height(Constants.FULL_HEIGHT) 169 } 170 } 171} 172