云账号提示弹窗使用新控件

Signed-off-by: fanchenxuan <fanchenxuan@huawei.com>
This commit is contained in:
fanchenxuan 2024-06-07 16:17:43 +08:00
parent c77f270849
commit c4bb0e23f9
6 changed files with 189 additions and 102 deletions

View File

@ -6,8 +6,8 @@
"versionName": "1.0.0.52",
"icon": "$media:app_icon",
"label": "$string:app_name",
"minAPIVersion": 11,
"targetAPIVersion": 11,
"minAPIVersion": 12,
"targetAPIVersion": 12,
"distributedNotificationEnabled": true,
"apiReleaseType" : "Beta5"
}

View File

@ -20,8 +20,8 @@
"versionName": "1.0.0.52",
"icon": "$media:app_icon",
"label": "$string:app_name",
"minAPIVersion": 11,
"targetAPIVersion": 11,
"minAPIVersion": 12,
"targetAPIVersion": 12,
"distributedNotificationEnabled": true,
"apiReleaseType" : "Beta5"
}

View File

@ -23,9 +23,9 @@
{
"name": "default",
"signingConfig": "default",
"compileSdkVersion": 11,
"compatibleSdkVersion": 11,
"targetSdkVersion": 11,
"compileSdkVersion": 12,
"compatibleSdkVersion": 12,
"targetSdkVersion": 12,
"runtimeOS": "OpenHarmony",
}
]

View File

@ -23,6 +23,7 @@ import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSessi
import ability from '@ohos.ability.ability';
import account_osAccount from '@ohos.account.osAccount';
import dlpPermission from '@ohos.dlpPermission';
import { CustomContentDialog } from '@ohos.arkui.advanced.Dialog';
import { sendDlpManagerAccountLogin } from '../common/utils';
import { HiLog } from '../common/HiLog';
@ -43,6 +44,71 @@ struct Index {
@State ok: string | Resource = '';
@State messageHeight: string = '';
@State windowHeight: number = 0;
@State accountType: number = dlpPermission.AccountType.DOMAIN_ACCOUNT;
dialogController: CustomDialogController = new CustomDialogController({
builder: CustomContentDialog({
contentBuilder: () => {
this.buildContent();
},
contentAreaPadding: { left: Constants.HEADER_COLUMN_PADDING_LEFT, right: Constants.HEADER_COLUMN_PADDING_RIGHT },
buttons: this.ok ? [
{
value: this.cancel ? this.cancel : $r('app.string.da_button'),
buttonStyle: ButtonStyleMode.TEXTUAL,
action: () => {
if (this.session !== undefined) {
this.session.terminateSelfWithResult({
'resultCode': 0,
'want': {
'bundleName': Constants.DLP_MANAGER_BUNDLE_NAME,
},
});
} else {
abilityResult.resultCode = 0;
(getContext(this) as common.UIAbilityContext).terminateSelfWithResult(abilityResult);
}
}
}, {
value: this.ok,
buttonStyle: ButtonStyleMode.TEXTUAL,
action: () => {
let error = (GlobalContext.load('abilityWant') as Want).parameters?.error as BusinessError;
if (error && error.code === Constants.ERR_JS_OFFLINE) {
let want: Want = {
action: 'action.system.home',
entities: ['entity.system.home'],
uri: 'wifi_entry'
};
(getContext(this) as common.UIAbilityContext).startAbility(want);
(getContext(this) as common.UIAbilityContext).terminateSelf();
return;
}
this.authWithPop();
}
}
] :
[
{
value: this.cancel ? this.cancel : $r('app.string.da_button'),
buttonStyle: ButtonStyleMode.TEXTUAL,
action: () => {
if (this.session !== undefined) {
this.session.terminateSelfWithResult({
'resultCode': 0,
'want': {
'bundleName': Constants.DLP_MANAGER_BUNDLE_NAME,
},
});
} else {
abilityResult.resultCode = 0;
(getContext(this) as common.UIAbilityContext).terminateSelfWithResult(abilityResult);
}
}
}
],
}),
});
authWithPop(): void {
HiLog.info(TAG, `authwithpop start`);
@ -127,6 +193,7 @@ struct Index {
let errorMsg = (GlobalContext.load('abilityWant') as Want).parameters?.error as BusinessError;
let accountType = (GlobalContext.load('abilityWant') as Want).parameters?.accountType as number;
let errInfo: Record<string, Resource> = {};
this.accountType = accountType;
if ([
Constants.ERR_JS_APP_PARAM_ERROR,
Constants.ERR_JS_APP_OPEN_REJECTED,
@ -152,12 +219,16 @@ struct Index {
this.cancel = errInfo.cancel;
this.ok = errInfo.ok;
this.setMessageHeight(messageCode);
if (accountType === dlpPermission.AccountType.CLOUD_ACCOUNT) {
this.dialogController.open();
}
} catch (err) {
HiLog.error(TAG, `showErrorDialog failed: ${JSON.stringify(err)}`);
}
}
build() {
@Builder
buildContent(): void {
Column() {
if (this.title) {
Row() {
@ -170,89 +241,125 @@ struct Index {
.align(Alignment.Start)
}
.width(Constants.HEADER_COLUMN_WIDTH)
.height(this.title ? Constants.DA_ROW_HEIGHT : '')
.padding({
left: Constants.HEADER_COLUMN_PADDING_LEFT,
right: Constants.HEADER_COLUMN_PADDING_RIGHT
})
.height(Constants.DA_ROW_HEIGHT)
}
Row() {
Text() {
Span(this.message)
}
.wordBreak(WordBreak.BREAK_WORD)
.fontWeight(FontWeight.Regular)
.fontColor($r('sys.color.ohos_id_color_text_primary'))
.fontSize($r('sys.float.ohos_id_text_size_body1'))
.textAlign(TextAlign.Start)
Text(this.message)
.wordBreak(WordBreak.BREAK_WORD)
.fontColor($r('sys.color.ohos_id_color_text_primary'))
.fontSize($r('sys.float.ohos_id_text_size_body1'))
.textAlign(TextAlign.Start)
}
.height(this.messageHeight)
.width(this.title ? Constants.HEADER_TEXT_WIDTH : '')
.align(Alignment.Center)
.padding({
left: Constants.HEADER_COLUMN_PADDING_LEFT,
right: Constants.HEADER_COLUMN_PADDING_RIGHT,
top: this.title ?
Constants.ENCRYPTION_MESSAGE_ALERT_MESSAGE_TOP : Constants.ENCRYPTION_MESSAGE_ALERT_MESSAGE_TOP1
})
Flex({ direction: FlexDirection.Row }) {
Button(this.cancel ? this.cancel : $r('app.string.da_button'), { type: ButtonType.Capsule, stateEffect: true })
.backgroundColor($r('sys.color.ohos_id_color_button_normal'))
.width(Constants.HEADER_TEXT_WIDTH)
.focusable(false)
.fontColor($r('sys.color.ohos_id_color_text_primary_activated'))
.height(Constants.FOOTER_HEIGHT)
.onClick(async (event) => {
if (this.session !== undefined) {
this.session.terminateSelfWithResult({
'resultCode': 0,
'want': {
'bundleName': Constants.DLP_MANAGER_BUNDLE_NAME,
},
});
} else {
abilityResult.resultCode = 0;
(getContext(this) as common.UIAbilityContext).terminateSelfWithResult(abilityResult);
}
})
.margin({ right: Constants.ENCRYPTION_PROTECTION_BUTTON_MARGIN })
if (this.ok) {
Button(this.ok, { type: ButtonType.Capsule, stateEffect: true })
.width(Constants.HEADER_TEXT_WIDTH)
.focusable(false)
.backgroundColor($r('sys.color.ohos_id_color_text_primary_activated'))
.height(Constants.FOOTER_BUTTON_HEIGHT)
.onClick(async (event) => {
let error = (GlobalContext.load('abilityWant') as Want).parameters?.error as BusinessError;
if (error && error.code === Constants.ERR_JS_OFFLINE) {
let want: Want = {
action: 'action.system.home',
entities: ['entity.system.home'],
uri: 'wifi_entry'
};
(getContext(this) as common.UIAbilityContext).startAbility(want);
(getContext(this) as common.UIAbilityContext).terminateSelf();
return;
}
this.authWithPop();
})
.margin({ left: Constants.ENCRYPTION_PROTECTION_BUTTON_MARGIN })
}
}
.margin({
left: this.ok ? Constants.ENCRYPTION_BUTTON_TO_BUTTON_WIDTH : Constants.ENCRYPTION_MESSAGE_DIALOG_TIPS_PADDING,
right: this.ok ? Constants.ENCRYPTION_BUTTON_TO_BUTTON_WIDTH : Constants.ENCRYPTION_MESSAGE_DIALOG_TIPS_PADDING,
bottom: Constants.ENCRYPTION_BUTTON_MARGIN_BOTTOM,
top: Constants.ENCRYPTION_BUTTON_TO_BUTTON_WIDTH
Constants.ENCRYPTION_MESSAGE_ALERT_MESSAGE_TOP : Constants.ENCRYPTION_MESSAGE_ALERT_MESSAGE_TOP1
})
}
.width(Constants.ENCRYPTION_MESSAGE_DIALOG_TIPS)
.borderRadius($r('sys.float.ohos_id_corner_radius_dialog'))
.alignItems(HorizontalAlign.Center)
.backgroundColor($r('sys.color.ohos_id_color_dialog_bg'))
.height(Constants.HEADER_COLUMN_WIDTH)
.shadow(ShadowStyle.OUTER_DEFAULT_MD)
.border({ width: Constants.DIALOG_MD_OFFSET, color: $r('app.color.encryption_divider_color') })
.backgroundBlurStyle(BlurStyle.COMPONENT_ULTRA_THIN);
}
build() {
if (this.accountType !== dlpPermission.AccountType.CLOUD_ACCOUNT) {
Column() {
if (this.title) {
Row() {
Text(this.title)
.lineHeight(Constants.DA_TEXT_LINE_HEIGHT)
.width(Constants.DU_WIDTH_FULL)
.fontSize($r('sys.float.ohos_id_text_size_dialog_tittle'))
.fontColor($r('sys.color.ohos_id_color_text_primary'))
.fontWeight(FontWeight.Bold)
.align(Alignment.Start)
}
.width(Constants.HEADER_COLUMN_WIDTH)
.height(this.title ? Constants.DA_ROW_HEIGHT : '')
.padding({
left: Constants.HEADER_COLUMN_PADDING_LEFT,
right: Constants.HEADER_COLUMN_PADDING_RIGHT
})
}
Row() {
Text() {
Span(this.message)
}
.wordBreak(WordBreak.BREAK_WORD)
.fontWeight(FontWeight.Regular)
.fontColor($r('sys.color.ohos_id_color_text_primary'))
.fontSize($r('sys.float.ohos_id_text_size_body1'))
.textAlign(TextAlign.Start)
}
.height(this.messageHeight)
.width(this.title ? Constants.HEADER_TEXT_WIDTH : '')
.align(Alignment.Center)
.padding({
left: Constants.HEADER_COLUMN_PADDING_LEFT,
right: Constants.HEADER_COLUMN_PADDING_RIGHT,
top: this.title ?
Constants.ENCRYPTION_MESSAGE_ALERT_MESSAGE_TOP : Constants.ENCRYPTION_MESSAGE_ALERT_MESSAGE_TOP1
})
Flex({ direction: FlexDirection.Row }) {
Button(this.cancel ? this.cancel : $r('app.string.da_button'), { type: ButtonType.Capsule, stateEffect: true })
.backgroundColor($r('sys.color.ohos_id_color_button_normal'))
.width(Constants.HEADER_TEXT_WIDTH)
.focusable(false)
.fontColor($r('sys.color.ohos_id_color_text_primary_activated'))
.height(Constants.FOOTER_HEIGHT)
.onClick(async (event) => {
if (this.session !== undefined) {
this.session.terminateSelfWithResult({
'resultCode': 0,
'want': {
'bundleName': Constants.DLP_MANAGER_BUNDLE_NAME,
},
});
} else {
abilityResult.resultCode = 0;
(getContext(this) as common.UIAbilityContext).terminateSelfWithResult(abilityResult);
}
})
.margin({ right: Constants.ENCRYPTION_PROTECTION_BUTTON_MARGIN })
if (this.ok) {
Button(this.ok, { type: ButtonType.Capsule, stateEffect: true })
.width(Constants.HEADER_TEXT_WIDTH)
.focusable(false)
.backgroundColor($r('sys.color.ohos_id_color_text_primary_activated'))
.height(Constants.FOOTER_BUTTON_HEIGHT)
.onClick(async (event) => {
let error = (GlobalContext.load('abilityWant') as Want).parameters?.error as BusinessError;
if (error && error.code === Constants.ERR_JS_OFFLINE) {
let want: Want = {
action: 'action.system.home',
entities: ['entity.system.home'],
uri: 'wifi_entry'
};
(getContext(this) as common.UIAbilityContext).startAbility(want);
(getContext(this) as common.UIAbilityContext).terminateSelf();
return;
}
this.authWithPop();
})
.margin({ left: Constants.ENCRYPTION_PROTECTION_BUTTON_MARGIN })
}
}
.margin({
left:
this.ok ? Constants.ENCRYPTION_BUTTON_TO_BUTTON_WIDTH : Constants.ENCRYPTION_MESSAGE_DIALOG_TIPS_PADDING,
right:
this.ok ? Constants.ENCRYPTION_BUTTON_TO_BUTTON_WIDTH : Constants.ENCRYPTION_MESSAGE_DIALOG_TIPS_PADDING,
bottom: Constants.ENCRYPTION_BUTTON_MARGIN_BOTTOM,
top: Constants.ENCRYPTION_BUTTON_TO_BUTTON_WIDTH
})
}
.width(Constants.ENCRYPTION_MESSAGE_DIALOG_TIPS)
.borderRadius($r('sys.float.ohos_id_corner_radius_dialog'))
.alignItems(HorizontalAlign.Center)
.backgroundColor($r('sys.color.ohos_id_color_dialog_bg'))
.height(Constants.HEADER_COLUMN_WIDTH)
.shadow(ShadowStyle.OUTER_DEFAULT_MD)
.border({ width: Constants.DIALOG_MD_OFFSET, color: $r('app.color.encryption_divider_color') })
.backgroundBlurStyle(BlurStyle.COMPONENT_ULTRA_THIN);
}
}
}

View File

@ -103,11 +103,6 @@
"ohos.want.action.sendData"
],
"uris": [
{
"scheme": "file",
"utd": "general.file",
"maxFileSupported": 1
},
{
"scheme": "file",
"utd": "general.plain-text",
@ -117,11 +112,6 @@
"scheme": "file",
"utd": "com.adobe.pdf",
"maxFileSupported": 1
},
{
"scheme": "file",
"utd": "org.openxmlformats.openxml",
"maxFileSupported": 1
}
]
}

View File

@ -116,11 +116,6 @@
"ohos.want.action.sendData"
],
"uris": [
{
"scheme": "file",
"utd": "general.file",
"maxFileSupported": 1
},
{
"scheme": "file",
"utd": "general.plain-text",
@ -130,11 +125,6 @@
"scheme": "file",
"utd": "com.adobe.pdf",
"maxFileSupported": 1
},
{
"scheme": "file",
"utd": "org.openxmlformats.openxml",
"maxFileSupported": 1
}
]
}