HarmonyOS开发中如何实现滑动验证码功能?

HarmonyOS开发中如何实现滑动验证码功能?

阅读 590
1 个回答

请参考以下代码示例:

import promptAction from '@ohos.promptAction' 
let customDialogId: number = 0; 
let sliderValue = 0; 
@Builder 
function customDialogBuilder() { 
  Column() { 
    Row({space:20}){ 
      Text('安全验证').fontSize(26) 
        .width('80%') 
        .height(60) 
        .textAlign(TextAlign.Center) 
        .lineHeight(60) 
      Image($r('app.media.error')) 
        .width(26) 
        .height(26) 
        .onClick(() => { 
          promptAction.closeCustomDialog(customDialogId) 
        }) 
    } 
    .margin({bottom:16}) 
    Stack() { 
      Text("请滑到最右端") 
        .fontSize(20) 
        .onClick(() => { 
          promptAction.closeCustomDialog(customDialogId) 
        }) 
      Slider({ style: SliderStyle.InSet, value: sliderValue }) 
        .trackColor('rgba(40,40,40,0.5)') 
        .selectedColor('rgba(200,200,200,1)') 
        .trackThickness(66) 
        .blockStyle({ type: SliderBlockType.IMAGE, image: $r('app.media.arrow') }) 
        .onChange((value: number, mode: SliderChangeMode) => { 
          if(value == 100) { 
            promptAction.closeCustomDialog(customDialogId) 
          } 
        }) 
    } 
    .height(90) 
    .width('80%') 
  }.height(220).padding(5) 
} 
@Entry 
@Component 
struct Index { 
  @State message: string = '获取验证码' 
  build() { 
    Row() { 
      Column() { 
        Button(this.message) 
          .fontSize(50) 
          .padding(16) 
          .onClick(() => { 
            promptAction.openCustomDialog({ 
              builder: customDialogBuilder.bind(this) 
            }).then((dialogId: number) => { 
              customDialogId = dialogId 
            }) 
          }) 
      } 
      .width('100%') 
    } 
    .height('100%') 
  } 
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题