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 ability from '@ohos.ability.ability'; 17import router from '@ohos.router'; 18import dlpPermission from '@ohos.dlpPermission'; 19import picker from '@ohos.file.picker'; 20import fs from '@ohos.file.fs'; 21import fileUri from '@ohos.file.fileuri'; 22import staffItem from '../common/encryptionComponents/staff'; 23import Constants from '../common/constant'; 24import { getAlertMessage, checkAccountLogin, getOsAccountInfo, calculate, toggleShow, directionStatus } from '../common/utils'; 25import { DlpAlertDialog } from '../common/components/dlp_alert_dialog'; 26import GlobalContext from '../common/GlobalContext'; 27import osAccount from '@ohos.account.osAccount'; 28import common from '@ohos.app.ability.common'; 29import { BusinessError } from '@ohos.base'; 30 31const TAG = '[DLPManager_ModEnc]'; 32 33class PermissionValue { 34 value: Resource | undefined 35 data: string = '' 36 index: number = 0 37} 38 39let abilityResult: ability.AbilityResult = { 40 'resultCode': 0, 41 'want': {} 42}; 43 44interface AuthAccount { 45 authAccount: string; 46} 47 48@Extend(Text) function customizeText() { 49 .fontColor($r('sys.color.ohos_id_color_text_primary_activated')) 50 .fontSize($r('sys.float.ohos_id_text_size_button2')) 51 .fontWeight(FontWeight.Medium) 52} 53 54let defaultDlpProperty: dlpPermission.DLPProperty = { 55 ownerAccount: '', 56 ownerAccountType: GlobalContext.load('domainAccount') as Boolean 57 ? dlpPermission.AccountType.DOMAIN_ACCOUNT : dlpPermission.AccountType.CLOUD_ACCOUNT, 58 authUserList: [], 59 contactAccount: '', 60 offlineAccess: true, 61 ownerAccountID: '', 62 everyoneAccessList: [] 63}; 64let defaultDlpFile: dlpPermission.DLPFile = { 65 dlpProperty: defaultDlpProperty, 66 recoverDLPFile: async() => {}, 67 closeDLPFile: async() => {}, 68 addDLPLinkFile: async() => {}, 69 stopFuseLink: async() => {}, 70 resumeFuseLink: async() => {}, 71 replaceDLPLinkFile: async() => {}, 72 deleteDLPLinkFile: async() => {} 73}; 74 75@Entry 76@Component 77struct changeEncryption { 78 dlpAlertDialog?: CustomDialogController; 79 srcFileName: string = ''; 80 linkFileName: string = ''; 81 @State directionStatus: number = 0; 82 @State handlePopup: boolean = false; 83 @State handlePopupReadOnly: boolean = false; 84 @State handlePopupEdit: boolean = false; 85 @State dlpFile: dlpPermission.DLPFile = defaultDlpFile; 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 private dlpFd: number = 0; 101 @State permissionDict: PermissionValue[] = [ 102 { 103 value: $r('app.string.PERMISSION_TYPE_SELECT_TARGET') as Resource, data: 'target', index: 0 104 }, 105 { 106 value: $r('app.string.PERMISSION_TYPE_SELECT_ALL') as Resource, data: 'all', index: 1 107 }, 108 { 109 value: $r('app.string.PERMISSION_TYPE_SELECT_SELF') as Resource, data: 'self', index: 2 110 } 111 ]; 112 @State selectedPermissionTypeReadOnly: PermissionValue = { 113 data: '', 114 value: $r('app.string.PERMISSION_TYPE_SELECT_ALL'), 115 index: 0 116 } 117 @State selectedPermissionTypeEdit: PermissionValue = { 118 data: '', 119 value: $r('app.string.PERMISSION_TYPE_SELECT_ALL'), 120 index: 1 121 } 122 123 @Builder popupBuilderReadOnly() { 124 Row() { 125 Text($r('app.string.header_title_readonly_tips')) 126 .fontFamily('HarmonyHeiTi') 127 .fontSize($r('sys.float.ohos_id_text_size_body2')) 128 .fontColor($r('sys.color.ohos_id_color_primary_dark')) 129 } 130 .width(Constants.HEADER_COLUMN_MESSAGE_TIPS) 131 .padding({ 132 left: Constants.ROW_FONT_SIZE, 133 right: Constants.ROW_FONT_SIZE, 134 top: Constants.DA_MARGIN_TOP, 135 bottom: Constants.DA_MARGIN_TOP 136 }) 137 } 138 139 @Builder popupBuilderEdit() { 140 Row() { 141 Text($r('app.string.header_title_edit_tips')) 142 .fontSize($r('sys.float.ohos_id_text_size_body2')) 143 .fontColor($r('sys.color.ohos_id_color_primary_dark')) 144 } 145 .width(Constants.HEADER_COLUMN_MESSAGE_TIPS) 146 .padding({ 147 left: Constants.ROW_FONT_SIZE, 148 right: Constants.ROW_FONT_SIZE, 149 top: Constants.DA_MARGIN_TOP, 150 bottom: Constants.DA_MARGIN_TOP 151 }) 152 } 153 154 showErrorDialog(title: Resource, message: Resource) { 155 this.dlpAlertDialog = new CustomDialogController({ 156 builder: DlpAlertDialog({ 157 title: title, 158 message: message, 159 action: () => { 160 } 161 }), 162 autoCancel: false, 163 customStyle: true, 164 }); 165 this.dlpAlertDialog.open(); 166 } 167 168 showErrorDialogAndExit(title: Resource, message: Resource) { 169 this.dlpAlertDialog = new CustomDialogController({ 170 builder: DlpAlertDialog({ 171 title: title, 172 message: message 173 }), 174 autoCancel: false, 175 customStyle: true 176 }) 177 this.dlpAlertDialog.open(); 178 } 179 180 async catchProcess() { 181 if (GlobalContext.load('requestIsFromSandBox')) { 182 try { 183 console.info(TAG, 'resumeFuseLink', this.srcFileName); 184 await this.dlpFile.resumeFuseLink(); 185 } catch (err) { 186 console.error(TAG, 'resumeFuseLink failed', (err as BusinessError).code, (err as BusinessError).message); 187 } 188 } 189 } 190 191 async unEncrypt() { 192 let plaintextFile = this.srcFileName.split('.')[0] + '.' + this.srcFileName.split('.')[1]; 193 if (GlobalContext.load('requestIsFromSandBox') as boolean) { 194 try { 195 console.info(TAG, 'stopFuseLink', this.srcFileName); 196 await this.dlpFile.stopFuseLink(); 197 } catch (err) { 198 console.error(TAG, 'stopFuseLink failed', (err as BusinessError).code, (err as BusinessError).message); 199 this.showErrorDialog($r('app.string.TITLE_APP_ERROR') as Resource, $r('app.string.MESSAGE_APP_INSIDE_ERROR') as Resource); 200 return; 201 } 202 } 203 console.info(TAG, 'Decrypt DLP file', this.srcFileName) 204 try { 205 let DocumentSaveOptions = new picker.DocumentSaveOptions(); 206 DocumentSaveOptions.newFileNames = [plaintextFile]; 207 let documentPicker = new picker.DocumentViewPicker(); 208 documentPicker.save(DocumentSaveOptions).then(async (saveRes) => { 209 if (saveRes === undefined || saveRes.length === 0) { 210 console.error(TAG, 'fail to get uri'); 211 await this.catchProcess(); 212 return; 213 } 214 console.info(TAG, 'get uri', saveRes) 215 let uri = saveRes[0]; 216 let dstFd: number = 0; 217 let uriInfo: fileUri.FileUri | undefined = undefined; 218 let file: fs.File | undefined = undefined; 219 try { 220 uriInfo = new fileUri.FileUri(uri); 221 } catch (err) { 222 console.log(TAG, 'fileUri fail', (err as BusinessError).code, (err as BusinessError).message); 223 } 224 try { 225 file = await fs.open(uri, fs.OpenMode.READ_WRITE); 226 dstFd = file.fd; 227 } catch (err) { 228 console.error(TAG, 'open', uri, 'failed', (err as BusinessError).code, (err as BusinessError).message); 229 try { 230 await fs.unlink(uriInfo!.path); 231 } catch (err) { 232 console.log(TAG, 'unlink fail', (err as BusinessError).code, (err as BusinessError).message); 233 } 234 this.showErrorDialog($r('app.string.TITLE_APP_ERROR') as Resource, $r('app.string.MESSAGE_APP_INSIDE_ERROR') as Resource); 235 await this.catchProcess(); 236 return; 237 }; 238 try { 239 console.info(TAG, 'recoverDLPFile', this.srcFileName, this.dlpFd); 240 await this.dlpFile.recoverDLPFile(dstFd); 241 } catch (err) { 242 console.error(TAG, 'recoverDLPFile', this.srcFileName, 'failed', (err as BusinessError).code, (err as BusinessError).message); 243 try { 244 await fs.close(file); 245 } catch (err) { 246 console.log(TAG, 'close fail', (err as BusinessError).code, (err as BusinessError).message); 247 } 248 try { 249 await fs.unlink(uriInfo!.path); 250 } catch (err) { 251 console.log(TAG, 'unlink fail', (err as BusinessError).code, (err as BusinessError).message); 252 } 253 let errorInfo = getAlertMessage( 254 err, $r('app.string.TITLE_SERVICE_ERROR'), $r('app.string.MESSAGE_RECOVER_DLP_ERROR')); 255 this.showErrorDialog(errorInfo.title as Resource, errorInfo.msg as Resource); 256 await this.catchProcess(); 257 return; 258 } 259 260 try { 261 await fs.close(file); 262 } catch (err) { 263 console.log(TAG, 'close fail', (err as BusinessError).code, (err as BusinessError).message); 264 } 265 if (GlobalContext.load('requestIsFromSandBox') as boolean) { //no need close dlp file in sandbox 266 try { 267 console.info(TAG, 'resumeFuseLink', this.srcFileName); 268 await this.dlpFile.resumeFuseLink(); 269 } catch (err) { 270 console.error(TAG, 'resumeFuseLink failed', (err as BusinessError).code, (err as BusinessError).message); 271 } 272 } else { 273 try { 274 console.info(TAG, 'closeDLPFile', this.srcFileName, this.dlpFd); 275 await this.dlpFile.closeDLPFile(); 276 } catch (err) { 277 console.error(TAG, 'closeDLPFile', this.srcFileName, 'failed', (err as BusinessError).code, (err as BusinessError).message); 278 } 279 } 280 if (GlobalContext.load('fileOpenHistoryFromMain') as Map<string, (string | number)[]>) { 281 (GlobalContext.load('fileOpenHistoryFromMain') as Map<string, (string | number)[]>).delete(GlobalContext.load('uri') as string); 282 } 283 abilityResult.resultCode = 0; 284 (GlobalContext 285 .load('context') as common.UIAbilityContext).terminateSelfWithResult(abilityResult); 286 }).catch((err: number) => { 287 console.error(TAG, 'DocumentViewPicker save failed', JSON.stringify(err)); 288 }); 289 } catch (err) { 290 console.error(TAG, 'Decrypt DLP file', this.srcFileName, 'failed', JSON.stringify(err as BusinessError)); 291 } 292 } 293 294 async showData(defaultDlpProperty: dlpPermission.DLPProperty) { 295 this.permissionDict.forEach(async (item, index) => { 296 this.permissionDict[index].value = $r(await (GlobalContext 297 .load('context') as common.UIAbilityContext).resourceManager.getString(item.value!.id)) 298 }) 299 let readOnlyData = (defaultDlpProperty.authUserList?.filter((item: dlpPermission.AuthUser) => { 300 return item.dlpFileAccess === 1; 301 })) ?? [] 302 let editData = defaultDlpProperty.authUserList?.filter((item: dlpPermission.AuthUser) => { 303 return item.dlpFileAccess === 2; 304 }) ?? [] 305 const filterEditFilter = () => { 306 if (editData.length === 0) { 307 this.selectedPermissionTypeEdit = this.permissionDict[2]; 308 } else { 309 this.staffDataArrayEdit = editData; 310 this.selectedPermissionTypeEdit = this.permissionDict[0]; 311 } 312 } 313 if ((defaultDlpProperty.everyoneAccessList !== undefined) && (defaultDlpProperty.everyoneAccessList.length > 0)) { 314 let perm = Math.max(...defaultDlpProperty.everyoneAccessList); 315 if (perm === dlpPermission.DLPFileAccess.CONTENT_EDIT) { 316 this.selectedPermissionTypeReadOnly = this.permissionDict[1]; 317 this.selectedPermissionTypeEdit = this.permissionDict[1]; 318 this.staffDataArrayReadOnly = readOnlyData; 319 } else if (perm === dlpPermission.DLPFileAccess.READ_ONLY) { 320 this.selectedPermissionTypeReadOnly = this.permissionDict[1]; 321 this.staffDataArrayReadOnly = []; 322 filterEditFilter() 323 } 324 } else { 325 this.staffDataArrayReadOnly = readOnlyData; 326 filterEditFilter() 327 } 328 this.routerData = { 329 'staffDataArrayReadOnly': this.staffDataArrayReadOnly, 330 'staffDataArrayEdit': this.staffDataArrayEdit, 331 } as Record<string, AuthAccount[]> 332 } 333 334 async aboutToAppear() { 335 this.prepareData = true; 336 try { 337 GlobalContext.store("accountInfo", await getOsAccountInfo()); 338 } catch (err) { 339 console.error(TAG, 'getOsAccountInfo failed', (err as BusinessError).code, (err as BusinessError).message); 340 this.showErrorDialogAndExit($r('app.string.TITLE_APP_ERROR'), $r('app.string.MESSAGE_APP_GET_ACCOUNT_ERROR')) 341 return; 342 } 343 if (!checkAccountLogin(GlobalContext.load('accountInfo') as osAccount.OsAccountInfo)) { 344 this.showErrorDialogAndExit($r('app.string.TITLE_APP_ERROR'), $r('app.string.MESSAGE_APP_NO_ACCOUNT_ERROR')); 345 return; 346 } 347 348 if (GlobalContext.load('requestIsFromSandBox') as boolean) { 349 console.info(TAG, 'request from sandbox'); 350 this.linkFileName = GlobalContext.load('linkFileName') as string; 351 this.dlpFd = GlobalContext.load('dlpFd') as number; 352 this.srcFileName = GlobalContext.load('dlpFileName') as string; 353 this.dlpFile = GlobalContext.load('dlpFile') as dlpPermission.DLPFile; 354 } else { 355 console.info(TAG, 'request from normal'); 356 this.dlpFd = GlobalContext.load('dlpFd') as number; 357 this.srcFileName = GlobalContext.load('dlpFileName') as string; 358 this.dlpFile = GlobalContext.load('dlpFile') as dlpPermission.DLPFile; 359 } 360 await this.showData(this.dlpFile.dlpProperty); 361 setTimeout(() => { 362 this.prepareData = false; 363 }, Constants.ENCRYPTION_SET_TIMEOUT_TIME) 364 365 this.directionStatus = (GlobalContext 366 .load('context') as common.UIAbilityContext).config.direction ?? -1; 367 directionStatus((counter) => { 368 this.directionStatus = counter; 369 }) 370 } 371 372 build() { 373 GridRow({ 374 columns: { 375 xs: Constants.XS_COLUMNS, 376 sm: Constants.SM_COLUMNS, 377 md: Constants.MD_COLUMNS, 378 lg: Constants.LG_COLUMNS 379 }, 380 gutter: Constants.DIALOG_GUTTER 381 }) { 382 GridCol({ 383 span: { 384 xs: Constants.XS_SPAN, 385 sm: Constants.SM_SPAN, 386 md: Constants.DIALOG_MD_SPAN, 387 lg: Constants.DIALOG_LG_SPAN 388 }, 389 offset: { 390 xs: Constants.XS_OFFSET, 391 sm: Constants.SM_OFFSET, 392 md: Constants.DIALOG_MD_OFFSET, 393 lg: Constants.DIALOG_LG_OFFSET 394 } 395 }) { 396 Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center, 397 direction: FlexDirection.Column }) { 398 Flex({ alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { 399 Column() { 400 Row() { 401 Text($r('app.string.header_title')) 402 .fontWeight(FontWeight.Medium) 403 .fontFamily($r('app.string.typeface')) 404 .fontColor($r('sys.color.ohos_id_color_text_primary')) 405 .fontSize(Constants.HEADER_TEXT_FRONT_SIZE) 406 .lineHeight(Constants.HEADER_TEXT_LINE_HEIGHT) 407 .width(Constants.HEADER_TEXT_WIDTH) 408 .align(Alignment.Start) 409 } 410 .width(Constants.HEADER_COLUMN_WIDTH) 411 .height(Constants.HEADER_COLUMN_HEIGHT) 412 .padding({ 413 left: Constants.HEADER_COLUMN_PADDING_LEFT, 414 right: Constants.HEADER_COLUMN_PADDING_RIGHT 415 }) 416 417 Scroll() { 418 Column() { 419 Row() { 420 Text($r('app.string.permissions_are_restricted')) 421 .fontWeight(FontWeight.Regular) 422 .fontColor($r('sys.color.ohos_id_color_text_secondary')) 423 .fontSize($r('sys.float.ohos_id_text_size_body1')) 424 .width(Constants.HEADER_TEXT_WIDTH) 425 .align(Alignment.Start) 426 } 427 .width(Constants.HEADER_COLUMN_WIDTH) 428 .margin({ bottom: Constants.ENCRYPTION_CHANGE_TIPS_MARGIN_BOTTOM }) 429 430 Column() { 431 if (this.selectedPermissionTypeReadOnly.data === 'all') { 432 Row() { 433 Text($r('app.string.header_title_readonly')) 434 .fontWeight(FontWeight.Medium) 435 .fontColor($r('sys.color.ohos_id_color_text_primary')) 436 .fontSize($r('sys.float.ohos_id_text_size_body2')) 437 Text(' : ') 438 .fontFamily($r('app.string.typeface')) 439 .fontWeight(FontWeight.Regular) 440 .fontColor($r('sys.color.ohos_id_color_text_primary')) 441 .fontSize($r('sys.float.ohos_id_text_size_body2')) 442 Text($r('app.string.PERMISSION_TYPE_SELECT_ALL')) 443 .fontFamily($r('app.string.typeface')) 444 .fontWeight(FontWeight.Regular) 445 .fontColor($r('sys.color.ohos_id_color_text_primary')) 446 .fontSize($r('sys.float.ohos_id_text_size_body2')) 447 Image($r('app.media.details')) 448 .width(Constants.FOOTER_ROW_PAD_RIGHT) 449 .height(Constants.FOOTER_ROW_PAD_RIGHT) 450 .margin({ left: Constants.AP_TEXT_PAD_RIGHT }) 451 .fillColor($r('sys.color.ohos_id_color_text_secondary')) 452 .onClick(() => { 453 this.handlePopupReadOnly = !this.handlePopupReadOnly 454 }) 455 .draggable(false) 456 .bindPopup(this.handlePopupReadOnly, { 457 builder: this.popupBuilderReadOnly, 458 placement: Placement.Bottom, 459 popupColor: ($r('sys.color.ohos_id_color_tooltip_background_dark')), 460 enableArrow: true, 461 showInSubWindow: false, 462 onStateChange: (e) => { 463 if (!e.isVisible) { 464 this.handlePopupReadOnly = false 465 } 466 } 467 }) 468 } 469 .width(Constants.FOOTER_ROW_WIDTH) 470 .height(Constants.ENCRYPTION_READ_ONLY_EDIT_HEIGHT) 471 .margin({ 472 top: Constants.ENCRYPTION_SUCCESS_ADD_STAFF_MARGIN_TOP, 473 bottom: Constants.ENCRYPTION_SUCCESS_ADD_STAFF_MARGIN_BOTTOM 474 }) 475 } else { 476 if (this.staffDataArrayReadOnly['length']) { 477 Row() { 478 Text($r('app.string.header_title_readonly')) 479 .fontWeight(FontWeight.Medium) 480 .fontColor($r('sys.color.ohos_id_color_text_primary')) 481 .fontSize($r('sys.float.ohos_id_text_size_body2')) 482 Text(` (${this.staffDataArrayReadOnly['length']}):`) 483 .fontFamily($r('app.string.typeface')) 484 .fontWeight(FontWeight.Regular) 485 .fontColor($r('sys.color.ohos_id_color_text_primary')) 486 .fontSize($r('sys.float.ohos_id_text_size_body2')) 487 Image($r('app.media.details')) 488 .width(Constants.FOOTER_ROW_PAD_RIGHT) 489 .height(Constants.FOOTER_ROW_PAD_RIGHT) 490 .margin({ left: Constants.AP_TEXT_PAD_RIGHT }) 491 .fillColor($r('sys.color.ohos_id_color_text_secondary')) 492 .onClick(() => { 493 this.handlePopupReadOnly = !this.handlePopupReadOnly 494 }) 495 .draggable(false) 496 .bindPopup(this.handlePopupReadOnly, { 497 builder: this.popupBuilderReadOnly, 498 placement: Placement.Bottom, 499 popupColor: ($r('sys.color.ohos_id_color_tooltip_background_dark')), 500 enableArrow: true, 501 showInSubWindow: false, 502 onStateChange: (e) => { 503 if (!e.isVisible) { 504 this.handlePopupReadOnly = false 505 } 506 } 507 }) 508 } 509 .width(Constants.FOOTER_ROW_WIDTH) 510 .height(Constants.ENCRYPTION_READ_ONLY_EDIT_HEIGHT) 511 .margin({ top: Constants.FOOTER_ROW_MARGIN }) 512 513 Flex({ 514 direction: FlexDirection.Row, 515 wrap: FlexWrap.Wrap, 516 }) { 517 if (this.staffDataArrayReadOnly['length'] > 0) { 518 ForEach( 519 this.showNamesArrReadOnly, 520 (item: dlpPermission.AuthUser, index) => { 521 staffItem({ 522 authAccount: item.authAccount, 523 isActive: false, 524 changeIndex: Number(index), 525 }) 526 }, 527 (item: dlpPermission.AuthUser) => item.authAccount 528 ) 529 if (Number(this.hideNamesNumReadOnly) > 0) { 530 Row() { 531 if (this.showNamesArrReadOnly.length !== this.staffDataArrayReadOnly['length']) { 532 Text('+') 533 .customizeText() 534 Text(this.hideNamesNumReadOnly) 535 .customizeText() 536 } 537 Image($r("app.media.icon_change")) 538 .draggable(false) 539 .width(Constants.PP_IMAGE_HEIGHT) 540 .height(Constants.PP_TEXT_FONT_SIZE2) 541 .objectFit(ImageFit.Contain) 542 .rotate({ 543 angle: !this.ReadOnlyFlag ? Constants.PP_BUTTON_PAD : Constants.ENCRYPTION_SUCCESS_TRANSLATE 544 }) 545 .transition({ type: TransitionType.All, opacity: Constants.PP_BUTTON_PAD }) 546 } 547 .height(Constants.ENCRYPTION_SUCCESS_TOGGLE_HEIGHT) 548 .onClick(() => { 549 let showValue = toggleShow(this.staffDataArrayReadOnly, this.showNamesArrReadOnly, this.ReadOnlyFlag, this.rowNamesLenReadOnly); 550 this.showNamesArrReadOnly = showValue.showNamesArr as AuthAccount[]; 551 this.ReadOnlyFlag = showValue.showFlag as boolean; 552 }) 553 } 554 } 555 } 556 .onAreaChange((oldValue: Area, newValue: Area) => { 557 if (oldValue.width === Constants.ENCRYPTION_ON_AREA_CHANGE_WIDTH || newValue.width !== oldValue.width) { 558 let nameValue = calculate(newValue, this.staffDataArrayReadOnly); 559 this.rowNamesLenReadOnly = nameValue.rowNamesLen as number; 560 this.showNamesArrReadOnly = nameValue.showNamesArr as AuthAccount[]; 561 this.hideNamesNumReadOnly = nameValue.hideNamesNum as string; 562 this.ReadOnlyFlag = false; 563 } 564 }) 565 .margin({ 566 top: Constants.ENCRYPTION_SUCCESS_ADD_STAFF_MARGIN_TOP, 567 bottom: Constants.ENCRYPTION_SUCCESS_ADD_STAFF_MARGIN_BOTTOM 568 }) 569 } 570 } 571 if (['all', 'self'].includes(this.selectedPermissionTypeEdit.data)) { 572 Row() { 573 Text($r('app.string.header_title_edit')) 574 .fontWeight(FontWeight.Medium) 575 .fontColor($r('sys.color.ohos_id_color_text_primary')) 576 .fontSize($r('sys.float.ohos_id_text_size_body2')) 577 Text(' : ') 578 .fontFamily($r('app.string.typeface')) 579 .fontWeight(FontWeight.Regular) 580 .fontColor($r('sys.color.ohos_id_color_text_primary')) 581 .fontSize($r('sys.float.ohos_id_text_size_body2')) 582 Text(this.selectedPermissionTypeEdit.data === 'all' ? $r('app.string.PERMISSION_TYPE_SELECT_ALL') : $r('app.string.PERMISSION_TYPE_SELECT_SELF')) 583 .fontFamily($r('app.string.typeface')) 584 .fontWeight(FontWeight.Regular) 585 .fontColor($r('sys.color.ohos_id_color_text_primary')) 586 .fontSize($r('sys.float.ohos_id_text_size_body2')) 587 Image($r('app.media.details')) 588 .width(Constants.FOOTER_ROW_PAD_RIGHT) 589 .height(Constants.FOOTER_ROW_PAD_RIGHT) 590 .margin({ left: Constants.AP_TEXT_PAD_RIGHT }) 591 .fillColor($r('sys.color.ohos_id_color_text_secondary')) 592 .onClick(() => { 593 this.handlePopupEdit = !this.handlePopupEdit 594 }) 595 .draggable(false) 596 .bindPopup(this.handlePopupEdit, { 597 builder: this.popupBuilderEdit, 598 placement: Placement.Bottom, 599 popupColor: ($r('sys.color.ohos_id_color_tooltip_background_dark')), 600 enableArrow: true, 601 showInSubWindow: false, 602 onStateChange: (e) => { 603 if (!e.isVisible) { 604 this.handlePopupEdit = false 605 } 606 } 607 }) 608 } 609 .justifyContent(FlexAlign.Start) 610 .width(Constants.FOOTER_ROW_WIDTH) 611 .height(Constants.ENCRYPTION_READ_ONLY_EDIT_HEIGHT) 612 .margin({ 613 top: Constants.ENCRYPTION_SUCCESS_ADD_STAFF_MARGIN_TOP, 614 bottom: Constants.ENCRYPTION_SUCCESS_ADD_STAFF_MARGIN_BOTTOM 615 }) 616 } else { 617 if (this.staffDataArrayEdit['length']) { 618 Row() { 619 Text($r('app.string.header_title_edit')) 620 .fontWeight(FontWeight.Medium) 621 .fontColor($r('sys.color.ohos_id_color_text_primary')) 622 .fontSize($r('sys.float.ohos_id_text_size_body2')) 623 Text(` (${this.staffDataArrayEdit['length']}):`) 624 .fontFamily($r('app.string.typeface')) 625 .fontWeight(FontWeight.Regular) 626 .fontColor($r('sys.color.ohos_id_color_text_primary')) 627 .fontSize($r('sys.float.ohos_id_text_size_body2')) 628 Image($r('app.media.details')) 629 .width(Constants.FOOTER_ROW_PAD_RIGHT) 630 .height(Constants.FOOTER_ROW_PAD_RIGHT) 631 .margin({ left: Constants.AP_TEXT_PAD_RIGHT }) 632 .fillColor($r('sys.color.ohos_id_color_text_secondary')) 633 .onClick(() => { 634 this.handlePopupEdit = !this.handlePopupEdit 635 }) 636 .draggable(false) 637 .bindPopup(this.handlePopupEdit, { 638 builder: this.popupBuilderEdit, 639 placement: Placement.Bottom, 640 popupColor: ($r('sys.color.ohos_id_color_tooltip_background_dark')), 641 enableArrow: true, 642 showInSubWindow: false, 643 onStateChange: (e) => { 644 if (!e.isVisible) { 645 this.handlePopupEdit = false 646 } 647 } 648 }) 649 } 650 .justifyContent(FlexAlign.Start) 651 .width(Constants.FOOTER_ROW_WIDTH) 652 .height(Constants.ENCRYPTION_READ_ONLY_EDIT_HEIGHT) 653 654 Flex({ 655 direction: FlexDirection.Row, 656 wrap: FlexWrap.Wrap, 657 }) { 658 if (this.staffDataArrayEdit['length'] > 0) { 659 ForEach( 660 this.showNamesArrEdit, 661 (item: dlpPermission.AuthUser, index) => { 662 staffItem({ 663 authAccount: item.authAccount, 664 isActive: false, 665 changeIndex: Number(index), 666 }) 667 }, 668 (item: dlpPermission.AuthUser) => item.authAccount 669 ) 670 if (Number(this.hideNamesNumEdit) > 0) { 671 Row() { 672 if (this.showNamesArrEdit.length !== this.staffDataArrayEdit['length']) { 673 Text('+') 674 .customizeText() 675 Text(this.hideNamesNumEdit) 676 .customizeText() 677 } 678 Image($r("app.media.icon_change")) 679 .draggable(false) 680 .width(Constants.PP_IMAGE_HEIGHT) 681 .height(Constants.PP_TEXT_FONT_SIZE2) 682 .objectFit(ImageFit.Contain) 683 .rotate({ 684 angle: !this.editFlag ? Constants.PP_BUTTON_PAD : Constants.ENCRYPTION_SUCCESS_TRANSLATE 685 }) 686 .transition({ type: TransitionType.All, opacity: Constants.PP_BUTTON_PAD }) 687 } 688 .height(Constants.ENCRYPTION_SUCCESS_TOGGLE_HEIGHT) 689 .onClick(() => { 690 let showValue = toggleShow(this.staffDataArrayEdit, this.showNamesArrEdit, this.editFlag, this.rowNamesLenEdit); 691 this.showNamesArrEdit = showValue.showNamesArr as AuthAccount[]; 692 this.editFlag = showValue.showFlag as boolean; 693 }) 694 } 695 } 696 } 697 .onAreaChange((oldValue: Area, newValue: Area) => { 698 if (oldValue.width === Constants.ENCRYPTION_ON_AREA_CHANGE_WIDTH || newValue.width !== oldValue.width) { 699 let nameValue = calculate(newValue, this.staffDataArrayEdit); 700 this.rowNamesLenEdit = nameValue.rowNamesLen as number; 701 this.showNamesArrEdit = nameValue.showNamesArr as AuthAccount[]; 702 this.hideNamesNumEdit = nameValue.hideNamesNum as string; 703 this.editFlag = false; 704 } 705 }) 706 .margin({ 707 top: Constants.ENCRYPTION_SUCCESS_ADD_STAFF_MARGIN_TOP, 708 bottom: Constants.ENCRYPTION_SUCCESS_ADD_STAFF_MARGIN_BOTTOM 709 }) 710 } 711 } 712 Column({ space: Constants.HEADER_ROW_FONT_SIZE }) { 713 Row() { 714 Text($r('app.string.document_valid_until')) 715 .fontSize($r('sys.float.ohos_id_text_size_body2')) 716 .fontColor($r('sys.color.ohos_id_color_text_primary')) 717 .fontWeight(FontWeight.Medium) 718 .textAlign(TextAlign.Start) 719 Text($r('app.string.permanently')) 720 .fontSize($r('sys.float.ohos_id_text_size_body2')) 721 .fontColor($r('sys.color.ohos_id_color_text_secondary')) 722 .fontWeight(FontWeight.Regular) 723 .width(Constants.HEADER_COLUMN_WIDTH) 724 .textAlign(TextAlign.Start) 725 .margin({ left: Constants.AP_TEXT_PAD_RIGHT }) 726 } 727 .width(Constants.HEADER_COLUMN_WIDTH) 728 .height(Constants.AP_MARGIN_TOP) 729 } 730 .padding({ 731 bottom: Constants.ENCRYPTION_CHANGE_VALID_UNTIL_MARGIN_BOTTOM 732 }) 733 } 734 } 735 }.constraintSize({ 736 maxHeight: this.directionStatus === 0 ? Constants.CHANGE_MAX_HEIGHT : Constants.ENCRYPTION_SUCCESS_MAX_HEIGHT 737 }) 738 .padding({ 739 left: Constants.HEADER_COLUMN_PADDING_LEFT, 740 right: Constants.HEADER_COLUMN_PADDING_RIGHT 741 }) 742 Flex({ direction: FlexDirection.Row }) { 743 Button($r('app.string.unencrypted'), { type: ButtonType.Capsule, stateEffect: true }) 744 .backgroundColor($r('app.color.base_button_color')) 745 .width(Constants.HEADER_TEXT_WIDTH) 746 .height(Constants.FOOTER_HEIGHT) 747 .fontColor($r('app.color.encryption_cancel')) 748 .onClick(async (event) => { 749 this.unEncrypt(); 750 }) 751 .margin({ right: Constants.ENCRYPTION_PROTECTION_BUTTON_MARGIN }) 752 Button($r('app.string.change_encryption'), { type: ButtonType.Capsule, stateEffect: true }) 753 .backgroundColor($r('app.color.base_button_color')) 754 .width(Constants.HEADER_TEXT_WIDTH) 755 .fontColor($r('app.color.encryption_cancel')) 756 .height(Constants.FOOTER_HEIGHT) 757 .onClick(async (event) => { 758 // update the global resource; 759 GlobalContext.store('dlpFile', this.dlpFile); 760 router.replaceUrl({ 761 url: 'pages/encryptionProtection', 762 params: this.routerData 763 }) 764 }) 765 .margin({ left: Constants.ENCRYPTION_PROTECTION_BUTTON_MARGIN }) 766 } 767 .margin({ 768 left: Constants.ENCRYPTION_BUTTON_TO_BUTTON_WIDTH, 769 right: Constants.ENCRYPTION_BUTTON_TO_BUTTON_WIDTH, 770 bottom: Constants.ENCRYPTION_BUTTON_MARGIN_BOTTOM, 771 top: Constants.ENCRYPTION_BUTTON_TO_BUTTON_WIDTH 772 }) 773 } 774 .visibility(this.prepareData ? Visibility.Hidden : Visibility.Visible) 775 .width(Constants.HEADER_COLUMN_WIDTH) 776 .backgroundColor($r('app.color.da_button_color')) 777 .borderRadius(Constants.INDEX_BORDER_RADIUS) 778 } 779 } 780 } 781 } 782 } 783} 784