import TitleBar from '../view/TitleBar' import { promptAction, router } from '@kit.ArkUI' import { CommonConstants } from '../common/constants/CommonConstants' import { AppUtil, PreferencesUtil, ToastUtil } from '@pura/harmony-utils' import { Utility } from '../common/util/Utility' import UserAuthModel from '../viewmodel/UserAuthModel' import { common, Want } from '@kit.AbilityKit' @Preview @Component export struct Verify{ @State verType:number = 0;// 0:密码 1:指纹 2:人脸 @State isMima:boolean = true @State isFingerprint:boolean = false @State isFace:boolean = false public onVerifyCompleted?: (isSuccess:boolean) => void//验证完成的结果。通知是否成功 @State titleBarModel: TitleBar.Model = new TitleBar.Model() .setTitleTextStyle(FontStyle.Normal) .setTitleBarStyle(TitleBar.BarStyle.TRANSPARENT) .setLeftIcon($r('app.media.left_back_white')) .setTitleName('验证密码') .setTitleFontColor(Color.White) .setTitleBarBackground($r('app.color.title_bar_bg')) .setLeftTitleBackground($r('app.color.title_bar_bg')) .setOnLeftClickListener(() => { router.back() }) @State verName:string = '' // 组件生命周期 aboutToAppear() { this.verName = AppUtil.getVersionName() this.verType = PreferencesUtil.getNumberSync('verType') this.doStartVerify() console.info('LifeCycleComponent aboutToAppear'); } doStartVerify(){ if(this.verType === 1){ if(UserAuthModel.isFingerprintAvailable()){ this.isMima = false this.isFingerprint = true this.isFace = false UserAuthModel.getFingerprintAuth(this.userAuthResult); UserAuthModel.start() }else{ this.gotoAuthSetting() } }else if(this.verType === 2){//如果是人脸,自动开启识别 if(UserAuthModel.isFaceAvailable()){ this.isMima = false this.isFingerprint = false this.isFace = true UserAuthModel.getFaceAuth(this.userAuthResult); UserAuthModel.start() }else{ this.gotoAuthSetting() } }else{ if(UserAuthModel.isPinAvailable()){ this.isMima = true this.isFingerprint = false this.isFace = false UserAuthModel.getPINAuth(this.userAuthResult); UserAuthModel.start() }else{ this.gotoAuthSetting() } } } //跳转到生物识别系统设置页面 gotoAuthSetting(){ // ToastUtil.showToast('第一次请开启密码、指纹或人脸其中的一种安全验证方式。') let context = getContext(this) as common.UIAbilityContext; let want: Want = { bundleName: 'com.huawei.hmos.settings', abilityName: 'com.huawei.hmos.settings.MainAbility', uri: 'biometrics_and_password_settings', parameters: { pushParams: 'com.example.natificationdemo' } }; context.startAbility(want) } /** * Operations After a User Is Successfully Authenticated. * * @param Whether the user authentication is successful. */ userAuthResult: (isSuccess: boolean) => void = (isSuccess: boolean) => { this.onVerifyCompleted?.(isSuccess)//播放完成的接口回调 } // 组件生命周期 aboutToDisappear() { console.info('LifeCycleComponent aboutToDisappear'); } build() { Column(){ // TitleBar({model:$titleBarModel}) Column() { Column(){ //锁屏密码 Row() { Image($r('app.media.mima')) .height(30) .alignSelf(ItemAlign.Center) .margin({ left: 28 }) Text('密码') .margin({ left: 10, right: 20 }) .fontSize(18) .fontColor(Color.Gray) .fontWeight(480) .id('text_update') Blank() Radio({ value: 'Radio1', group: 'radioGroup' }) .width(22) .height(22) .margin({ left: 20, right: 20 }) .align(Alignment.Center) .checked(this.isMima) .onChange((isChecked: boolean) => { if (isChecked) { this.verType = 0 } }) } .width('100%') .height(66) .onClick(() => { this.isMima = true this.isFingerprint = false this.isFace = false this.verType = 0 }) Row() { Image($r('app.media.touchid')) .height(30) .alignSelf(ItemAlign.Center) .margin({ left: 28 }) Text('指纹') .margin({ left: 10, right: 20 }) .fontSize(18) .fontColor(Color.Gray) .fontWeight(480) .id('text_update') Blank() Radio({ value: 'Radio2', group: 'radioGroup' }) .width(22) .height(22) .margin({ left: 20, right: 20 }) .align(Alignment.Center) .checked(this.isFingerprint) .onChange((isChecked: boolean) => { if (isChecked) { this.verType = 1 } }) } .width('100%') .height(66) .onClick(() => { this.isMima = false this.isFingerprint = true this.isFace = false this.verType = 1 }) Row() { Image($r('app.media.face')) .height(30) .alignSelf(ItemAlign.Center) .margin({ left: 28 }) Text('人脸') .margin({ left: 10, right: 20 }) .fontSize(18) .fontColor(Color.Gray) .fontWeight(480) .id('text_update') Blank() Radio({ value: 'Radio3', group: 'radioGroup' }) .width(22) .height(22) .margin({ left: 20, right: 20 }) .align(Alignment.Center) .checked(this.isFace) .onChange((isChecked: boolean) => { if (isChecked) { this.verType = 2 } }) } .width('100%') .height(66) .onClick(() => { this.isMima = false this.isFingerprint = false this.isFace = true this.verType = 2 }) } .backgroundColor($r('app.color.bottom_control_background')) .margin({top:30,left:30,right:30}) .borderRadius(20) Button('确定', { type: ButtonType.Capsule, stateEffect: false }) .width('70%') .height(55) .margin({ top: 25, bottom: 10 }) .backgroundColor($r('app.color.title_bar_bg')) // .linearGradient({ // direction: GradientDirection.Right, // colors: [['#ff37a0fc', 0.0], ['#f5856e', 0.5], ['#67e667', 1.0]] // }) .onClick(() => { this.doStartVerify() PreferencesUtil.putSync('verType',this.verType) }) } // .linearGradient({colors:[['#ff37a0fc', 0.0], ['#67e667', 0.5]]}) .height('100%') .width('100%') .backgroundColor($r('app.color.index_background')) } } }