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