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