IONIC3验证码倒计时按钮实现

作者: IonicBlog | 来源:发表于2017-10-23 21:51 被阅读1032次
verificationcode.gif

通常在登陆注册或重置密码时,需要用到手机验证码,今天开源一个验证码倒计时的按钮实现。

1.新建页面

ionic g page forget 

2.forget.html代码实现

<ion-header>
<ion-navbar color="secondary">
    <ion-title>找回密码</ion-title>
</ion-navbar>
</ion-header>
<ion-content fullscreen>
<ion-list no-lines>
    <ion-item style="background:none;" text-center>
    ![](assets/imgs/logo.jpg)
    <h3 style="color:white">积分系统</h3>
    </ion-item>
</ion-list>
<ion-grid class="xmf_form">
    <ion-row>
    <ion-item class="item_input">
        <ion-input type="number" [(ngModel)]="codeParam.usertel" placeholder="手机号"></ion-input>
        <button item-right ion-button round [disabled]="!verifyCode.disable" (click)="getCode()">{{verifyCode.verifyCodeTips}}</button>
    </ion-item>
    </ion-row>
    <ion-row>
    <ion-item class="item_input">
        <ion-input type="number" [(ngModel)]="params.vcode" placeholder="验证码"></ion-input>
    </ion-item>
    </ion-row>
    <ion-row>
    <ion-item class="item_input">
        <ion-input type="password" [(ngModel)]="params.newpass" placeholder="密码"> </ion-input>
    </ion-item>
    </ion-row>
    <ion-row>
    <ion-item class="item_input">
        <ion-input type="password" [(ngModel)]="params.sure_pwd" placeholder="确认密码"> </ion-input>
    </ion-item>
    </ion-row>
    <ion-row>
    <ion-col style="padding: 10px 20px 0px 20px;" text-center>
        <button ion-button full round (click)="doReset()"> 重置 </button>
    </ion-col>
    </ion-row>
    <ion-row>
    <ion-col tappable text-center>
        <!--忘记密码?-->
    </ion-col>
    </ion-row>
</ion-grid>
</ion-content>

3.forget.ts代码实现

    import { Component } from '@angular/core';
    import { NavController, NavParams } from 'ionic-angular';

    @Component({
    selector: 'page-forget',
    templateUrl: 'forget.html',
    })
    export class ForgetPage {

    params = {
        usertel: '',
        newpass: '',
        vcode: '',
        sure_pwd: ''
    }
    codeParam = {
        fromflag: 2,
        usertel: ""
    }
    constructor(public navCtrl: NavController, public navParams: NavParams) {
    }

    ionViewDidLoad() {
        console.log('ionViewDidLoad ForgetPage');
    }


    // 验证码倒计时
    verifyCode: any = {
        verifyCodeTips: "获取验证码",
        countdown: 60,
        disable: true
    }
    // 倒计时
    settime() {
        if (this.verifyCode.countdown == 1) {
        this.verifyCode.countdown = 60;
        this.verifyCode.verifyCodeTips = "获取验证码";
        this.verifyCode.disable = true;
        return;
        } else {
        this.verifyCode.countdown--;
        }

        this.verifyCode.verifyCodeTips = "重新获取(" + this.verifyCode.countdown + ")";
        setTimeout(() => {
        this.verifyCode.verifyCodeTips = "重新获取(" + this.verifyCode.countdown + ")";
        this.settime();
        }, 1000);
    }
    getCode() {
        if (this.codeParam.usertel == '') {
        console.debug("请填写手机号!");
        return;
        }

        //发送验证码成功后开始倒计时

        this.verifyCode.disable = false;
        this.settime();

    }
    doReset() {
        this.params.usertel = this.codeParam.usertel;

        if (this.params.usertel == "") {
        console.debug("请输入手机号");
        return;
        }

        if (this.params.vcode == "") {
        console.debug("请输入验证码");
        return;
        }

        if (this.params.newpass == this.params.sure_pwd) {

        } else {
        console.debug("两次密码输入不一致");
        }
    }
}

完!好了,请收藏点赞,谢谢!

相关文章

  • iOS 短信验证码倒计时按钮的实现

    验证码倒计时按钮的应用是非常普遍的,本文介绍了IOS实现验证码倒计时功能,点击获取验证码,进入时间倒计时,感兴趣的...

  • iOS 短信验证码倒计时按钮的实现

    个人博客: LiCheng的博客 引言: 验证码倒计时按钮的应用是非常普遍的,本文介绍了IOS实现验证码倒计时功能...

  • IONIC3验证码倒计时按钮实现

    通常在登陆注册或重置密码时,需要用到手机验证码,今天开源一个验证码倒计时的按钮实现。 1.新建页面 2.forge...

  • iOS 验证码倒计时

    /** 倒计时方法 在点击获取验证码按钮的方法里调用此方法即可实现, 需要在倒计时里修改按钮相关的请在此方法里yo...

  • iOS中倒计时按钮的实现

    我们经常会遇到按钮上进行倒计时的情况,比如获取验证码的时候。本文将讲解如何实现倒计时按钮。为了让大家清楚地知道本文...

  • swift 倒计时按钮设置

    获取验证码倒计时的按钮。 在你需要的时候调用: 这样就实现了你的获取验证码倒计时,不过还有一个最重要的问题:当你初...

  • 小程序如何实现验证码倒计时

    实现功能: 点击发送验证码,发送按钮进入倒计时状态。 具体实现: 要实现JS的倒计时功能,首先要了解两个JS的定...

  • RAC | RactiveCocoa/ReactiveObjC

    实现一个简单的验证码获取倒计时的功能 UIButton 私有变量 按钮事件监听和处理 开启定时器 设置按钮titl...

  • Android 用 RxBinding 与 RxJava2 实现

    场景:注册账号页面时,我们点击按钮发送验证码,在等待验证码时,界面会有倒计时提示,这此期间按钮不可点击。当倒计时结...

  • 封装按钮倒计时,一行代码实现后台也能倒计时

    封装按钮倒计时,一行代码实现后台也能倒计时 一般登录注册都会有发送验证码的功能,首先实现该功能,我们需要做什么? ...

网友评论

  • 2a21fb2e2e9e:膜拜大神
  • fe073be9761c:可以!很棒!
  • Renbq:你好 有项目源码地址吗?
    Renbq:@IonicBlog ok 好的:+1:
    IonicBlog:@Renbq 所有代码都在文章里了
  • 候鸟_ywh:为什么不单独把那个写成组件呢
  • 谁说需要十年:顺便问一下,如果APP里有一个相机拍照上传的功能,每次我只能打包后在手机上测试,然后弹框出来看做的对不对,有什么更好的办法吗,打断点之类的,或者可以在浏览器上调试的
    JanyQuan:chrome://inspect/#devices 这个可以在浏览器上打印出来结果
    IonicBlog:跨平台开发不同于原生开发,调用设备API最直接的办法就是真机调试。想看错误的话可以使用try-catch语法,并封装一个recordError的函数,放到catch里来记录error,并存储到缓存。然后做一个页面来读取并显示缓存里的异常数据,如果有需要,后期抽时间出一篇这方面的文章。
  • 谁说需要十年:桶哥出品,必属精品!:clap:
    IonicBlog:老铁双击666
  • poison771:文章呢

本文标题:IONIC3验证码倒计时按钮实现

本文链接:https://www.haomeiwen.com/subject/qrdzuxtx.html