| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- 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'))
- }
- }
- }
|