• 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';
21const TAG = "[DLPManager_staff]";
22
23@Component
24struct staffItem {
25  @Prop authAccount: string = '';
26  @Prop isActive: boolean = false;
27  @State containerBackgroundColor: string = '#0D000000';
28  @State color: Resource[] = [
29    $r('sys.color.ohos_id_color_special1'),
30    $r('sys.color.ohos_id_color_special2'),
31    $r('sys.color.ohos_id_color_special3'),
32    $r('sys.color.ohos_id_color_special4'),
33    $r('sys.color.ohos_id_color_special5'),
34    $r('sys.color.ohos_id_color_special6'),
35    $r('sys.color.ohos_id_color_special7'),
36    $r('sys.color.ohos_id_color_special8'),
37    $r('sys.color.ohos_id_color_special9'),
38    $r('sys.color.ohos_id_color_special10'),
39    $r('sys.color.ohos_id_color_special11'),
40  ];
41  @Prop changeIndex: number = 0;
42  @State domainTips: string = '';
43  @State accountNameTips: string = '';
44  @State handlePopupTips: boolean = false;
45
46  @Builder popupBuilderTips() {
47    Column() {
48      Row() {
49        Text($r('app.string.encrypt_employee_id'))
50          .fontFamily('HarmonyHeiTi')
51          .fontSize($r('sys.float.ohos_id_text_size_body2'))
52          .fontColor($r('sys.color.ohos_id_color_primary_dark'))
53        Text(' : ')
54          .fontFamily('HarmonyHeiTi')
55          .fontSize($r('sys.float.ohos_id_text_size_body2'))
56          .fontColor($r('sys.color.ohos_id_color_primary_dark'))
57        Text(this.accountNameTips)
58          .fontFamily('HarmonyHeiTi')
59          .fontSize($r('sys.float.ohos_id_text_size_body2'))
60          .fontColor($r('sys.color.ohos_id_color_primary_dark'))
61      }
62      .width(Constants.HEADER_COLUMN_MESSAGE_TIPS)
63      if (GlobalContext.load('domainAccount')) {
64        Row() {
65          Text($r('app.string.encrypt_domain'))
66            .fontFamily('HarmonyHeiTi')
67            .fontSize($r('sys.float.ohos_id_text_size_body2'))
68            .fontColor($r('sys.color.ohos_id_color_primary_dark'))
69          Text(' : ')
70            .fontFamily('HarmonyHeiTi')
71            .fontSize($r('sys.float.ohos_id_text_size_body2'))
72            .fontColor($r('sys.color.ohos_id_color_primary_dark'))
73          Text(this.domainTips)
74            .fontFamily('HarmonyHeiTi')
75            .fontSize($r('sys.float.ohos_id_text_size_body2'))
76            .fontColor($r('sys.color.ohos_id_color_primary_dark'))
77        }
78        .width(Constants.HEADER_COLUMN_MESSAGE_TIPS)
79      }
80    }
81    .padding({
82      left: Constants.ROW_FONT_SIZE,
83      right: Constants.ROW_FONT_SIZE,
84      top: Constants.DA_MARGIN_TOP,
85      bottom: Constants.DA_MARGIN_TOP
86    })
87  }
88
89  private rollColor() {
90    while (this.changeIndex > this.color.length - 1) {
91      this.changeIndex = this.changeIndex - this.color.length
92    }
93    return this.color[this.changeIndex]
94  }
95
96  build() {
97    Row() {
98      Text(this.authAccount?.[0]?.toLocaleUpperCase())
99        .fontSize($r('sys.float.ohos_id_text_size_body3'))
100        .fontWeight(FontWeight.Regular)
101        .width(Constants.HEADER_ROW_FONT_SIZE)
102        .height(Constants.HEADER_ROW_FONT_SIZE)
103        .borderRadius(Constants.ENCRYPTION_STAFF_BORDER_RADIUS)
104        .backgroundColor(this.rollColor())
105        .fontColor(Color.White)
106        .textAlign(TextAlign.Center)
107        .margin({
108          right: Constants.ADD_STAFF_ITEM_MARGIN_RIGHT,
109        })
110      Text(this.authAccount.split('')
111        .join('\u200B'))
112        .constraintSize({
113          maxWidth: Constants.ENCRYPTION_STAFF_MAX_WIDTH
114        })
115        .textOverflow({
116          overflow: TextOverflow.Ellipsis
117        })
118        .maxLines(Constants.PP_TEXT_MAX_LINE)
119        .fontSize($r('sys.float.ohos_id_text_size_button2'))
120    }
121    .onClick(() => {
122      let domainAccountInfo: account_osAccount.GetDomainAccountInfoOptions = {
123        domain: 'china',
124        accountName: this.authAccount.toLocaleLowerCase()
125      }
126      if (GlobalContext.load('domainAccount')) {
127        try {
128          account_osAccount.DomainAccountManager.getAccountInfo(domainAccountInfo)
129            .then((result: account_osAccount.DomainAccountInfo) => {
130              this.handlePopupTips = !this.handlePopupTips;
131              this.domainTips = result.domain;
132              this.accountNameTips = result.accountName;
133            }).catch((err: BusinessError) => {
134            console.log(TAG, 'call getAccountInfo failed, error: ' + JSON.stringify(err));
135          });
136        } catch (err) {
137          console.log(TAG, 'getAccountInfo exception = ' + JSON.stringify(err));
138        }
139      } else {
140        this.accountNameTips = this.authAccount;
141      }
142    })
143    .bindPopup(this.handlePopupTips, {
144      builder: this.popupBuilderTips,
145      placement: Placement.Bottom,
146      popupColor: ($r('sys.color.ohos_id_color_tooltip_background_dark')),
147      enableArrow: true,
148      showInSubWindow: false,
149      onStateChange: (e) => {
150        if (!e.isVisible) {
151          this.handlePopupTips = false;
152        }
153      }
154    })
155    .width(Constants.ENCRYPTION_ADD_STAFF_WIDTH)
156    .alignItems(VerticalAlign.Center)
157    .backgroundColor(this.isActive ? '#1A0A59F7' : this.containerBackgroundColor)
158    .borderRadius(Constants.ENCRYPTION_SUCCESS_CHANGE_TOP)
159    .padding(
160      {
161        top: Constants.ENCRYPTION_STAFF_PAD,
162        bottom: Constants.ENCRYPTION_STAFF_PAD,
163        left: Constants.FOOTER_ROW_MARGIN,
164        right: Constants.FOOTER_ROW_MARGIN
165      }
166    )
167    .margin({
168      right: Constants.ENCRYPTION_ADD_STAFF_MARGIN_RIGHT,
169      bottom: Constants.ENCRYPTION_ADD_STAFF_MARGIN_BOTTOM
170    })
171  }
172}
173
174export default staffItem;
175