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 router from '@ohos.router'; 18import Constants from '../common/utils/constant'; 19import { permissionInfos } from '../common/model/permissionGroup'; 20import { Log, verifyAccessToken } from '../common/utils/utils'; 21import { OtherPermission, RouterParams3 } from '../common/model/typedef'; 22import { Permission } from '../common/model/definition'; 23import { BusinessError } from '@kit.BasicServicesKit'; 24 25let status: number = (router.getParams() as RouterParams3).status; // Status: Allowed, Forbidden 26let permissions: Permission[] = (router.getParams() as RouterParams3).permission; // permissions name 27let otherPermissionList: OtherPermission[] = []; // otherPermission List 28for (let i = 0; i < permissions.length; i++) { 29 let permissionInfo = permissionInfos.get(permissions[i]); 30 if (!permissionInfo) { 31 continue; 32 } 33 otherPermissionList.push( 34 new OtherPermission(permissionInfo.label, permissions[i]) 35 ); 36} 37 38@Entry 39@Component 40struct appNamePage { 41 private backTitle: ResourceStr = (router.getParams() as RouterParams3).backTitle; 42 private tokenId: number = (router.getParams() as RouterParams3).tokenId; 43 44 build() { 45 GridRow({ gutter: Constants.GUTTER, columns: { 46 xs: Constants.XS_COLUMNS, sm: Constants.SM_COLUMNS, md: Constants.MD_COLUMNS, lg: Constants.LG_COLUMNS } }) { 47 GridCol({ 48 span: { xs: Constants.XS_SPAN, sm: Constants.SM_SPAN, md: Constants.MD_SPAN, lg: Constants.LG_SPAN }, 49 offset: { xs: Constants.XS_OFFSET, sm: Constants.SM_OFFSET, md: Constants.MD_OFFSET, lg: Constants.LG_OFFSET } 50 }) { 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 .height(Constants.FULL_HEIGHT) 66 .width(Constants.FULL_WIDTH) 67 .backgroundColor($r('sys.color.background_secondary')) 68 } 69 }.backgroundColor($r('sys.color.background_secondary')) 70 } 71 72/** 73 * Lifecycle function, triggered once when this page is displayed 74 */ 75 onPageShow() { 76 permissions.forEach(permission => { 77 verifyAccessToken(this.tokenId, permission).then((data): void => { 78 status = data; 79 }).catch((err: BusinessError) => { 80 Log.error(`verifyAccessToken failed: ${JSON.stringify(err)}`) 81 }); 82 }) 83 } 84} 85 86@Component 87struct appNameItem { 88 private bundleName: string = (router.getParams() as RouterParams3).bundleName; 89 private tokenId: number = (router.getParams() as RouterParams3).tokenId; 90 @State otherPermissionListItem: OtherPermission[] = otherPermissionList; // Other permission interface data array 91 @State isTouch: string = ''; 92 93 @Builder ListItemLayout(item: OtherPermission) { 94 ListItem() { 95 Row() { 96 Column() { 97 Flex({ justifyContent: FlexAlign.Start, alignItems: ItemAlign.Center }) { 98 Row() { 99 Text(item.permissionLabel) 100 .fontSize(Constants.TEXT_MIDDLE_FONT_SIZE) 101 .fontColor($r('sys.color.font_primary')) 102 .flexGrow(Constants.FLEX_GROW) 103 SymbolGlyph($r('sys.symbol.chevron_forward')) 104 .width(Constants.IMAGE_WIDTH) 105 .height(Constants.IMAGE_HEIGHT) 106 .fontSize(Constants.FONT_SIZE_18_vp) 107 .fontColor([$r('sys.color.icon_tertiary')]) 108 .fontWeight(FontWeight.Medium) 109 } 110 .width(Constants.FULL_WIDTH) 111 .height(Constants.LISTITEM_ROW_HEIGHT) 112 } 113 }.onClick(() => { 114 router.pushUrl({ 115 url: 'pages/application-tertiary', 116 params: { 117 bundleName: this.bundleName, 118 backTitle: item.permissionLabel, 119 permission: [item.permission], 120 status, 121 tokenId: this.tokenId 122 } 123 }); 124 }) 125 } 126 }.padding({ left: $r('sys.float.ohos_id_card_margin_start'), right: $r('sys.float.ohos_id_card_margin_end') }) 127 .borderRadius($r('sys.float.ohos_id_corner_radius_default_l')) 128 .linearGradient((this.isTouch === item.permission) ? { 129 angle: 90, 130 direction: GradientDirection.Right, 131 colors: [['#DCEAF9', 0.0], ['#FAFAFA', 1.0]] 132 } : { 133 angle: 90, 134 direction: GradientDirection.Right, 135 colors: [[$r('sys.color.comp_background_list_card'), 1], [$r('sys.color.comp_background_list_card'), 1]] 136 }) 137 .onTouch(event => { 138 if (event === undefined) { 139 return; 140 } 141 if (event.type === TouchType.Down) { 142 this.isTouch = item.permission; 143 } 144 if (event.type === TouchType.Up) { 145 this.isTouch = ''; 146 } 147 }) 148 } 149 150 build() { 151 Row() { 152 Column() { 153 Row() { 154 List() { 155 ForEach(this.otherPermissionListItem, (item: OtherPermission) => { 156 this.ListItemLayout(item) 157 }, (item: OtherPermission) => JSON.stringify(item)) 158 }.backgroundColor($r('sys.color.comp_background_list_card')) 159 .borderRadius($r('sys.float.ohos_id_corner_radius_card')) 160 .padding(Constants.LIST_PADDING_TOP) 161 .divider({ 162 strokeWidth: Constants.DIVIDER, 163 color: $r('sys.color.comp_divider'), 164 startMargin: Constants.DEFAULT_MARGIN_START, 165 endMargin: Constants.DEFAULT_MARGIN_END 166 }) 167 }.margin({ top: Constants.ROW_MARGIN_TOP }) 168 .padding({ left: Constants.LIST_PADDING_LEFT, right: Constants.LISTITEM_PADDING_RIGHT }) 169 } 170 .width(Constants.FULL_WIDTH) 171 .height(Constants.FULL_HEIGHT) 172 } 173 } 174} 175