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