1.WXML页面

  1. <view>
  2. <!--<section class="mask" catchtap="canclePwd" wx:if="{{inputPwd}}"></section>-->
  3. <section class="pwd-modal" catchtap="getFocus" >
  4. <!-- <p class="close">X</p> -->
  5. <!--<p class="title">输入查看密码</p>-->
  6. <ul>
  7. <li><i class="circle" wx:if="{{password.length >= 1}}"></i></li>
  8. <li><i class="circle" wx:if="{{password.length >= 2}}"></i></li>
  9. <li><i class="circle" wx:if="{{password.length >= 3}}"></i></li>
  10. <li><i class="circle" wx:if="{{password.length >= 4}}"></i></li>
  11. <li><i class="circle" wx:if="{{password.length >= 5}}"></i></li>
  12. <li><i class="circle" wx:if="{{password.length >= 6}}"></i></li>
  13. </ul>
  14. <input ref="inputs" focus="{{isFocus}}" type="number" maxlength="6" bindinput="pwd" value="{{password}}"/>
  15. </section>
  16.  
  17. <view class="submit" bindtap="submit">确定</view>
  18. </view>

2.WXSS

  1. .mask {
  2. position: fixed;
  3. top: 0;
  4. left: 0;
  5. min-height: 100%;
  6. width: 100%;
  7. background: rgba(0, 0, 0, 0.5);
  8. z-index: 10;
  9. }
  10.  
  11. .pwd-modal {
  12. /*position: fixed;*/
  13. /*top: 258rpx;*/
  14. /*left: 54rpx;*/
  15. /*right: 54rpx;*/
  16. /*height: 504rpx;*/
  17. padding-top: 50rpx;
  18. background: white;
  19. z-index: 99;
  20. border-radius: 8rpx;
  21. text-align: center;
  22. }
  23.  
  24. ul {
  25. display: flex;
  26. margin: 94rpx 38rpx 104rpx;
  27. }
  28. .submit{
  29. position: fixed;
  30. bottom: 0;
  31. left: 0;
  32. right: 0;
  33. height:98rpx;
  34. background:rgba(253,49,49,1);
  35. box-shadow:0px -4px 6px 0px rgba(0,0,0,0.02);
  36. color: #FFFFFF;
  37. text-align: center;
  38. line-height: 98rpx;
  39. color: #FFFFFF;
  40. font-size: 34rpx;
  41. }
  42. ul li {
  43. width: 100%;
  44. height: 96rpx;
  45. line-height: 94rpx;
  46. border: 1rpx solid #ececeb;
  47. border-right: 0 none;
  48. box-sizing: border-box;
  49. text-align: center;
  50. font-size: 0;
  51. }
  52.  
  53. ul li:last-of-type {
  54. border-right: 1rpx solid #ececeb;
  55. }
  56.  
  57. ul li .circle {
  58. display: inline-block;
  59. vertical-align: middle;
  60. width: 50rpx;
  61. height: 50rpx;
  62. border-radius: 50%;
  63. background: black;
  64. }
  65.  
  66. input {
  67. text-indent: -9999rpx;
  68. margin-left: -9999rpx;
  69. opacity: 0;
  70. }

3.JS

  1. //index.js
  2. //获取应用实例
  3. const app = getApp()
  4.  
  5. Page({
  6. data: {
  7. password: '',
  8. isFocus: false,
  9. inputPwd: true,
  10. inputNum: 0,
  11. passwordFirst: '',
  12. passwordTwo: '',
  13. },
  14. pwd(e) {
  15. console.log(666)
  16. console.log(e.detail.value)
  17. console.log(666)
  18. let reg = /[^\d]/g
  19. let mobile = e.detail.value.replace(reg, '')
  20. this.setData({
  21. password: mobile
  22. })
  23. return mobile
  24. },
  25. getFocus() {
  26. this.setData({
  27. isFocus: true
  28. })
  29. },
  30. onLoad: function () {
  31. console.log(this.data.password.length)
  32. },
  33. submit(){
  34. let that = this
  35. if (that.data.password.length == 6) {
  36. if (that.data.inputNum == 0) {
  37. that.data.passwordFirst = that.data.password
  38. that.data.inputNum = 1
  39. wx.setNavigationBarTitle({
  40. title: '再次输入密码',
  41. })
  42. that.setData({
  43. password: '',
  44. isFocus: false,
  45. inputPwd: true,
  46. })
  47. } else if (that.data.inputNum == 1){
  48. that.data.passwordTwo = that.data.password
  49. if (that.data.passwordFirst == that.data.passwordTwo) {
  50. // 传that.data.passwordTwo为支付密码
  51. wx.showToast({
  52. title: '设置成功',
  53. icon: 'success',
  54. success: function (res) {
  55. wx.navigateBack({
  56. delta: 1
  57. })
  58. }
  59. })
  60.  
  61. } else {
  62. wx.showToast({
  63. title: '两次输入密码不同,请重新输入',
  64. icon: 'none',
  65. })
  66. wx.setNavigationBarTitle({
  67. title: '设置支付密码',
  68. })
  69. that.setData({
  70. password: '',
  71. isFocus: false,
  72. inputPwd: true,
  73. inputNum: 0,
  74. passwordFirst: '',
  75. passwordTwo: ''
  76. })
  77. return false
  78. }
  79. }
  80. }
  81. },
  82.  
  83. })

微信小程序 密码键盘 - 密码页面组件 (原生小程序代码)的更多相关文章

  1. 微信小程序富文本渲染组件html2wxml及html2wxml代码块格式化在ios下字体过大问题

    1.组件使用: 之前微信小程序的富文本渲染组件用的wxParse,对普通富文本确实可以,但是对于代码格式pre标签则无法使用. 下面这个html2wxml很不错,可以支持代码高亮. 详细文档:http ...

  2. 微信小程序开发 [02] 页面注册和基本组件

    1.页面注册 既然我们希望跳转到新的页面,那自然要新建页面相关的文件才行.在开篇已经讲过,一个小程序页面由四个文件组成,假如我们的页面名为welcome,那么这四个文件则是: welcome.js w ...

  3. 微信小程序 基本介绍及组件

    创建项目 微信开发工具深入介绍 https://developers.weixin.qq.com/miniprogram/dev/devtools/devtools.html 基本项目目录 1. 配置 ...

  4. 微信小程序自定义导航栏组件,完美适配所有手机,可实现各种功能和情况

    背景 在做小程序时,关于默认导航栏,我们遇到了以下的问题: Android.IOS 手机对于页面 title 的展示不一致,安卓 title 的显示不居中 页面的 title 只支持纯文本级别的样式控 ...

  5. 微信小程序开发—快速掌握组件及API的方法

    微信小程序框架为开发者提供了一系列的组件和API接口. 组件主要完成小程序的视图部分,例如文字.图片显示.API主要完成逻辑功能,例如网络请求.数据存储.音视频播放控制,以及微信开放的微信登录.微信支 ...

  6. 微信小程序开发—快速掌握组件及API的方法---转载

    微信小程序框架为开发者提供了一系列的组件和API接口. 组件主要完成小程序的视图部分,例如文字.图片显示.API主要完成逻辑功能,例如网络请求.数据存储.音视频播放控制,以及微信开放的微信登录.微信支 ...

  7. [小程序开发] 微信小程序audio音频播放组件+api_wx.createAudioContext

    引言: audio是微信小程序中的音频组件,可以轻松实现小程序中播放/停止音频等自定义动作. 附上微信小程序audio组件的相关属性说明:https://mp.weixin.qq.com/debug/ ...

  8. 微信小程序详解——页面之间的跳转方式【路由】和参数传递

    微信小程序拥有web网页和Application共同的特征,我们的页面都不是孤立存在的,而是通过和其他页面进行交互,来共同完成系统的功能.今天我们来研究小程序页面之间的跳转方式. 1.先导 在Andr ...

  9. 完整微信小程序授权登录页面教程

    完整微信小程序授权登录页面教程 1.前言 微信官方对getUserInfo接口做了修改,授权窗口无法直接弹出,而取而代之是需要创建一个button,将其open-type属性绑定getUseInfo方 ...

随机推荐

  1. JavaScript面向对象之get和set设置读写属性

    之前我们通过this和prototype申明的属性都是可读写的属性,如果想实现单独控制,就必须使用get和set存取期. 基本方法的 步骤一般包含两个步骤,1,使用var关键字定义一个私有属性作为中间 ...

  2. kickstart ---无人值守安装

    kickstart 实战 http://man.linuxde.net/download/CentOS_6_9镜像 安装: 关闭防火墙 且在编辑虚拟网络的vnet8中要取消使用本地dhcp项 1.yu ...

  3. Win10部署IIS 10.0

    win10自带IIS10.0 控制面板 >> 程序 >>启用或关闭Windows功能 勾选完之后会安装IIS,安装完成后 计算机管理 >> 服务和应用程序 > ...

  4. 浅谈Java中的关键字

    谈到final关键字,想必很多人都不陌生,在使用匿名内部类的时候可能会经常用到final关键字.另外,Java中的String类就是一个final类,那么今天我们就来了解final这个关键字的用法. ...

  5. docker+httpd的安装

    docker pull docker.io/httpd //直接这么运行会报“没有conf/httpd.cong这个文件” docker run -d --name httpd2. -p : -p : ...

  6. java框架之SpringCloud(6)-Zuul路由网关

    介绍 Zuul 包含了对请求的路由和过滤两个最重要的功能: 其中路由功能服务将外部请求转发到具体的微服务实例上,是实现外部访问统一入口的基础.而过滤的功能则负责对请求的处理过程进行干预,是实现请求校验 ...

  7. vue-cli 搭建的项目,无法用本地IP访问

    项目是用vue-cli搭建的,是基于移动端的,需要在手机上测试的时候发现用ip访问不了,用localhost是可以访问的,网上查资料的解决办法(此为Mac机子的解决办法): 在config文件里面的i ...

  8. VC++运行库 集32位/64位整合版

    运行程序时,win7/win10(x86和x64)常会遇到缺少什么缺少msvc***.dll问题 安装下面链接提供的程序,安装后,便可解决. [2016-10-10]Microsoft Visual ...

  9. C#中的装箱(inboxing)和拆箱(unboxing)(简单理解)

    装箱和拆箱是值类型和引用类型之间相互转换是要执行的操作.  装箱:将一个值类型隐式地转换成一个object类型,或把这个值类型转换成一个被该值类型应用的接口类型,把一个值类型的值装箱,就是创建一个ob ...

  10. configparser配置文件处理

    创建一个configparser格式的文档: import configparser config = configparser.ConfigParser()config["DEFAULT& ...