From 428a3da5bed1b2392ebe1761188eb992c0c59d4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E8=9C=9C?= Date: Sat, 28 Dec 2024 17:47:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=BA=E8=84=B8+=E6=8C=87=E7=BA=B9+=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=20=E8=AE=A4=E8=AF=81=E9=9C=80=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李蜜 --- .../src/main/ets/common/module/DialogType.ts | 2 + entry/src/main/ets/common/utils/FuncUtils.ts | 3 + .../main/ets/pages/components/FaceAuth.ets | 142 +++++++++++++++++- 3 files changed, 143 insertions(+), 4 deletions(-) diff --git a/entry/src/main/ets/common/module/DialogType.ts b/entry/src/main/ets/common/module/DialogType.ts index e6660c0..e6ff2c3 100644 --- a/entry/src/main/ets/common/module/DialogType.ts +++ b/entry/src/main/ets/common/module/DialogType.ts @@ -24,6 +24,8 @@ export enum DialogType { PIN_FACE = 6, // PIN and FINGER PIN_FINGER = 7, + // FACE and FINGER + FACE_FINGER = 8, // ALL ALL = 10, } diff --git a/entry/src/main/ets/common/utils/FuncUtils.ts b/entry/src/main/ets/common/utils/FuncUtils.ts index f1655cc..74e3e57 100644 --- a/entry/src/main/ets/common/utils/FuncUtils.ts +++ b/entry/src/main/ets/common/utils/FuncUtils.ts @@ -42,6 +42,9 @@ export class FuncUtils { } return DialogType.PIN; } + if (type.includes(userAuth.UserAuthType.FACE) && type.includes(userAuth.UserAuthType.FINGERPRINT)) { + return DialogType.FACE_FINGER; + } if (type.includes(userAuth.UserAuthType.FINGERPRINT)) { return DialogType.FINGER; } diff --git a/entry/src/main/ets/pages/components/FaceAuth.ets b/entry/src/main/ets/pages/components/FaceAuth.ets index 67fe200..4779dc5 100644 --- a/entry/src/main/ets/pages/components/FaceAuth.ets +++ b/entry/src/main/ets/pages/components/FaceAuth.ets @@ -34,6 +34,7 @@ const PADDING_24 = 24; const MARGIN_TOP = 113; const PIN_FACE = 1; const PIN_FACE_FINGER = 2; +const FACE_FINGER = 3; const MULTI_PIN = 4; const SIX_PIN = 5; const SINGLE_FACE = 6; @@ -58,8 +59,7 @@ export default struct FaceAuth { @Link pinSubType: string; @Link dialogType: DialogType; @State inputValue: string = ''; - @State dialogTypeFlag: number = this.dialogType === DialogType.PIN_FACE ? - PIN_FACE : (this.dialogType === DialogType.ALL ? PIN_FACE_FINGER : SINGLE_FACE); + @State dialogTypeFlag: number = this.initDialogTypeFlag(); // 1:Portrait screen 2:Landscape mode @State screenType: number = 0; @State fingerPositionY: number = 0; @@ -88,6 +88,18 @@ export default struct FaceAuth { this.inputValue = promptText; } + initDialogTypeFlag(): number { + if (this.dialogType === DialogType.PIN_FACE) { + return PIN_FACE; + } else if (this.dialogType === DialogType.ALL) { + return PIN_FACE_FINGER; + } else if (this.dialogType === DialogType.FACE_FINGER) { + return FACE_FINGER; + } else { + return SINGLE_FACE; + } + } + aboutToAppear(): void { LogUtils.debug(TAG, 'aboutToAppear'); try { @@ -115,7 +127,7 @@ export default struct FaceAuth { this.prompt = (AppStorage.get("context") as common.ExtensionContext)?.resourceManager .getStringSync($r('app.string.unified_authwidget_hint_recognition').id); AuthUtils.getInstance().sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFace]); - } else if (this.dialogType === DialogType.ALL) { + } else if (this.dialogType === DialogType.ALL || this.dialogType === DialogType.FACE_FINGER) { AuthUtils.getInstance() .sendNotice('EVENT_AUTH_TYPE_READY', [Constants.noticeTypeFinger, Constants.noticeTypeFace]); } else { @@ -134,6 +146,8 @@ export default struct FaceAuth { LogUtils.error(TAG, 'aboutToAppear catch error: ' + error?.code); (AppStorage.get("session") as UIExtensionContentSession)?.terminateSelf(); } + LogUtils.error(TAG, + `================dialogType: ${this.dialogType} dialogTypeFlag: ${this.dialogTypeFlag} isPinFaceFinger: ${this.isPinFaceFinger}`); } aboutToDisappear(): void { @@ -193,6 +207,7 @@ export default struct FaceAuth { onCmdDataChange(num?: string): void { this.cmdData.length > 0 && this.cmdData.map(async (item) => { + LogUtils.debug(TAG, '=========================item.payload: ' + JSON.stringify(item.payload)); const payload: CmdData = item.payload; if (payload.type === Constants.noticeTypePin) { if (payload.result === 0) { @@ -270,6 +285,7 @@ export default struct FaceAuth { this.fingerPosition = JSON.parse(payload.sensorInfo); const displayClass = display.getDefaultDisplaySync(); this.screen = [displayClass.width, displayClass.height]; + LogUtils.debug(TAG, '=========================sensorType: ' + JSON.parse(payload.sensorInfo)?.sensorType as string); switch (JSON.parse(payload.sensorInfo)?.sensorType as string) { case 'NON_SENSOR': case 'OUT_OF_SCREEN_SENSOR': { @@ -277,7 +293,9 @@ export default struct FaceAuth { break; } default: - this.isPinFaceFinger = true; + if (this.dialogType !== DialogType.FACE_FINGER) { + this.isPinFaceFinger = true; + } let tempPositionLine = JSON.parse(payload.sensorInfo).udSensorCenterYInThousandth / displayClass.height; FuncUtils.judgmentOverflow(tempPositionLine); if (tempPositionLine < FINGER_SENSOR_POSITION_LINE) { @@ -684,7 +702,123 @@ export default struct FaceAuth { bottom: ($r('sys.float.ohos_id_dialog_margin_bottom')) }) } + } else if (this.dialogType === DialogType.FACE_FINGER && + (AppStorage.get("wantParams") as WantParams)?.navigationButtonText as string) { + Column() { + // The first form of facial fingerprint password + Flex({ justifyContent: FlexAlign.SpaceBetween }) { + Image($r('app.media.ic_public_cancel')) + .draggable(false) + .id('cancelImgAllFaceAuth') + .width($r('app.float.digital_password_mask_height')) + .height($r('app.float.digital_password_mask_height')) + .margin({ + top: $r('app.float.digital_password_mask_height'), + left: $r('app.float.digital_password_mask_height') + }) + .onClick(() => { + this.textValue = ''; + this.handleCancel(); + }) + Button((AppStorage.get("wantParams") as WantParams)?.navigationButtonText as string) + .id('usePwdBtnAllFaceAuth') + .backgroundColor(Color.White) + .height($r('app.float.digital_password_mask_height')) + .padding(0) + .margin({ + top: $r('app.float.digital_password_mask_height'), + right: $r('app.float.digital_password_mask_height') + }) + .fontColor($r('sys.color.ohos_id_color_activated')) + .fontSize($r('sys.float.ohos_id_text_size_body1')) + .fontWeight(FontWeight.Medium) + .onClick(() => { + this.textValue = ''; + AuthUtils.getInstance().sendNotice(Constants.noticeEventCancel, [Constants.noticeTypeFace]); + this.handleCancel(); + }) + } + if (AppStorage.get('titleLength') as number < (AppStorage.get("wantParams") as WantParams)?.title.length) { + Scroll() { + Column() { + Image($r('app.media.error_faceID')) + .draggable(false) + .id('imgAllFaceAuth') + .width($r('app.float.image_small')) + .height($r('app.float.image_small')) + .margin({ bottom: $r('app.float.content_padding') }) + .colorBlend($r('sys.color.ohos_id_color_activated')) + .onClick(() => { + this.sendFaceEvent(); + }) + Text((AppStorage.get("wantParams") as WantParams)?.title) + .draggable(false) + .fontSize($r('sys.float.ohos_id_text_size_body1')) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .fontWeight(FontWeight.Medium) + Text(this.prompt) + .draggable(false) + .id('resetPromptTextAllFaceAuth') + .margin({ top: $r('app.float.element_margin') }) + .height($r('app.float.size_24')) + .fontSize($r('sys.float.ohos_id_text_size_body2')) + .fontColor(this.onFontColor(this.prompt, (AppStorage.get("context") as common.ExtensionContext))) + }.margin({left: $r('app.float.size_24'), right: $r('app.float.size_24')}) + } + .width('100%') + .height($r('app.float.scroll_height_122')) + .margin({top: $r('app.float.content_padding')}) + .scrollable(ScrollDirection.Vertical) + .scrollBarColor(Color.Gray) + } else { + Image($r('app.media.error_faceID')) + .draggable(false) + .id('imgAllFaceAuth') + .width($r('app.float.image_small')) + .height($r('app.float.image_small')) + .margin({ top: $r('app.float.content_padding'), bottom: $r('app.float.content_padding') }) + .colorBlend($r('sys.color.ohos_id_color_activated')) + .onClick(() => { + this.sendFaceEvent(); + }) + Text((AppStorage.get("wantParams") as WantParams)?.title) + .draggable(false) + .fontSize($r('sys.float.ohos_id_text_size_body1')) + .fontColor($r('sys.color.ohos_id_color_text_primary')) + .height($r('app.float.size_24')) + .fontWeight(FontWeight.Medium) + Text(this.prompt) + .draggable(false) + .id('resetPromptTextAllFaceAuth') + .margin({ top: $r('app.float.element_margin') }) + .height($r('app.float.size_24')) + .fontSize($r('sys.float.ohos_id_text_size_body2')) + .fontColor(this.onFontColor(this.prompt, (AppStorage.get("context") as common.ExtensionContext))) + } + Image($r('app.media.ic_blue_fingerprint')) + .draggable(false) + .id('blueFingerprintImgAllFaceAuth') + // radius + .width(px2vp(this.fingerPosition.udSensorRadiusInPx * 2)) + .height(px2vp(this.fingerPosition.udSensorRadiusInPx * 2)) + .margin({ + top: $r('app.float.digital_password_mask_height'), + bottom: $r('app.float.digital_password_mask_height') + }) + .colorBlend($r('sys.color.ohos_id_color_activated')) + .onClick(() => { + this.sendFingerEvent(); + }) + } + .position({ y: this.fingerPositionY }) + .backgroundColor($r('sys.color.ohos_id_color_dialog_bg')) + .borderRadius($r('sys.float.ohos_id_corner_radius_dialog')) + .margin({ + left: ($r('sys.float.ohos_id_dialog_margin_start')), + right: ($r('sys.float.ohos_id_dialog_margin_end')), + bottom: ($r('sys.float.ohos_id_dialog_margin_bottom')) + }) } else { Column() { if (this.dialogTypeFlag === PIN_FACE) { -- Gitee