• 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 account_osAccount from '@ohos.account.osAccount';
17import { BusinessError } from '@ohos.base';
18import osAccount from '@ohos.account.osAccount';
19import Constants from '../constant';
20import GlobalContext from '../GlobalContext';
21import { AccountTips, AccountTipsConfig } from '../AccountTipsConfig';
22import { getAlertMessage } from '../utils';
23import { DlpAlertDialog } from '../components/dlp_alert_dialog';
24
25const TAG = "[DLPManager_staff]";
26
27@Extend(Text) function TipsTextStyle(){
28  .fontSize($r('sys.float.ohos_id_text_size_body2'))
29  .fontColor($r('sys.color.ohos_id_color_primary_dark'))
30  .textOverflow({
31    overflow: TextOverflow.Ellipsis
32  })
33  .maxLines(Constants.PP_TEXT_MAX_LINE)
34}
35
36@Component
37struct staffItem {
38  @Prop authAccount: string = '';
39  @Prop isActive: boolean = false;
40  @State color: Resource[] = [
41    $r('sys.color.ohos_id_color_special1'),
42    $r('sys.color.ohos_id_color_special2'),
43    $r('sys.color.ohos_id_color_special3'),
44    $r('sys.color.ohos_id_color_special4'),
45    $r('sys.color.ohos_id_color_special5'),
46    $r('sys.color.ohos_id_color_special6'),
47    $r('sys.color.ohos_id_color_special7'),
48    $r('sys.color.ohos_id_color_special8'),
49    $r('sys.color.ohos_id_color_special9'),
50    $r('sys.color.ohos_id_color_special10'),
51    $r('sys.color.ohos_id_color_special11'),
52  ];
53  @Prop changeIndex: number = 0;
54  @State domainTips: string = '';
55  @State accountNameTips: string = '';
56  @State handlePopupTips: boolean = false;
57
58  @Prop textContent: string = '';
59  @State accountTipsArray: Array<AccountTips> = new Array<AccountTips>();
60  dlpAlertDialog?: CustomDialogController;
61
62  @Builder popupBuilderTips() {
63    Column() {
64      if(GlobalContext.load('domainAccount')){
65        ForEach(this.accountTipsArray, (item: AccountTips) => {
66          if (item.isShow) {
67            Row() {
68              if (AccountTipsConfig.isSysLanguage()) {
69                Text(item.description?.replace('%s', item.value)).TipsTextStyle()
70              } else {
71                Text(item.descriptionEn?.replace('%s', item.value)).TipsTextStyle()
72              }
73            }.height(Constants.TIPS_HEIGHT_ITEM)
74          }
75        }, (item: AccountTips) => item.key)
76      }else{
77        Row() {
78          Text($r('app.string.encrypt_employee_id', this.accountNameTips))
79            .wordBreak(WordBreak.BREAK_ALL)
80            .TipsTextStyle()
81        }
82        .width(Constants.HEADER_COLUMN_MESSAGE_TIPS)
83      }
84    }
85    .alignItems(HorizontalAlign.Start)
86    .padding({
87      left: Constants.ROW_FONT_SIZE,
88      right: Constants.ROW_FONT_SIZE,
89      top: Constants.DA_MARGIN_TOP,
90      bottom: Constants.DA_MARGIN_TOP
91    })
92  }
93
94  private rollColor() {
95    while (this.changeIndex > this.color.length - 1) {
96      this.changeIndex = this.changeIndex - this.color.length
97    }
98    return this.color[this.changeIndex]
99  }
100
101  private showErrorDialog(title: Resource, message: Resource) {
102    this.dlpAlertDialog = new CustomDialogController({
103      builder: DlpAlertDialog({
104        title: title,
105        message: message,
106        action: () => {
107        }
108      }),
109      autoCancel: false,
110      customStyle: true,
111    });
112    this.dlpAlertDialog.open();
113  }
114
115  private splitContent() {
116    if (GlobalContext.load('domainAccount')) {
117      if (this.textContent) {
118        if (this.textContent.length > Constants.TIPS_NAME_LENGTH) {
119          return this.textContent.split('').join(Constants.TIPS_SPACE_ZERO)
120        } else if (this.textContent.length === Constants.TIPS_NAME_LENGTH) {
121          return this.textContent.split('').join(Constants.TIPS_SPACE_EM)
122        } else {
123          return Constants.TIPS_SPACE_EN + this.textContent;
124        }
125      }
126    }
127    return this.textContent;
128  }
129
130  async aboutToAppear(){
131    if (!GlobalContext.load('domainAccount')) {
132      this.textContent = this.authAccount;
133    }
134  }
135
136  build() {
137    Row() {
138      Text(this.authAccount?.[0]?.toLocaleUpperCase())
139        .fontSize($r('sys.float.ohos_id_text_size_body3'))
140        .fontWeight(FontWeight.Regular)
141        .width(Constants.HEADER_ROW_FONT_SIZE)
142        .height(Constants.HEADER_ROW_FONT_SIZE)
143        .borderRadius(Constants.ENCRYPTION_STAFF_BORDER_RADIUS)
144        .backgroundColor(this.rollColor())
145        .fontColor($r('sys.color.ohos_fa_text_contrary'))
146        .textAlign(TextAlign.Center)
147        .margin({
148          right: Constants.ADD_STAFF_ITEM_MARGIN_RIGHT,
149        })
150      Text(this.splitContent())
151        .constraintSize({
152          maxWidth: this.authAccount === this.textContent ? Constants.ENCRYPTION_STAFF_MAX_WIDTH : Constants.TIPS_STAFF_MAX_WIDTH
153        })
154        .textOverflow({
155          overflow: TextOverflow.Ellipsis
156        })
157        .maxLines(Constants.PP_TEXT_MAX_LINE)
158        .fontSize($r('sys.float.ohos_id_text_size_button2'))
159    }
160    .onClick(() => {
161      if (GlobalContext.load('domainAccount')) {
162        try {
163          AccountTipsConfig.getAccountInfo(this.authAccount)
164            .then(async (result: account_osAccount.DomainAccountInfo) => {
165              this.accountTipsArray = await AccountTipsConfig.getConfigTips();
166              this.handlePopupTips = !this.handlePopupTips;
167              this.accountTipsArray?.forEach((item: AccountTips) => {
168                let value: string = result[item.key];
169                item.value = value;
170              })
171            })
172            .catch((err: BusinessError) => {
173              console.error(`${TAG} getAccountInfo error: ${JSON.stringify(err)}`);
174              let errInfo = getAlertMessage(err);
175              this.showErrorDialog(errInfo.title, errInfo.msg);
176            })
177        } catch (err) {
178          console.error(TAG, 'getAccountInfo exception = ' + JSON.stringify(err));
179        }
180      } else {
181        this.accountNameTips = this.authAccount;
182      }
183    })
184    .bindPopup(this.handlePopupTips, {
185      builder: this.popupBuilderTips,
186      placement: Placement.BottomLeft,
187      popupColor: ($r('sys.color.ohos_id_color_tooltip_background_dark')),
188      enableArrow: true,
189      showInSubWindow: false,
190      arrowOffset: Constants.TIPS_ARROW_OFFSET,
191      onStateChange: (e) => {
192        if (!e.isVisible) {
193          this.handlePopupTips = false;
194        }
195      }
196    })
197    .width(this.authAccount === this.textContent ? Constants.ENCRYPTION_ADD_STAFF_WIDTH : Constants.TIPS_STAFF_WIDTH)
198    .alignItems(VerticalAlign.Center)
199    .backgroundColor(this.isActive ? '#1A0A59F7' : $r('sys.color.ohos_id_color_button_normal'))
200    .borderRadius(Constants.ENCRYPTION_SUCCESS_CHANGE_TOP)
201    .padding(
202      {
203        top: Constants.ENCRYPTION_STAFF_PAD,
204        bottom: Constants.ENCRYPTION_STAFF_PAD,
205        left: Constants.FOOTER_ROW_MARGIN,
206        right: Constants.FOOTER_ROW_MARGIN
207      }
208    )
209    .margin({
210      right: Constants.ENCRYPTION_ADD_STAFF_MARGIN_RIGHT,
211      bottom: Constants.ENCRYPTION_ADD_STAFF_MARGIN_BOTTOM
212    })
213  }
214}
215
216export { staffItem };
217