• 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 UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession';
18import { BusinessError } from '@ohos.base';
19import Constants from '../common/constant';
20import { showErrorDialogAndExit, sendDlpManagerAccountLogin, colorStatus } from '../common/utils';
21
22const TAG = "[DLPManager_alertMessage]";
23
24let storage = LocalStorage.getShared();
25@Entry(storage)
26@Component
27struct AlertMessage {
28  @State session: UIExtensionContentSession | undefined = storage === undefined ? undefined : storage.get<UIExtensionContentSession>('session');
29  @State message?: Resource = storage.get<Resource>('message');
30  @State messageName?: string = storage.get<string>('messageName');
31  @State title?: Resource = storage.get<Resource>('title');
32  @State cancel?: Resource = storage.get<Resource>('cancel');
33  @State ok?: Resource = storage.get<Resource>('ok');
34
35  authWithPop(): void {
36    console.log(TAG, 'authwithpop start');
37    try {
38      account_osAccount.DomainAccountManager.authWithPopup({
39        onResult: async (resultCode: number, authResult: account_osAccount.AuthResult) => {
40          sendDlpManagerAccountLogin(resultCode);
41          if (resultCode === Constants.ERR_JS_NETWORK_INVALID) {
42            await showErrorDialogAndExit({ code: Constants.ERR_JS_APP_NETWORK_INVALID } as BusinessError);
43            return;
44          }
45          if (this.session !== undefined) {
46            this.session.terminateSelfWithResult({
47              'resultCode': 0,
48              'want': {
49                'bundleName': Constants.DLP_MANAGER_BUNDLE_NAME,
50              },
51            });
52          }
53          console.log(TAG, 'auth resultCode = ' + resultCode);
54          console.log(TAG, 'auth authResult = ' + JSON.stringify(authResult));
55        }
56      })
57    } catch (err) {
58      console.log(TAG, 'auth exception = ' + JSON.stringify(err));
59    }
60  }
61
62  build() {
63    GridRow({
64      columns: {
65        xs: Constants.XS_COLUMNS,
66        sm: Constants.SM_COLUMNS,
67        md: Constants.MD_COLUMNS,
68        lg: Constants.LG_COLUMNS
69      },
70      gutter: Constants.DIALOG_GUTTER
71    }) {
72      GridCol({
73        span: {
74          xs: Constants.XS_SPAN,
75          sm: Constants.SM_SPAN,
76          md: Constants.SM_SPAN,
77          lg: Constants.SM_SPAN
78        },
79        offset: {
80          xs: Constants.XS_OFFSET,
81          sm: Constants.SM_OFFSET,
82          md: Constants.LG_OFFSET,
83          lg: Constants.SM_SPAN
84        }
85      }) {
86        Flex({ justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center,
87          direction: FlexDirection.Column }) {
88          Flex({ alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
89            Column() {
90              Row() {
91                Text(this.title)
92                  .lineHeight(Constants.DA_TEXT_LINE_HEIGHT)
93                  .width(Constants.DU_WIDTH_FULL)
94                  .fontSize($r('sys.float.ohos_id_text_size_dialog_tittle'))
95                  .fontColor($r('sys.color.ohos_id_color_text_primary'))
96                  .fontWeight(FontWeight.Medium)
97              }
98              .height(this.title ? Constants.DA_ROW_HEIGHT : '')
99              .padding({
100                left: Constants.ENCRYPTION_MESSAGE_ALERT_MESSAGE_PADDING_LEFT,
101                top: this.title ? Constants.ENCRYPTION_MESSAGE_ALERT_MESSAGE_PADDING_TOP : 0
102              })
103              Row() {
104                Text() {
105                  if (this.messageName) {
106                    Span('“')
107                    Span(this.messageName)
108                    Span('”')
109                  }
110                  Span(this.message)
111                }
112                .fontWeight(FontWeight.Regular)
113                .fontColor($r('sys.color.ohos_id_color_text_primary'))
114                .fontSize($r('sys.float.ohos_id_text_size_body1'))
115                .textAlign(TextAlign.Start)
116              }
117              .align(Alignment.Center)
118              .padding({
119                left: Constants.HEADER_COLUMN_PADDING_LEFT,
120                right: Constants.HEADER_COLUMN_PADDING_RIGHT,
121                top: this.title ? Constants.ENCRYPTION_MESSAGE_ALERT_MESSAGE_TOP : Constants.ENCRYPTION_MESSAGE_ALERT_MESSAGE_TOP1
122              })
123              Flex({ direction: FlexDirection.Row }) {
124                Button(this.cancel? this.cancel : $r('app.string.da_button'), { type: ButtonType.Capsule, stateEffect: true })
125                  .backgroundColor($r('sys.color.ohos_id_color_button_normal'))
126                  .width(Constants.HEADER_TEXT_WIDTH)
127                  .focusable(false)
128                  .fontColor($r('sys.color.ohos_id_color_text_primary_activated'))
129                  .height(Constants.FOOTER_HEIGHT)
130                  .onClick(async (event) => {
131                    if (this.session !== undefined) {
132                      this.session.terminateSelfWithResult({
133                        'resultCode': 0,
134                        'want': {
135                          'bundleName': Constants.DLP_MANAGER_BUNDLE_NAME,
136                        },
137                      });
138                    }
139                  })
140                  .margin({ right: Constants.ENCRYPTION_PROTECTION_BUTTON_MARGIN })
141                if (this.ok) {
142                  Button(this.ok, { type: ButtonType.Capsule, stateEffect: true })
143                    .backgroundColor($r('sys.color.ohos_id_color_text_primary_activated'))
144                    .width(Constants.HEADER_TEXT_WIDTH)
145                    .focusable(false)
146                    .height(Constants.FOOTER_BUTTON_HEIGHT)
147                    .onClick(async (event) => {
148                      this.authWithPop();
149                    })
150                    .margin({ left: Constants.ENCRYPTION_PROTECTION_BUTTON_MARGIN })
151                }
152              }
153              .margin({
154                left: this.ok ? Constants.ENCRYPTION_BUTTON_TO_BUTTON_WIDTH : Constants.ENCRYPTION_MESSAGE_DIALOG_TIPS_PADDING,
155                right: this.ok ? Constants.ENCRYPTION_BUTTON_TO_BUTTON_WIDTH : Constants.ENCRYPTION_MESSAGE_DIALOG_TIPS_PADDING,
156                bottom: Constants.ENCRYPTION_BUTTON_MARGIN_BOTTOM,
157                top: Constants.ENCRYPTION_BUTTON_TO_BUTTON_WIDTH
158              })
159            }
160            .width(Constants.ENCRYPTION_MESSAGE_DIALOG_TIPS)
161            .borderRadius($r('sys.float.ohos_id_corner_radius_dialog'))
162            .alignItems(HorizontalAlign.Center)
163            .backgroundColor($r('sys.color.ohos_id_color_dialog_bg'))
164            .shadow(ShadowStyle.OUTER_DEFAULT_SM)
165          }
166        }
167      }
168    }
169  }
170}
171