IONIC3验证码倒计时按钮实现

简介: verificationcode.gif通常在登陆注册或重置密码时,需要用到手机验证码,今天开源一个验证码倒计时的按钮实现。1.新建页面ionic g page forget 2.
img_784916b70c72309187aa3934de12f304.gif
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("两次密码输入不一致");
        }
    }
}

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

目录
相关文章
ionic3 导航栏返回按钮事件设置 多级页面返回到指定的页面
ionic3 导航栏返回按钮事件设置 多级页面返回到指定的页面
|
Android开发 JavaScript
Ionic2 下处理 Android 设备下返回按钮的事件
原文发表于我的技术博客 本文分享了 Ionic2 下处理 Android 设备下返回按钮的事件,供参考。原文发表于我的技术博客 代码中我分享了如何捕捉 Ionic2 项目在 Android 设备下返回按钮事件,并在捕捉到的事件中可以灵活根据需求编写相关业务逻辑,如退出、返回等。
1173 0
|
Android开发
ionic3项目实战教程 - 第13讲 ionic3社交分享(QQ分享和微信分享)
ionic3项目实战教程 - 第13讲 ionic3社交分享(QQ分享和微信分享) 图片发自简书App 这一讲主要包含以下几个部分: 1.在微信开放平台创建应用获得wechatappid; 2.
1404 0
|
Android开发 iOS开发
ionic3项目实战教程 - 第12讲 ionic3制作icon和splash
这一讲主要包含以下几个部分: 1.设计icon; 2.设计splash; 3.生成各个平台各个尺寸的icon和splash; 1.设计icon 来,打开你的PS,新建-文件,像素为1024*1024,背景透明,确定; .
1168 0
|
Web App开发
ionic3项目实战教程 - 第11讲 ionic3个人中心界面设计
ionic3项目实战教程 - 第11讲 ionic3个人中心界面设计 这一讲主要包含一下几个部分: 1.个人中心ts具体代码展示; 2.个人中心html具体代码展示; 3.
1365 0
ionic3项目实战教程 - 第10讲 ionic3分类菜单设计(类似外卖)
注意,干货来了,相比前面几讲这一讲就要难以消化多了,请做好心理准备。 因为在这之前,经常看到有群友在求这种分类菜单的组建,今天我就为大家再造一个轮子 [微笑脸]。
1086 0
|
Web App开发
ionic3项目实战教程 - 第8讲 ionic3商品详情页的实现
这一讲主要包含以下几个部分: 1.创建商品详情页 2.获取商品详情页的数据 3.展示商品详情页的数据 1.创建商品详情页 执行 ionic g page product-details 8-1.
1061 0
|
Web App开发
ionic3项目实战教程 - 第9讲 ionic3应用内主题浏览器ThemeableBrowser的使用
这一讲主要实现商品的"抢购"功能 1.安装ThemeableBrowser插件; 2.使用ThemeableBrowser插件; 1.安装插件 分别执行以下命令: ionic cordova plugin add cordova-plugin-t...
1435 0
ionic3项目实战教程 - 第7讲 ionic3商品列表页的实现
这一讲主要包含以下几个部分: 1.创建商品列表页 2.根据分类获取商品列表 2.展示商品列表 1.创建商品列表页 执行 ionic g page product-list 7-1.
870 0
ionic3项目实战教程 - 第5讲 ionic3商城首页透明导航栏设计
这一讲主要包含以下几个部分 1.配置APP主色调; 2.设置ion-content组建的fullscreen属性; 3.设计透明导航栏 配置APP主色调; 找到src/theme/variables.
1329 0