1/* 2 * Copyright (c) 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 router from '@ohos.router'; 17import utils from '../../common/utils' 18import doubleButtonComponent from '../component/autoManager/doubleButtonComponent' 19import logger from '../../common/logger' 20import Want from '@ohos.app.ability.Want'; 21import common from '@ohos.app.ability.common'; 22 23const TAG = 'ManagerStart'; 24 25@Entry 26@Component 27struct ManagerStart { 28 @State textContext: Resource = $r('app.string.unitManageDevice'); 29 @State textManager: Resource = $r('app.string.unitManage'); 30 @State textManagerBefore: Resource = $r('app.string.textManagerBefore'); 31 @State textManagerAfter: Resource = $r('app.string.textManagerAfter'); 32 @State textTerms: Resource = $r('app.string.textTerms'); 33 @State textTermsBefore: Resource = $r('app.string.textTermsBefore'); 34 private storage = LocalStorage.getShared(); 35 36 build() { 37 Column() { 38 GridContainer({ 39 columns: utils.isLargeDevice(), 40 sizeType: SizeType.Auto, 41 gutter: '12vp', 42 margin: '12vp' 43 }) { 44 Column() { 45 Image($r('app.media.ic_start')) 46 .width($r('app.float.wh_value_40')) 47 .height($r('app.float.wh_value_40')) 48 .margin({ top: '72vp', bottom: '16vp' }) 49 .objectFit(ImageFit.Contain) 50 51 Text(this.textContext) 52 .height('40vp') 53 .textAlign(TextAlign.Center) 54 .fontWeight(FontWeight.Medium) 55 .lineHeight($r('app.float.lineHeight_vp_41')) 56 .fontSize($r('app.float.font_vp_30')) 57 .fontFamily('HarmonyHeiTi') 58 } 59 .useSizeType({ 60 xs: { span: 8, offset: 0 }, sm: { span: 8, offset: 0 }, 61 md: { span: 8, offset: 0 }, lg: { span: 8, offset: 2 } 62 }) 63 .width('100%') 64 .align(Alignment.Center) 65 66 Column() { 67 Row() { 68 Text() { 69 Span(this.textTermsBefore) 70 .fontWeight(FontWeight.Regular) 71 .fontSize($r('app.float.font_vp_16')) 72 .fontFamily('HarmonyHeiTi') 73 74 Span(this.textTerms) 75 .decoration({ type: TextDecorationType.None }) 76 .fontColor(0x007DFF) 77 .fontSize($r('app.float.font_vp_16')) 78 .fontFamily('HarmonyHeiTi') 79 .fontWeight(FontWeight.Regular) 80 .onClick(() => { 81 router.pushUrl({ url: 'pages/autoManager/termsShowPage' }) 82 }) 83 84 Span(this.textManagerBefore) 85 .fontWeight(FontWeight.Regular) 86 .fontSize($r('app.float.font_vp_16')) 87 .fontFamily('HarmonyHeiTi') 88 89 Span(this.textManager) 90 .decoration({ type: TextDecorationType.None }) 91 .fontColor(0x007DFF) 92 .fontSize($r('app.float.font_vp_16')) 93 .fontFamily('HarmonyHeiTi') 94 .fontWeight(FontWeight.Regular) 95 .onClick(() => { 96 router.pushUrl({ url: 'pages/autoManager/unitManagerShowPage' }) 97 }) 98 99 Span(this.textManagerAfter) 100 .fontWeight(FontWeight.Regular) 101 .fontSize($r('app.float.font_vp_16')) 102 .fontFamily('HarmonyHeiTi') 103 } 104 .lineHeight($r('app.float.lineHeight_vp_21_5')) 105 } 106 .useSizeType({ 107 xs: { span: 8, offset: 0 }, sm: { span: 8, offset: 0 }, 108 md: { span: 8, offset: 0 }, lg: { span: 8, offset: 2 } 109 }) 110 .width('100%') 111 .margin({ top: '48vp' }) 112 .justifyContent(FlexAlign.Center) 113 } 114 .width('100%') 115 } 116 117 Blank() 118 119 GridContainer({ 120 columns: utils.isLargeDevice(), 121 sizeType: SizeType.Auto, 122 gutter: '12vp', 123 margin: '12vp' 124 }) { 125 Column() { 126 Button() { 127 Text($r('app.string.buttonAcceptAndContinue')) 128 .fontSize($r('app.float.font_vp_16')) 129 .fontFamily('HarmonyHeiTi') 130 .fontWeight(FontWeight.Medium) 131 .fontColor(0xFFFFFF) 132 .lineHeight($r('app.float.lineHeight_vp_22')) 133 } 134 .backgroundColor(0x007DFF) 135 .onClick(() => { 136 router.pushUrl({ url: 'pages/autoManager/loadingInfo' }) 137 }) 138 .width('100%') 139 .height('40vp') 140 .useSizeType({ 141 xs: { span: 2, offset: 3 }, sm: { span: 2, offset: 3 }, 142 md: { span: 2, offset: 3 }, lg: { span: 2, offset: 3 } 143 }) 144 } 145 .width('100%') 146 .useSizeType({ 147 xs: { span: 8, offset: 0 }, sm: { span: 8, offset: 0 }, 148 md: { span: 8, offset: 0 }, lg: { span: 8, offset: 2 } 149 }) 150 .margin({ bottom: '100vp' }) 151 } 152 153 GridContainer({ 154 columns: utils.isLargeDevice(), 155 sizeType: SizeType.Auto, 156 gutter: '12vp', 157 margin: '12vp' 158 }) { 159 Column() { 160 doubleButtonComponent({ nextFlag: true, returnDialogFlag: false }) 161 } 162 .useSizeType({ 163 xs: { span: 8, offset: 0 }, sm: { span: 8, offset: 0 }, 164 md: { span: 8, offset: 0 }, lg: { span: 12, offset: 0 } 165 }) 166 .width('100%') 167 .margin({ bottom: '16vp' }) 168 } 169 } 170 .backgroundColor(0xF1F3F5) 171 .width('100%') 172 .height('100%') 173 } 174 175 aboutToAppear() { 176 this.parseManageParameter(); 177 } 178 179 parseManageParameter() { 180 this.storage = LocalStorage.getShared(); 181 let data = this.storage.get<Want>('autoManagerAbilityWant'); 182 183 if (!utils.checkObjPropertyValid(data, 'parameters.elementName.abilityName') || 184 !utils.checkObjPropertyValid(data, 'parameters.enterprise.name') || 185 !utils.isValid((data.parameters?.elementName as Record<string, string>).bundleName) || 186 !utils.isValid(data.parameters?.url) || 187 !utils.isValid(data.parameters?.termsName) || 188 (!utils.isValid(data.parameters?.termsContent) || !(data.parameters?.termsContent instanceof Array)) || 189 !utils.isValid((data.parameters?.enterprise as Record<string, string>).description)) { 190 logger.error(TAG, 'parseManageParameter fail! parameters is not valid'); 191 (getContext(this) as common.UIAbilityContext).terminateSelf(); 192 return; 193 } 194 195 let mapVal = new Map([ 196 ['manageAbilityName', (data.parameters?.elementName as Record<string, string>).abilityName], 197 ['manageBundleName', (data.parameters?.elementName as Record<string, string>).bundleName], 198 ['manageUrl', data.parameters?.url], 199 ['manageTermsName', data.parameters?.termsName], 200 ['manageTermsContent', data.parameters?.termsContent], 201 ['manageEnterpriseName', (data.parameters?.enterprise as Record<string, string>).name], 202 ['manageEnterpriseDescription', (data.parameters?.enterprise as Record<string, string>).description] 203 ]); 204 205 for (let item of Array.from(mapVal.keys())) { 206 AppStorage.setOrCreate(item, mapVal.get(item)); 207 } 208 } 209}