1/* 2 * Copyright (c) 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 UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession'; 17import ability from '@ohos.ability.ability'; 18import router from '@ohos.router'; 19import dlpPermission from '@ohos.dlpPermission'; 20import picker from '@ohos.file.picker'; 21import fs from '@ohos.file.fs'; 22import fileUri from '@ohos.file.fileuri'; 23import { BusinessError } from '@ohos.base'; 24import osAccount from '@ohos.account.osAccount'; 25import common from '@ohos.app.ability.common'; 26import { staffItem } from '../common/encryptionComponents/staff'; 27import Constants from '../common/constant'; 28import { 29 AuthAccount, 30 checkDomainAccountInfo, 31 getOsAccountInfo, 32 calculate, 33 toggleShow, 34 directionStatus, 35 getTime, 36 sendDlpManagerFileConfiguration 37} from '../common/utils'; 38import { DlpAlertDialog } from '../common/components/dlp_alert_dialog'; 39import GlobalContext from '../common/GlobalContext'; 40import HomeFeature from '../feature/HomeFeature'; 41import { AccountTipsConfig } from '../common/AccountTipsConfig'; 42import { EncryptingPanel } from '../common/encryptionComponents/encrypting'; 43import { GetAlertMessage } from '../common/GetAlertMessage'; 44import { HiLog } from '../common/HiLog'; 45import { SystemUtils } from '../common/systemUtils'; 46import FileUtils, { FileMsg } from '../common/FileUtils'; 47import AccountManager from '../manager/AccountManager'; 48import CommonUtil from '../common/CommonUtil'; 49 50const TAG = 'ModEnc'; 51 52class PermissionValue { 53 public value: Resource | undefined 54 public data: string = '' 55 public index: number = 0 56} 57 58let abilityResult: ability.AbilityResult = { 59 'resultCode': 0, 60 'want': {} 61}; 62 63@Extend(Text) 64function customizeText() { 65 .fontColor($r('sys.color.ohos_id_color_text_primary_activated')) 66 .fontSize($r('sys.float.ohos_id_text_size_button2')) 67 .fontWeight(FontWeight.Medium) 68} 69 70let storage = LocalStorage.getShared(); 71@Entry(storage) 72@Component 73struct changeEncryption { 74 private homeFeature: HomeFeature = GlobalContext.load('homeFeature'); 75 @State session: UIExtensionContentSession | undefined = 76 storage === undefined ? undefined : storage.get<UIExtensionContentSession>('session'); 77 dlpAlertDialog?: CustomDialogController; 78 srcFileName: string = ''; 79 linkFileName: string = ''; 80 @State directionStatus: number = 0; 81 @State handlePopup: boolean = false; 82 @State handlePopupReadOnly: boolean = false; 83 @State handlePopupEdit: boolean = false; 84 @State authPerm: number = 2; 85 @State routerFlag: boolean = false; 86 @State editFlag: boolean = false; 87 @State readOnlyFlag: boolean = false; 88 @State rowNamesLenEdit: number = 0; 89 @State rowNamesLenReadOnly: number = 0; 90 @State hideNamesNumEdit: string = '0'; 91 @State hideNamesNumReadOnly: string = '0'; 92 @State prepareData: boolean = false; 93 @State showNamesArrEdit: AuthAccount[] = []; 94 @State showNamesArrReadOnly: AuthAccount[] = []; 95 @State staffDataArrayReadOnly: AuthAccount[] = []; 96 @State staffDataArrayEdit: AuthAccount[] = []; 97 private routerData: Record<string, AuthAccount[]> = {}; 98 @State permissionDict: PermissionValue[] = [ 99 { 100 value: $r('app.string.PERMISSION_TYPE_SELECT_TARGET') as Resource, data: 'target', index: 0 101 }, 102 { 103 value: $r('app.string.PERMISSION_TYPE_SELECT_ALL') as Resource, data: 'all', index: 1 104 }, 105 { 106 value: $r('app.string.PERMISSION_TYPE_SELECT_SELF') as Resource, data: 'self', index: 2 107 } 108 ]; 109 @State selectedPermissionTypeReadOnly: PermissionValue = { 110 data: '', 111 value: $r('app.string.PERMISSION_TYPE_SELECT_ALL'), 112 index: 0 113 } 114 @State selectedPermissionTypeEdit: PermissionValue = { 115 data: '', 116 value: $r('app.string.PERMISSION_TYPE_SELECT_ALL'), 117 index: 1 118 } 119 120 @Builder popupBuilderReadOnly() { 121 Row() { 122 Text($r('app.string.header_title_readonly_tips')) 123 .fontFamily('HarmonyHeiTi') 124 .fontSize($r('sys.float.ohos_id_text_size_body2')) 125 .fontColor($r('sys.color.ohos_id_color_text_primary')) 126 } 127 .width(Constants.HEADER_COLUMN_MESSAGE_TIPS) 128 .padding({ 129 left: Constants.ROW_FONT_SIZE, 130 right: Constants.ROW_FONT_SIZE, 131 top: Constants.DA_MARGIN_TOP, 132 bottom: Constants.DA_MARGIN_TOP 133 }) 134 } 135 136 @Builder popupBuilderEdit() { 137 Row() { 138 Text($r('app.string.header_title_edit_tips')) 139 .fontSize($r('sys.float.ohos_id_text_size_body2')) 140 .fontColor($r('sys.color.ohos_id_color_text_primary')) 141 } 142 .width(Constants.HEADER_COLUMN_MESSAGE_TIPS) 143 .padding({ 144 left: Constants.ROW_FONT_SIZE, 145 right: Constants.ROW_FONT_SIZE, 146 top: Constants.DA_MARGIN_TOP, 147 bottom: Constants.DA_MARGIN_TOP 148 }) 149 } 150 151 showErrorDialog(title: string | Resource, message: string | Resource) { 152 this.dlpAlertDialog = new CustomDialogController({ 153 builder: DlpAlertDialog({ 154 title: title, 155 message: message, 156 action: () => { 157 } 158 }), 159 autoCancel: false, 160 customStyle: true, 161 maskColor: Constants.TRANSPARENT_BACKGROUND_COLOR 162 }); 163 this.dlpAlertDialog.open(); 164 } 165 166 async catchProcess() { 167 if (GlobalContext.load('requestIsFromSandBox') as boolean) { 168 HiLog.info(TAG, `resumeFuseLink: ${this.srcFileName}`); 169 this.homeFeature.resumeFuseLinkHome(GlobalContext.load('uri'), (err: number) => { 170 if (err !== 0) { 171 HiLog.error(TAG, `resumeFuseLink failed: ${err}`); 172 } 173 }); 174 } 175 } 176 177 stopFuseLinkHome() { 178 return new Promise<void>((resolve, reject) => { 179 this.homeFeature.stopFuseLinkHome(GlobalContext.load('uri'), (err: number) => { 180 if (err !== 0) { 181 HiLog.error(TAG, `stopFuseLink failed: ${err}`); 182 this.showErrorDialog($r('app.string.TITLE_APP_ERROR') as Resource, 183 $r('app.string.MESSAGE_SERVICE_INSIDE_ERROR') as Resource); 184 reject(); 185 } 186 resolve(); 187 }); 188 }) 189 } 190 191 recoverDLPFileHome(plainUri: string) { 192 return new Promise<void>((resolve, reject) => { 193 this.homeFeature.recoverDLPFileHome(GlobalContext.load('uri'), plainUri, async (err: number) => { 194 if (err !== 0) { 195 HiLog.error(TAG, `recoverDLPFile: ${this.srcFileName}, failed: ${err}`); 196 let errorInfo = 197 {'title': '', 'msg': $r('app.string.MESSAGE_RECOVER_DLP_ERROR') } as Record<string, string | Resource>; 198 this.showErrorDialog(errorInfo.title, errorInfo.msg); 199 await this.catchProcess(); 200 reject(); 201 } 202 resolve(); 203 }); 204 }) 205 } 206 207 async unEncrypt() { 208 let plaintextFile = FileUtils.getFileMsgByFileName(this.srcFileName); 209 if (GlobalContext.load('requestIsFromSandBox') as boolean) { 210 try { 211 await this.stopFuseLinkHome(); 212 } catch { 213 return; 214 } 215 } 216 HiLog.info(TAG, `Decrypt DLP file: ${this.srcFileName}`); 217 try { 218 let srcFileUri: string = GlobalContext.load('uri'); 219 let srcFileMsg: FileMsg = FileUtils.getAllSuffixByUri(srcFileUri); 220 let documentSaveOptions = new picker.DocumentSaveOptions(); 221 documentSaveOptions.newFileNames = [decodeURIComponent(plaintextFile)]; 222 documentSaveOptions.fileSuffixChoices = [`.${srcFileMsg.fileType}`]; 223 documentSaveOptions.defaultFilePathUri = srcFileUri.substring(0, 224 srcFileUri.length - srcFileMsg.fileType.length - srcFileMsg.fileName.length - 5); 225 let documentPicker = new picker.DocumentViewPicker(); 226 documentPicker.save(documentSaveOptions).then(async (saveRes) => { 227 if (saveRes === undefined || saveRes.length === 0) { 228 HiLog.error(TAG, `fail to get uri`); 229 await this.catchProcess(); 230 return; 231 } 232 HiLog.info(TAG, `get uri success`); 233 try { 234 await this.fileDecryption(saveRes); 235 } catch { 236 HiLog.info(TAG, `file decryption fail`); 237 } 238 }).catch((err: number) => { 239 HiLog.error(TAG, `DocumentViewPicker save failed: ${JSON.stringify(err)}`); 240 }); 241 } catch (err) { 242 HiLog.error(TAG, `Decrypt DLP file: ${this.srcFileName}, failed: ${JSON.stringify(err)}`); 243 } 244 } 245 246 async fileDecryption(saveRes: Array<string>): Promise<void> { 247 let plainUri = saveRes[0]; 248 let uriInfo: fileUri.FileUri | undefined = undefined; 249 let file: fs.File | undefined = undefined; 250 try { 251 uriInfo = new fileUri.FileUri(plainUri); 252 } catch (err) { 253 HiLog.info(TAG, `fileUri fail: ${JSON.stringify(err)}`); 254 } 255 try { 256 file = await fs.open(plainUri, fs.OpenMode.READ_WRITE); 257 await this.recoverDLPFileHome(plainUri); 258 } catch (err) { 259 HiLog.error(TAG, `recoverDLPFile: ${this.srcFileName}, failed: ${JSON.stringify(err)}`); 260 try { 261 await fs.unlink(uriInfo!.path); 262 } catch (err) { 263 HiLog.info(TAG, `unlink fail: ${JSON.stringify(err)}`); 264 } 265 let errorInfo = 266 {'title': '', 'msg': $r('app.string.MESSAGE_RECOVER_DLP_ERROR') } as Record<string, string | Resource>; 267 this.showErrorDialog(errorInfo.title as Resource, errorInfo.msg as Resource); 268 await this.catchProcess(); 269 return; 270 } finally { 271 if (file) { 272 fs.closeSync(file); 273 } 274 } 275 await this.terminateSelfWithResult(); 276 } 277 278 async terminateSelfWithResult() { 279 if (GlobalContext.load('requestIsFromSandBox') as boolean) { //no need close dlp file in sandbox 280 HiLog.info(TAG, `resumeFuseLink: ${this.srcFileName}`); 281 this.homeFeature.resumeFuseLinkHome(GlobalContext.load('uri'), (err: number) => { 282 if (err !== 0) { 283 HiLog.error(TAG, `resumeFuseLink failed: ${err}`); 284 } 285 }); 286 } else { 287 HiLog.info(TAG, `closeDLPFile: ${this.srcFileName}`); 288 this.homeFeature.closeDLPFileHome(GlobalContext.load('uri'), (err: number) => { 289 if (err !== 0) { 290 HiLog.error(TAG, `closeDLPFile failed: ${err}`); 291 } 292 }); 293 } 294 if (this.session !== undefined) { 295 this.session.terminateSelfWithResult({ 296 'resultCode': 0, 297 'want': { 298 'bundleName': Constants.DLP_MANAGER_BUNDLE_NAME, 299 }, 300 }); 301 } else { 302 if (GlobalContext.load('fileOpenHistoryFromMain')) { 303 (GlobalContext.load('fileOpenHistoryFromMain') as Map<string, Object>) 304 .delete(GlobalContext.load('uri') as string) 305 } 306 abilityResult.resultCode = 0; 307 (getContext(this) as common.UIAbilityContext).terminateSelfWithResult(abilityResult); 308 } 309 } 310 311 async showData(defaultDlpProperty: dlpPermission.DLPProperty) { 312 this.permissionDict.forEach(async (item, index) => { 313 this.permissionDict[index].value = $r(getContext(this).resourceManager.getStringSync(item.value!.id)) 314 }); 315 let readOnlyData = (defaultDlpProperty.authUserList?.filter((item: dlpPermission.AuthUser) => { 316 return item.dlpFileAccess === 1; 317 })) ?? []; 318 let editData = defaultDlpProperty.authUserList?.filter((item: dlpPermission.AuthUser) => { 319 return item.dlpFileAccess === 2; 320 }) ?? []; 321 const filterEditFilter = () => { 322 if (editData.length === 0) { 323 this.selectedPermissionTypeEdit = this.permissionDict[2]; 324 AppStorage.setOrCreate('hiWriteScope', 'Onlyme'); 325 } else { 326 this.staffDataArrayEdit = editData; 327 this.selectedPermissionTypeEdit = this.permissionDict[0]; 328 AppStorage.setOrCreate('hiWriteScope', 'User'); 329 } 330 }; 331 if ((defaultDlpProperty.everyoneAccessList !== undefined) && (defaultDlpProperty.everyoneAccessList.length > 0)) { 332 let perm = Math.max(...defaultDlpProperty.everyoneAccessList); 333 if (perm === dlpPermission.DLPFileAccess.CONTENT_EDIT) { 334 this.selectedPermissionTypeReadOnly = this.permissionDict[1]; 335 AppStorage.setOrCreate('hiReadScope', 'Everyone'); 336 this.selectedPermissionTypeEdit = this.permissionDict[1]; 337 AppStorage.setOrCreate('hiWriteScope', 'Everyone'); 338 this.staffDataArrayReadOnly = readOnlyData; 339 } else if (perm === dlpPermission.DLPFileAccess.READ_ONLY) { 340 this.selectedPermissionTypeReadOnly = this.permissionDict[1]; 341 AppStorage.setOrCreate('hiReadScope', 'Everyone'); 342 this.staffDataArrayReadOnly = []; 343 filterEditFilter(); 344 } else { 345 AppStorage.setOrCreate('hiReadScope', 'User'); 346 } 347 } else { 348 AppStorage.setOrCreate('hiReadScope', 'User'); 349 this.staffDataArrayReadOnly = readOnlyData; 350 filterEditFilter(); 351 } 352 try { 353 await this.getRouterParams(); 354 } catch (err) { 355 HiLog.error(TAG, `fail to get routerParams`); 356 } 357 } 358 359 async getRouterParams() { 360 let routerParams: Record<string, AuthAccount[]> = router.getParams() as Record<string, AuthAccount[]>; 361 if (routerParams !== undefined) { // router 362 this.staffDataArrayReadOnly = routerParams.staffDataArrayReadOnly as AuthAccount[]; 363 this.staffDataArrayEdit = routerParams.staffDataArrayEdit as AuthAccount[]; 364 365 this.routerData = { 366 'staffDataArrayReadOnly': this.staffDataArrayReadOnly, 367 'staffDataArrayEdit': this.staffDataArrayEdit, 368 } as Record<string, AuthAccount[]>; 369 } else { // ability 370 await AccountTipsConfig.getConfigTips(); 371 await this.getTextContent(); 372 373 this.routerData = { 374 'staffDataArrayReadOnly': this.staffDataArrayReadOnly, 375 'staffDataArrayEdit': this.staffDataArrayEdit, 376 } as Record<string, AuthAccount[]>; 377 } 378 } 379 380 async getTextContent(): Promise<void> { 381 await this.dealStaffData(this.staffDataArrayReadOnly); 382 await this.dealStaffData(this.staffDataArrayEdit); 383 } 384 385 async dealStaffData(dataArray: AuthAccount[]): Promise<void> { 386 let searchReq = dataArray.map(item =>{ 387 return item.authAccount; 388 }); 389 if (searchReq.length < 1) { 390 return; 391 } 392 let result = await AccountManager.getDomainAccountWithRetry(searchReq); 393 if (!result || CommonUtil.isEmptyArray(result.getData())) { 394 return; 395 } 396 dataArray.forEach(data =>{ 397 let accountName = data.authAccount; 398 let match = result?.getData().find(item => accountName === item.accountName); 399 if (match) { 400 data.textContent = match[AccountTipsConfig.showContentKey]; 401 } 402 }); 403 } 404 405 async aboutToAppear() { 406 AccountManager.connectAbility(getContext(this) as common.UIAbilityContext); 407 408 this.prepareData = true; 409 try { 410 GlobalContext.store('accountInfo', await getOsAccountInfo()); 411 } catch (err) { 412 HiLog.error(TAG, `getOsAccountInfo failed: ${JSON.stringify(err)}`); 413 if (this.session !== undefined) { 414 let errorInfo = GetAlertMessage.getAlertMessage({ code: Constants.ERR_JS_GET_ACCOUNT_ERROR } as BusinessError); 415 this.showErrorDialog(errorInfo.title, errorInfo.msg); 416 } 417 return; 418 } 419 let codeMessage = checkDomainAccountInfo(GlobalContext.load('accountInfo') as osAccount.OsAccountInfo); 420 if (codeMessage) { 421 if (this.session !== undefined) { 422 let errorInfo = GetAlertMessage.getAlertMessage( 423 { code: codeMessage } as BusinessError); 424 this.showErrorDialog(errorInfo.title, errorInfo.msg); 425 } 426 return; 427 } 428 if (GlobalContext.load('requestIsFromSandBox') as boolean) { 429 HiLog.info(TAG, `request from sandbox`); 430 this.linkFileName = GlobalContext.load('linkFileName') as string; 431 this.srcFileName = GlobalContext.load('dlpFileName') as string; 432 } else { 433 HiLog.info(TAG, `request from normal`); 434 this.srcFileName = GlobalContext.load('dlpFileName') as string; 435 } 436 await this.showData(GlobalContext.load('dlpProperty')); 437 setTimeout(() => { 438 this.prepareData = false; 439 }, Constants.ENCRYPTION_SET_TIMEOUT_TIME) 440 441 this.directionStatus = (getContext(this) as common.UIExtensionContext).config.direction ?? -1; 442 directionStatus((counter) => { 443 this.directionStatus = counter; 444 }) 445 } 446 447 build() { 448 GridRow({ 449 columns: { 450 xs: Constants.XS_COLUMNS, 451 sm: Constants.SM_COLUMNS, 452 md: Constants.MD_COLUMNS, 453 lg: Constants.LG_COLUMNS 454 }, 455 gutter: Constants.DIALOG_GUTTER 456 }) { 457 GridCol({ 458 span: { 459 xs: Constants.XS_SPAN, 460 sm: Constants.SM_SPAN, 461 md: Constants.DIALOG_MD_SPAN, 462 lg: Constants.DIALOG_LG_SPAN 463 }, 464 offset: { 465 xs: Constants.XS_OFFSET, 466 sm: Constants.SM_OFFSET, 467 md: Constants.DIALOG_MD_OFFSET, 468 lg: Constants.DIALOG_LG_OFFSET 469 } 470 }) { 471 Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center, 472 direction: FlexDirection.Column }) { 473 Flex({ alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { 474 EncryptingPanel({ processing: $prepareData, loadingType: Constants.LOAD_TYPE_CE }) 475 if (!this.prepareData) { 476 Column() { 477 Row() { 478 Text($r('app.string.header_title')) 479 .fontWeight(FontWeight.Bold) 480 .fontFamily($r('app.string.typeface')) 481 .fontColor($r('sys.color.ohos_id_color_text_primary')) 482 .fontSize($r('sys.float.ohos_id_text_size_dialog_tittle')) 483 .width(Constants.HEADER_TEXT_WIDTH) 484 .align(Alignment.Start) 485 } 486 .width(Constants.HEADER_COLUMN_WIDTH) 487 .height(Constants.HEADER_COLUMN_HEIGHT) 488 .padding({ 489 left: Constants.HEADER_COLUMN_PADDING_LEFT, 490 right: Constants.HEADER_COLUMN_PADDING_RIGHT 491 }) 492 .margin({ bottom: Constants.HEADER_COLUMN_MARGIN_BOTTOM }); 493 494 Scroll() { 495 Column() { 496 Row() { 497 Text($r('app.string.permissions_are_restricted')) 498 .fontWeight(FontWeight.Regular) 499 .fontColor($r('sys.color.ohos_id_color_text_secondary')) 500 .fontSize($r('sys.float.ohos_id_text_size_body1')) 501 .width(Constants.HEADER_TEXT_WIDTH) 502 .align(Alignment.Start) 503 } 504 .width(Constants.HEADER_COLUMN_WIDTH) 505 .margin({ bottom: Constants.ENCRYPTION_CHANGE_TIPS_MARGIN_BOTTOM }) 506 507 Column() { 508 if (this.selectedPermissionTypeReadOnly.data === 'all') { 509 Row() { 510 Text($r('app.string.header_title_readonly')) 511 .fontWeight(FontWeight.Medium) 512 .fontColor($r('sys.color.ohos_id_color_text_primary')) 513 .fontSize($r('sys.float.ohos_id_text_size_body2')) 514 Text(' : ') 515 .fontFamily($r('app.string.typeface')) 516 .fontWeight(FontWeight.Regular) 517 .fontColor($r('sys.color.ohos_id_color_text_primary')) 518 .fontSize($r('sys.float.ohos_id_text_size_body2')) 519 Text($r('app.string.PERMISSION_TYPE_SELECT_ALL')) 520 .fontFamily($r('app.string.typeface')) 521 .fontWeight(FontWeight.Regular) 522 .fontColor($r('sys.color.ohos_id_color_text_primary')) 523 .fontSize($r('sys.float.ohos_id_text_size_body2')) 524 SymbolGlyph($r('sys.symbol.info_circle')) 525 .fontSize(`${Constants.FOOTER_ROW_PAD_RIGHT}vp`) 526 .fontColor([$r('sys.color.icon_secondary')]) 527 .margin({ 528 right: SystemUtils.isRTL() ? Constants.AP_TEXT_PAD_RIGHT : Constants.AP_TEXT_PAD_LEFT, 529 left: SystemUtils.isRTL() ? Constants.AP_TEXT_PAD_LEFT : Constants.AP_TEXT_PAD_RIGHT, 530 }) 531 .onClick(() => { 532 this.handlePopupReadOnly = !this.handlePopupReadOnly 533 }) 534 .draggable(false) 535 .bindPopup(this.handlePopupReadOnly, { 536 builder: this.popupBuilderReadOnly, 537 placement: SystemUtils.isRTL() ? Placement.BottomRight : Placement.BottomLeft, 538 offset: { 539 x: SystemUtils.isRTL() ? Constants.POPUP_OFFSET_RTL_X : Constants.POPUP_OFFSET_X 540 }, 541 enableArrow: true, 542 showInSubWindow: false, 543 onStateChange: (e) => { 544 if (!e.isVisible) { 545 this.handlePopupReadOnly = false 546 } 547 } 548 }) 549 } 550 .width(Constants.FOOTER_ROW_WIDTH) 551 .margin({ 552 top: Constants.ENCRYPTION_SUCCESS_ADD_STAFF_MARGIN_TOP, 553 bottom: Constants.ENCRYPTION_SUCCESS_ADD_STAFF_MARGIN_BOTTOM 554 }) 555 } else { 556 if (this.staffDataArrayReadOnly['length']) { 557 Row() { 558 Text($r('app.string.header_title_readonly')) 559 .fontWeight(FontWeight.Medium) 560 .fontColor($r('sys.color.ohos_id_color_text_primary')) 561 .fontSize($r('sys.float.ohos_id_text_size_body2')) 562 Text(` (${this.staffDataArrayReadOnly['length']}):`) 563 .fontFamily($r('app.string.typeface')) 564 .fontWeight(FontWeight.Regular) 565 .fontColor($r('sys.color.ohos_id_color_text_primary')) 566 .fontSize($r('sys.float.ohos_id_text_size_body2')) 567 SymbolGlyph($r('sys.symbol.info_circle')) 568 .fontSize(`${Constants.FOOTER_ROW_PAD_RIGHT}vp`) 569 .fontColor([$r('sys.color.icon_secondary')]) 570 .margin({ 571 right: SystemUtils.isRTL() ? Constants.AP_TEXT_PAD_RIGHT : Constants.AP_TEXT_PAD_LEFT, 572 left: SystemUtils.isRTL() ? Constants.AP_TEXT_PAD_LEFT : Constants.AP_TEXT_PAD_RIGHT, 573 }) 574 .onClick(() => { 575 this.handlePopupReadOnly = !this.handlePopupReadOnly 576 }) 577 .draggable(false) 578 .bindPopup(this.handlePopupReadOnly, { 579 builder: this.popupBuilderReadOnly, 580 placement: SystemUtils.isRTL() ? Placement.BottomRight : Placement.BottomLeft, 581 offset: { 582 x: SystemUtils.isRTL() ? Constants.POPUP_OFFSET_RTL_X : Constants.POPUP_OFFSET_X 583 }, 584 enableArrow: true, 585 showInSubWindow: false, 586 onStateChange: (e) => { 587 if (!e.isVisible) { 588 this.handlePopupReadOnly = false 589 } 590 } 591 }) 592 } 593 .width(Constants.FOOTER_ROW_WIDTH) 594 .margin({ top: Constants.FOOTER_ROW_MARGIN }) 595 596 Flex({ 597 direction: FlexDirection.Row, 598 wrap: FlexWrap.Wrap, 599 }) { 600 if (this.staffDataArrayReadOnly['length'] > 0) { 601 ForEach( 602 this.showNamesArrReadOnly, 603 (item: AuthAccount, index) => { 604 staffItem({ 605 authAccount: item.authAccount, 606 textContent: item.textContent, 607 isActive: false, 608 changeIndex: Number(index), 609 }) 610 }, 611 (item: AuthAccount) => item.authAccount 612 ) 613 if (Number(this.hideNamesNumReadOnly) > 0) { 614 Row() { 615 if (this.showNamesArrReadOnly.length !== this.staffDataArrayReadOnly['length']) { 616 Text() { 617 Span('+') 618 Span(this.hideNamesNumReadOnly) 619 } 620 .customizeText() 621 } 622 SymbolGlyph($r('sys.symbol.chevron_down')) 623 .fontSize(`${Constants.PP_IMAGE_HEIGHT}vp`) 624 .fontColor([$r('sys.color.ohos_id_color_secondary')]) 625 .rotate({ 626 angle: !this.readOnlyFlag ? 627 Constants.PP_BUTTON_PAD : Constants.ENCRYPTION_SUCCESS_TRANSLATE 628 }) 629 .transition({ type: TransitionType.All, opacity: Constants.PP_BUTTON_PAD }) 630 } 631 .height(Constants.ENCRYPTION_SUCCESS_TOGGLE_HEIGHT) 632 .onClick(() => { 633 let showValue = toggleShow( 634 this.staffDataArrayReadOnly, 635 this.showNamesArrReadOnly, 636 this.readOnlyFlag, 637 this.rowNamesLenReadOnly 638 ); 639 this.showNamesArrReadOnly = showValue.showNamesArr as AuthAccount[]; 640 this.readOnlyFlag = showValue.showFlag as boolean; 641 }) 642 } 643 } 644 } 645 .onAreaChange((oldValue: Area, newValue: Area) => { 646 if (oldValue.width === 647 Constants.ENCRYPTION_ON_AREA_CHANGE_WIDTH || newValue.width !== oldValue.width) { 648 let nameValue = calculate(newValue, this.staffDataArrayReadOnly); 649 this.rowNamesLenReadOnly = nameValue.rowNamesLen as number; 650 this.showNamesArrReadOnly = nameValue.showNamesArr as AuthAccount[]; 651 this.hideNamesNumReadOnly = nameValue.hideNamesNum as string; 652 this.readOnlyFlag = false; 653 } 654 }) 655 .margin({ 656 top: Constants.ENCRYPTION_SUCCESS_ADD_STAFF_MARGIN_TOP, 657 bottom: Constants.ENCRYPTION_SUCCESS_ADD_STAFF_MARGIN_BOTTOM 658 }) 659 } 660 } 661 if (['all', 'self'].includes(this.selectedPermissionTypeEdit.data)) { 662 Row() { 663 Text($r('app.string.header_title_edit')) 664 .fontWeight(FontWeight.Medium) 665 .fontColor($r('sys.color.ohos_id_color_text_primary')) 666 .fontSize($r('sys.float.ohos_id_text_size_body2')) 667 Text(' : ') 668 .fontFamily($r('app.string.typeface')) 669 .fontWeight(FontWeight.Regular) 670 .fontColor($r('sys.color.ohos_id_color_text_primary')) 671 .fontSize($r('sys.float.ohos_id_text_size_body2')) 672 Text(this.selectedPermissionTypeEdit.data === 'all' ? 673 $r('app.string.PERMISSION_TYPE_SELECT_ALL') : $r('app.string.PERMISSION_TYPE_SELECT_SELF')) 674 .fontFamily($r('app.string.typeface')) 675 .fontWeight(FontWeight.Regular) 676 .fontColor($r('sys.color.ohos_id_color_text_primary')) 677 .fontSize($r('sys.float.ohos_id_text_size_body2')) 678 SymbolGlyph($r('sys.symbol.info_circle')) 679 .fontSize(`${Constants.FOOTER_ROW_PAD_RIGHT}vp`) 680 .fontColor([$r('sys.color.icon_secondary')]) 681 .margin({ 682 right: SystemUtils.isRTL() ? Constants.AP_TEXT_PAD_RIGHT : Constants.AP_TEXT_PAD_LEFT, 683 left: SystemUtils.isRTL() ? Constants.AP_TEXT_PAD_LEFT : Constants.AP_TEXT_PAD_RIGHT, 684 }) 685 .onClick(() => { 686 this.handlePopupEdit = !this.handlePopupEdit 687 }) 688 .draggable(false) 689 .bindPopup(this.handlePopupEdit, { 690 builder: this.popupBuilderEdit, 691 placement: SystemUtils.isRTL() ? Placement.BottomRight : Placement.BottomLeft, 692 offset: { 693 x: SystemUtils.isRTL() ? Constants.POPUP_OFFSET_RTL_X : Constants.POPUP_OFFSET_X 694 }, 695 enableArrow: true, 696 showInSubWindow: false, 697 onStateChange: (e) => { 698 if (!e.isVisible) { 699 this.handlePopupEdit = false 700 } 701 } 702 }) 703 } 704 .justifyContent(FlexAlign.Start) 705 .width(Constants.FOOTER_ROW_WIDTH) 706 .margin({ 707 top: Constants.ENCRYPTION_SUCCESS_ADD_STAFF_MARGIN_TOP, 708 bottom: Constants.ENCRYPTION_SUCCESS_ADD_STAFF_MARGIN_BOTTOM 709 }) 710 } else { 711 if (this.staffDataArrayEdit['length']) { 712 Row() { 713 Text($r('app.string.header_title_edit')) 714 .fontWeight(FontWeight.Medium) 715 .fontColor($r('sys.color.ohos_id_color_text_primary')) 716 .fontSize($r('sys.float.ohos_id_text_size_body2')) 717 Text(` (${this.staffDataArrayEdit['length']}):`) 718 .fontFamily($r('app.string.typeface')) 719 .fontWeight(FontWeight.Regular) 720 .fontColor($r('sys.color.ohos_id_color_text_primary')) 721 .fontSize($r('sys.float.ohos_id_text_size_body2')) 722 SymbolGlyph($r('sys.symbol.info_circle')) 723 .fontSize(`${Constants.FOOTER_ROW_PAD_RIGHT}vp`) 724 .fontColor([$r('sys.color.icon_secondary')]) 725 .margin({ 726 right: SystemUtils.isRTL() ? Constants.AP_TEXT_PAD_RIGHT : Constants.AP_TEXT_PAD_LEFT, 727 left: SystemUtils.isRTL() ? Constants.AP_TEXT_PAD_LEFT : Constants.AP_TEXT_PAD_RIGHT, 728 }) 729 .onClick(() => { 730 this.handlePopupEdit = !this.handlePopupEdit 731 }) 732 .draggable(false) 733 .bindPopup(this.handlePopupEdit, { 734 builder: this.popupBuilderEdit, 735 placement: SystemUtils.isRTL() ? Placement.BottomRight : Placement.BottomLeft, 736 offset: { 737 x: SystemUtils.isRTL() ? Constants.POPUP_OFFSET_RTL_X : Constants.POPUP_OFFSET_X 738 }, 739 enableArrow: true, 740 showInSubWindow: false, 741 onStateChange: (e) => { 742 if (!e.isVisible) { 743 this.handlePopupEdit = false 744 } 745 } 746 }) 747 } 748 .justifyContent(FlexAlign.Start) 749 .width(Constants.FOOTER_ROW_WIDTH) 750 751 Flex({ 752 direction: FlexDirection.Row, 753 wrap: FlexWrap.Wrap, 754 }) { 755 if (this.staffDataArrayEdit['length'] > 0) { 756 ForEach( 757 this.showNamesArrEdit, 758 (item: AuthAccount, index) => { 759 staffItem({ 760 authAccount: item.authAccount, 761 textContent: item.textContent, 762 isActive: false, 763 changeIndex: Number(index), 764 }) 765 }, 766 (item: AuthAccount) => item.authAccount 767 ) 768 if (Number(this.hideNamesNumEdit) > 0) { 769 Row() { 770 if (this.showNamesArrEdit.length !== this.staffDataArrayEdit['length']) { 771 Text() { 772 Span('+') 773 Span(this.hideNamesNumEdit) 774 } 775 .customizeText() 776 } 777 SymbolGlyph($r('sys.symbol.chevron_down')) 778 .fontSize(`${Constants.PP_IMAGE_HEIGHT}vp`) 779 .fontColor([$r('sys.color.ohos_id_color_secondary')]) 780 .rotate({ 781 angle: !this.editFlag ? 782 Constants.PP_BUTTON_PAD : Constants.ENCRYPTION_SUCCESS_TRANSLATE 783 }) 784 .transition({ type: TransitionType.All, opacity: Constants.PP_BUTTON_PAD }) 785 } 786 .height(Constants.ENCRYPTION_SUCCESS_TOGGLE_HEIGHT) 787 .onClick(() => { 788 let showValue = toggleShow( 789 this.staffDataArrayEdit, 790 this.showNamesArrEdit, 791 this.editFlag, 792 this.rowNamesLenEdit 793 ); 794 this.showNamesArrEdit = showValue.showNamesArr as AuthAccount[]; 795 this.editFlag = showValue.showFlag as boolean; 796 }) 797 } 798 } 799 } 800 .onAreaChange((oldValue: Area, newValue: Area) => { 801 if (oldValue.width === 802 Constants.ENCRYPTION_ON_AREA_CHANGE_WIDTH || newValue.width !== oldValue.width) { 803 let nameValue = calculate(newValue, this.staffDataArrayEdit); 804 this.rowNamesLenEdit = nameValue.rowNamesLen as number; 805 this.showNamesArrEdit = nameValue.showNamesArr as AuthAccount[]; 806 this.hideNamesNumEdit = nameValue.hideNamesNum as string; 807 this.editFlag = false; 808 } 809 }) 810 .margin({ 811 top: Constants.ENCRYPTION_SUCCESS_ADD_STAFF_MARGIN_TOP, 812 bottom: Constants.ENCRYPTION_SUCCESS_ADD_STAFF_MARGIN_BOTTOM 813 }) 814 } 815 } 816 Column({ space: Constants.HEADER_ROW_FONT_SIZE }) { 817 Row() { 818 Text($r('app.string.Document_valid_until')) 819 .fontSize($r('sys.float.ohos_id_text_size_body2')) 820 .fontColor($r('sys.color.ohos_id_color_text_primary')) 821 .fontWeight(FontWeight.Medium) 822 .textAlign(TextAlign.Start) 823 Text(' :') 824 .fontFamily($r('app.string.typeface')) 825 .fontWeight(FontWeight.Regular) 826 .fontColor($r('sys.color.ohos_id_color_text_primary')) 827 .fontSize($r('sys.float.ohos_id_text_size_body2')) 828 .margin({ 829 right: SystemUtils.isRTL() ? Constants.AP_TEXT_PAD_LEFT : Constants.AP_TEXT_PAD_RIGHT, 830 left: SystemUtils.isRTL() ? Constants.AP_TEXT_PAD_RIGHT : Constants.AP_TEXT_PAD_LEFT, 831 }) 832 Text(getTime()) 833 .fontSize($r('sys.float.ohos_id_text_size_body2')) 834 .fontColor($r('sys.color.ohos_id_color_text_secondary')) 835 .fontWeight(FontWeight.Regular) 836 .width(Constants.HEADER_COLUMN_WIDTH) 837 .textAlign(TextAlign.Start) 838 .margin({ 839 right: SystemUtils.isRTL() ? Constants.AP_TEXT_PAD_RIGHT : Constants.AP_TEXT_PAD_LEFT, 840 left: SystemUtils.isRTL() ? Constants.AP_TEXT_PAD_LEFT : Constants.AP_TEXT_PAD_RIGHT, 841 }) 842 } 843 .width(Constants.HEADER_COLUMN_WIDTH) 844 } 845 .padding({ 846 bottom: Constants.ENCRYPTION_CHANGE_VALID_UNTIL_MARGIN_BOTTOM 847 }) 848 } 849 } 850 }.constraintSize({ 851 maxHeight: this.directionStatus === 852 0 ? Constants.CHANGE_MAX_HEIGHT : Constants.ENCRYPTION_SUCCESS_MAX_HEIGHT 853 }) 854 .padding({ 855 left: Constants.HEADER_COLUMN_PADDING_LEFT, 856 right: Constants.HEADER_COLUMN_PADDING_RIGHT 857 }) 858 Flex({ direction: FlexDirection.Row }) { 859 Button($r('app.string.unencrypted'), { type: ButtonType.Capsule, stateEffect: true }) 860 .backgroundColor($r('sys.color.ohos_id_color_button_normal')) 861 .width(Constants.HEADER_TEXT_WIDTH) 862 .controlSize(ControlSize.NORMAL) 863 .fontColor($r('sys.color.ohos_id_color_text_primary_activated')) 864 .onClick(async (event) => { 865 AppStorage.setOrCreate('hiOperation', 'Delete_policy'); 866 AppStorage.setOrCreate('hiAdvancedSettings', false); 867 AppStorage.setOrCreate('hiStorePath', false); 868 AppStorage.setOrCreate('hiValidDate', false); 869 AppStorage.setOrCreate('hiAccountVerifySucc', 0); 870 AppStorage.setOrCreate('hiAccountVerifyFail', 0); 871 this.unEncrypt(); 872 sendDlpManagerFileConfiguration(); 873 }) 874 .margin({ 875 right: SystemUtils.isRTL() ? 876 Constants.ADD_STAFF_ITEM_MARGIN_LEFT : Constants.ENCRYPTION_PROTECTION_BUTTON_MARGIN, 877 left: SystemUtils.isRTL() ? 878 Constants.ENCRYPTION_PROTECTION_BUTTON_MARGIN : Constants.ADD_STAFF_ITEM_MARGIN_LEFT, 879 }) 880 Button($r('app.string.change_encryption'), { type: ButtonType.Capsule, stateEffect: true }) 881 .backgroundColor($r('sys.color.ohos_id_color_button_normal')) 882 .width(Constants.HEADER_TEXT_WIDTH) 883 .fontColor($r('sys.color.ohos_id_color_text_primary_activated')) 884 .controlSize(ControlSize.NORMAL) 885 .onClick(async (event) => { 886 router.replaceUrl({ 887 url: 'pages/encryptionProtection', 888 params: this.routerData 889 }) 890 }) 891 .margin({ 892 right: SystemUtils.isRTL() ? 893 Constants.ENCRYPTION_PROTECTION_BUTTON_MARGIN : Constants.ADD_STAFF_ITEM_MARGIN_LEFT, 894 left: SystemUtils.isRTL() ? 895 Constants.ADD_STAFF_ITEM_MARGIN_LEFT : Constants.ENCRYPTION_PROTECTION_BUTTON_MARGIN, 896 }) 897 } 898 .margin({ 899 left: Constants.ENCRYPTION_BUTTON_TO_BUTTON_WIDTH, 900 right: Constants.ENCRYPTION_BUTTON_TO_BUTTON_WIDTH, 901 bottom: Constants.ENCRYPTION_BUTTON_MARGIN_BOTTOM, 902 top: Constants.ENCRYPTION_BUTTON_TO_BUTTON_WIDTH 903 }) 904 } 905 .visibility(this.prepareData ? Visibility.Hidden : Visibility.Visible) 906 .width(Constants.ENCRYPTION_PC_FIXING_WIDTH) 907 .backgroundColor($r('sys.color.ohos_id_color_dialog_bg')) 908 .borderRadius($r('sys.float.ohos_id_corner_radius_dialog')) 909 .constraintSize({ 910 minWidth: Constants.ENCRYPTION_PC_FIXING_WIDTH 911 }) 912 .backgroundBlurStyle(BlurStyle.COMPONENT_ULTRA_THICK); 913 } 914 } 915 } 916 } 917 } 918 .backgroundColor($r('sys.color.mask_fourth')) 919 } 920} 921