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, RouterParams1, PermissionApplications } from '../common/utils/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 Image($r('app.media.ic_public_arrow_right')) 75 .fillColor($r('sys.color.icon_tertiary')) 76 .objectFit(ImageFit.Contain) 77 .height(Constants.IMAGE_HEIGHT) 78 .width(Constants.IMAGE_WIDTH) 79 .draggable(false) 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 for (let i = 0; i < permissionsList[0].permissions.length; i++) { 126 permissionGroups.forEach((item) => { 127 if (item.permissionName === permissionsList[0].permissions[i]) { 128 this.calendarListItem.push( 129 new CalendarObj(item.permissionName, item.groupName, item.label, i) 130 ) 131 } 132 }) 133 } 134 } 135 136 build() { 137 Row() { 138 Column() { 139 Row() { 140 List() { 141 if (this.calendarListItem.length > 0) { 142 ForEach(this.calendarListItem, (item: CalendarObj) => { 143 this.ListItemLayout(item) 144 }, (item: CalendarObj) => JSON.stringify(item)) 145 } else { 146 ListItem() { 147 Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { 148 Text($r('app.string.no_permission')) 149 .fontSize(Constants.TEXT_MIDDLE_FONT_SIZE) 150 .fontColor($r('sys.color.font_primary')) 151 } 152 } 153 .width(Constants.FULL_WIDTH) 154 .height(Constants.LISTITEM_ROW_HEIGHT) 155 .padding({ left: Constants.DEFAULT_PADDING_START, right: Constants.DEFAULT_PADDING_END }) 156 } 157 }.backgroundColor($r('sys.color.comp_background_list_card')) 158 .borderRadius($r('sys.float.ohos_id_corner_radius_card')) 159 .padding(Constants.LIST_PADDING_TOP) 160 .divider({ 161 strokeWidth: Constants.DIVIDER, 162 color: $r('sys.color.comp_divider'), 163 startMargin: Constants.DEFAULT_MARGIN_START, 164 endMargin: Constants.DEFAULT_MARGIN_END 165 }) 166 }.margin({ top: Constants.ROW_MARGIN_TOP }) 167 .padding({ left: Constants.LIST_PADDING_LEFT, right: Constants.LISTITEM_PADDING_RIGHT }) 168 } 169 .width(Constants.FULL_WIDTH) 170 .height(Constants.FULL_HEIGHT) 171 } 172 } 173} 174