鴻蒙行為驗(yàn)證碼

先上效果圖

Screenshot_2024-07-11T171321.png
Screenshot_2024-07-11T171404.png

實(shí)現(xiàn)

  • 1 代碼有刪減看思路吧
@CustomDialog
struct VFBlockDialog {
  controller?: CustomDialogController
  onResultsClick: (token: string,captchaVerification:string) => void=()=>{};
  @State positionX: number = 0
  @State value: number = 0
  @State seconds: number = 0.1
  @State timeTemp: number = 0
  @State type: number = 0 //默認(rèn)0  1 失敗  2成功
  @State isLoding: boolean = false
  @State captchaBean: CaptchaBean = Const.TabBars_DEFAULT_NEWS_TYPES;

  build() {
    Column() {
      Row() {
        Text('請完成安全驗(yàn)證')
        Image($r('app.media.vfet_delete')).width(20).height(20)
          .onClick(() => {
            if (this.controller != undefined) {
              this.controller.close()
            }
          })
      }
      .width("100%").padding({ top: 16, left: 16, right: 16 }).justifyContent(FlexAlign.SpaceBetween)

      Stack({ alignContent: Alignment.TopStart, }) {
        Image(this.captchaBean.originalImageUrl)
          .height(155)
          .borderRadius(10)
          .width('100%')

        Image(this.captchaBean.jigsawImageUrl)// 數(shù)據(jù)改變時,改變組件位置
          .height(155)
          .translate({ x: this.positionX, y: 0, z: 0 })
        Image($r('app.media.vficon_refresh')).width(30).height(30)
          .translate({ x: 280, y: 0, z: 0 })
          .onClick(() => {
            if(this.type==0){
              this.refresh()
            }
          })
        if (this.type!=0) {
          Column() {
            Image(this.type==1?$r('app.media.vfdrag_error'):$r('app.media.vfdrag_success')).width(32).height(32).margin({ top: 39 })
            Text(this.type==1?$r('app.string.vfblock_failed'):$r('app.string.vfblock_success')).fontSize(16).fontColor(this.type==1?0xFA5E59:0x51c024).margin({ top: 16 })
            if (this.type==1){
              Text(){
               Span($r('app.string.vf_pintu_error_tip')).fontSize(14).fontColor(0x333333)
               Span($r('app.string.correct')).fontSize(14).fontColor(0xFA5E59)
               Span($r('app.string.position')).fontSize(14).fontColor(0x333333)
              }.margin({ top: 4 })
            }else {
              Text(){
                Span($r('app.string.vfpinyu_success_tip')).fontSize(14).fontColor(0x333333)
                Span(this.seconds.toFixed(1)).fontSize(14).fontColor(0x51c024)
                Span($r('app.string.vfpinyu_success_seconds')).fontSize(14).fontColor(0x333333)
                Span(this.seconds>1?((99 - (this.seconds - 1) / 0.1))<1?'1':((99 - (this.seconds - 1) / 0.1)).toFixed(0):'99').fontSize(14).fontColor(0x51c024)
                Span($r('app.string.vfpinyu_success_user')).fontSize(14).fontColor(0x333333)
              }.margin({ top: 4 })
            }

          }.height(155).backgroundColor(0xbbFFFFFF)
          .width(310)
        }
        if (this.isLoding) {
          Progress({ value: 0, total: 100, type: ProgressType.Ring })
            .width(50).color(Color.Blue)
            .translate({ x: 130, y: 50, z: 0 })
            .style({ strokeWidth: 10, status: ProgressStatus.LOADING })
        }


      }
      .width('100%')
      .padding({
        top: 14,
        left: 16,
        bottom: 15,
        right: 16
      })
      .borderRadius(10)

      Stack({ alignContent: Alignment.Center, }) {

        Slider({
          style: SliderStyle.InSet,
          value: this.value,
          max: 310,
          min: 0
        })
          .width('100%')
          .enabled(this.type==0&&this.captchaBean.originalImageUrl!='')
          .padding({ left: 10, right: 10, bottom: 16 })
          .blockStyle({ type: SliderBlockType.IMAGE, image:this.type==0?$r('app.media.vfdrag_btn_n'):this.type==1?$r('app.media.vfdrag_btn_error'):$r('app.media.vfdrag_btn_success') })
          .trackBorderRadius(10)
          .trackThickness(40)
          .selectedColor(this.type==0?'#117BFF':this.type==1?'#FA5E59':'#65C93D')
          .blockSize({ width: 40, height: 40 })
          .onChange((value: number, mode: SliderChangeMode) => {
            this.value = value;
            this.positionX = (310 - 65) / 310 * value
            // console.info('value:' + value + 'positionX:' + this.positionX.toFixed(0)+"--->"+mode+"---"+SliderChangeMode.Begin);
            if (mode == SliderChangeMode.End) {
              this.seconds=((new Date().getTime()-this.timeTemp)/1000)
              console.info('seconds-->'+this.seconds+"--->"+this.timeTemp)
              this.checkAsync(this.positionX)
              // this.positionX = 0
              // this.value = 0;
            }else if (mode==SliderChangeMode.Begin){
                this.timeTemp=new Date().getTime();
            }
          })
        if (this.value == 0) {
          Text($r('app.string.vf_drag_tv_tip2')).height(40).padding({ bottom: 16 }).fontSize(16).fontColor(Color.Gray)
        }
      }
      .width('100%')

    }
  }
}
  • 2 代碼有刪減看思路吧
@CustomDialog
struct VFWordCaptchaDialog {
  controller?: CustomDialogController
  onResultsClick: (token: string,captchaVerification:string) => void=()=>{};
  @State type: number = 0 //默認(rèn)0  1 失敗  2成功
  @State isLoding: boolean = false
  @State captchaBean: CaptchaBean = Const.TabBars_DEFAULT_NEWS_TYPES;
  @State pointList: Point[] = [];
  build() {
    Column() {
      Row() {
        Text('請完成安全驗(yàn)證')
        Image($r('app.media.vfet_delete')).width(20).height(20)
          .onClick(() => {
            if (this.controller != undefined) {
              this.controller.close()
            }
          })
      }
      .width("100%").padding({ top: 16, left: 16, right: 16 }).justifyContent(FlexAlign.SpaceBetween)

      Stack({ alignContent: Alignment.TopStart, }) {
        Image(this.captchaBean.originalImageUrl)
          .height(155)
          .borderRadius(10)
          .width('100%')
          .onClick((event: ClickEvent) => {
            if (this.pointList.length<this.captchaBean.wordList.length){
              this.pointList.push(new Point(Math.round(event.x), Math.round(event.y)))
              console.log('點(diǎn)擊事件' + event.x + "----" + event.y)
              console.log('點(diǎn)擊事件' + JSON.stringify(this.pointList))
              if (this.pointList.length==this.captchaBean.wordList.length) {
                this.checkAsync()
              }
            }
          })
        if (this.pointList != null && this.pointList.length > 0) {
          ForEach(this.pointList, (item: Point, index: number) => {
            Stack({ alignContent: Alignment.Top, }){
              Text((index+1).toString()).fontColor(Color.White).fontSize(14).margin({top:5,right:2})
            }.width(34).height(34).backgroundImage($r('app.media.vfdot_bg')).translate({x:item.x-17,y:item.y-17,z:0})
          })
        }

        Image($r('app.media.vficon_refresh')).width(30).height(30)
          .translate({ x: 280, y: 0, z: 0 })
          .onClick(() => {
            this.refresh()
          })
        if (this.isLoding) {
          Progress({ value: 0, total: 100, type: ProgressType.Ring })
            .width(50).color(Color.Blue)
            .translate({ x: 130, y: 50, z: 0 })
            .style({ strokeWidth: 10, status: ProgressStatus.LOADING })
        }
      }
      .width('100%')
      .padding({
        top: 14,
        left: 16,
        bottom: 15,
        right: 16
      })
      .borderRadius(10)

      Stack() {
        Row({}) {
          if (this.type == 0) {
            Text($r('app.string.vfplease_click_next')).fontSize(14).fontColor(0x3B4147)
            Text(this.captchaBean.wordList.toString() + "】").fontSize(14).fontColor(0x3B4147)
          } else if (this.type == 1) {
            Image($r('app.media.vfword_res_error')).width(24).height(24)
            Text($r('app.string.vf_error')).fontSize(14).fontColor(Color.White).margin({ left: 10 })
          } else {
            Image($r('app.media.vfword_res_success')).width(24).height(24)
            Text($r('app.string.vf_success')).fontSize(14).fontColor(Color.White).margin({ left: 10 })
          }

        }
        .height(40)
        .borderRadius(10)
        .margin({
          top: 4,
          bottom: 16
        })
        .width('100%')
        .justifyContent(FlexAlign.Center)
        .backgroundColor((this.type == 0) ? 0xEBF0F5 : (this.type == 1) ? 0xFA5E59 : 0x65C93D)

      }.margin({ left: 16, right: 16 })
    }

  }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市祝辣,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌缴阎,老刑警劉巖,帶你破解...
    沈念sama閱讀 219,539評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件简软,死亡現(xiàn)場離奇詭異蛮拔,居然都是意外死亡述暂,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,594評論 3 396
  • 文/潘曉璐 我一進(jìn)店門语泽,熙熙樓的掌柜王于貴愁眉苦臉地迎上來贸典,“玉大人,你說我怎么就攤上這事踱卵±韧眨” “怎么了?”我有些...
    開封第一講書人閱讀 165,871評論 0 356
  • 文/不壞的土叔 我叫張陵惋砂,是天一觀的道長妒挎。 經(jīng)常有香客問我,道長西饵,這世上最難降的妖魔是什么酝掩? 我笑而不...
    開封第一講書人閱讀 58,963評論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮眷柔,結(jié)果婚禮上期虾,老公的妹妹穿的比我還像新娘。我一直安慰自己驯嘱,他們只是感情好镶苞,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,984評論 6 393
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著鞠评,像睡著了一般茂蚓。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上剃幌,一...
    開封第一講書人閱讀 51,763評論 1 307
  • 那天聋涨,我揣著相機(jī)與錄音,去河邊找鬼负乡。 笑死牍白,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的抖棘。 我是一名探鬼主播茂腥,決...
    沈念sama閱讀 40,468評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼钉答!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起杈抢,我...
    開封第一講書人閱讀 39,357評論 0 276
  • 序言:老撾萬榮一對情侶失蹤数尿,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后惶楼,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體右蹦,經(jīng)...
    沈念sama閱讀 45,850評論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡诊杆,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,002評論 3 338
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了何陆。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片晨汹。...
    茶點(diǎn)故事閱讀 40,144評論 1 351
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖贷盲,靈堂內(nèi)的尸體忽然破棺而出淘这,到底是詐尸還是另有隱情,我是刑警寧澤巩剖,帶...
    沈念sama閱讀 35,823評論 5 346
  • 正文 年R本政府宣布铝穷,位于F島的核電站,受9級特大地震影響佳魔,放射性物質(zhì)發(fā)生泄漏曙聂。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,483評論 3 331
  • 文/蒙蒙 一鞠鲜、第九天 我趴在偏房一處隱蔽的房頂上張望宁脊。 院中可真熱鬧,春花似錦贤姆、人聲如沸榆苞。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,026評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽语稠。三九已至,卻和暖如春弄砍,著一層夾襖步出監(jiān)牢的瞬間仙畦,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,150評論 1 272
  • 我被黑心中介騙來泰國打工音婶, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留慨畸,地道東北人。 一個月前我還...
    沈念sama閱讀 48,415評論 3 373
  • 正文 我出身青樓衣式,卻偏偏與公主長得像寸士,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子碴卧,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,092評論 2 355

推薦閱讀更多精彩內(nèi)容

  • 一弱卡、Markdown介紹 Markdown是一種輕量級標(biāo)記語言[https://baike.baidu.com/i...
    Julia111閱讀 463評論 0 0
  • 本文包含的Markdown語法有: 標(biāo)題 文字 粗斜體 劃線 腳注 段落 換行 分隔符 列表 區(qū)塊引用 代碼 鏈接...
    四冥閱讀 658評論 0 0
  • 一、為什么使用Markdown住册? 使用Markdown的契機(jī)在于自己建立的blog網(wǎng)站婶博,在發(fā)布博文是不可能只是發(fā)布...
    豬豬殺手呀閱讀 427評論 0 0
  • Markdown 是一種輕量級標(biāo)記語言 , 通過簡單的標(biāo)記語法荧飞,使文本內(nèi)容具有一定的格式 凡人。 一名党、段落 1. 標(biāo)題...
    youcans閱讀 661評論 0 0
  • MARKDOWN基本語法 引子 作為一名往計算機(jī)方向發(fā)展的學(xué)生,使用計算機(jī)學(xué)習(xí)是計算機(jī)類學(xué)生的常態(tài)挠轴,非常需要利用計...
    Snemc閱讀 5,407評論 0 1