2020/9/27 0:00:00
泉源:不详
作者:未知
微信小程序在开发微信支付功效时,,,若是需要实现输入支付密码,,,应该要怎样解决,,,下面为各人整理了微信小程序实现输入支付密码demo

微信小程序开发实现微信支付密码的输入,,,要解决:
1、小程序要想唤起键盘,,,必需要借助input控件。。。。。。通过input控件和其属性focus来唤起和隐藏输入键盘。。。。。。
2、要让input控件不可见。。。。。。让光标和输入的字符都不可见,,,这里是把input控件定位到左边不可见规模。。。。。。
实现demo代码:

1、页面代码
-
<view catchtap='showInputLayer' class="btn_pay">连忙支付</view>
-
<!-- 密码输入框 -->
-
<view wx:if='{{showPayPwdInput}}'>
-
<view class='bg_layer'></view>
-
<view class='input_main'>
-
<view class='input_title'>
-
<view class='input_back' catchtap='hidePayLayer'><text></text></view>
-
<text>输入支付密码</text>
-
</view>
-
<view class='input_tip'><text>使用会员卡余额支付需要验证身份,,,验证通事后才可举行支付。。。。。。</text></view>
-
<view class='input_row' catchtap='getFocus'>
-
<view class='pwd_item' wx:for='{{6}}' wx:key='item' wx:for-index='i'>
-
<text wx:if='{{pwdVal.length>i}}'></text>
-
</view>
-
</view>
-
<view class='forget_pwd' catchtap='hidePayLayer'>遗忘密码</view>
-
<input class='input_control' password type='number' focus='{{payFocus}}' bindinput='inputPwd' maxlength='6'/>
-
</view>
-
</view>
2、js代码
-
//index.js
-
//获取应用实例
-
const app = getApp()
-
-
Page({
-
data: {
-
showPayPwdInput: false, //是否展示密码输入层
-
pwdVal: '', //输入的密码
-
payFocus: true, //文本框焦点
-
},
-
onLoad: function () {
-
this.showInputLayer();
-
},
-
/**
-
* 显示支付密码输入层
-
*/
-
showInputLayer: function(){
-
this.setData({ showPayPwdInput: true, payFocus: true });
-
},
-
/**
-
* 隐藏支付密码输入层
-
*/
-
hidePayLayer: function(){
-
-
var val = this.data.pwdVal;
-
-
this.setData({ showPayPwdInput: false, payFocus: false, pwdVal: '' }, function(){
-
wx.showToast({
-
title: val,
-
})
-
});
-
-
},
-
/**
-
* 获取焦点
-
*/
-
getFocus: function(){
-
this.setData({ payFocus: true });
-
},
-
/**
-
* 输入密码监听
-
*/
-
inputPwd: function(e){
-
this.setData({ pwdVal: e.detail.value });
-
-
if (e.detail.value.length >= 6){
-
this.hidePayLayer();
-
}
-
}
-
})
3、样式
-
.btn_pay{
-
margin: 100rpx auto; width: 600rpx; height: 100rpx; line-height: 100rpx; border-radius: 100rpx;
-
background-color: #d3a95a; color: #fff; font-size: 36rpx; text-align: center;
-
}
-
/* 支付密码css start */
-
.bg_layer{
-
position: fixed; left: 0; top: 0; bottom: 0; right: 0;
-
background-color: rgba(0, 0, 0, 0.6); z-index: 9998;
-
}
-
.input_main{
-
position: fixed; left: 0; bottom: 500rpx; width: 100%; height: 394rpx;
-
background-color: #fff; z-index: 9999;
-
}
-
.input_title{
-
width: 100%; height: 90rpx; line-height: 90rpx; text-align: center;
-
font-size: 32rpx; border-bottom: 1rpx solid #e2e2e2;
-
}
-
.input_back{
-
position: absolute; left: 0; top: 0;
-
width: 80rpx; height: 90rpx; display: flex; justify-content: center; align-items: center;
-
}
-
.input_back text{
-
width: 20rpx;
-
height: 20rpx;
-
background-color: white;
-
border: 1rpx solid #aaa;
-
border-width: 5rpx 0 0 5rpx;
-
transform: rotate(-45deg);
-
}
-
-
.input_tip{ margin: 30rpx; font-size: 24rpx; color: #888; }
-
-
/* 密码掩码模拟 */
-
.input_row{
-
width: 690rpx; margin: 0 auto; height: 98rpx; position: relative;
-
display: flex; align-items: center; border: 1rpx solid #e2e2e2; border-radius: 20rpx;
-
}
-
.input_row .pwd_item{
-
flex: 1; display: flex; align-items: center; justify-content: center;
-
height: 100%; border-right: 1rpx solid #e2e2e2; position: relative;
-
}
-
.pwd_item:nth-last-of-type(1) { border-right: 0; }
-
.pwd_item text {
-
width: 30rpx; height: 30rpx; border-radius: 30rpx; background-color: #555;
-
}
-
-
-
.forget_pwd{
-
float: right; margin: 30rpx; width: 100rpx; text-align: right; font-size: 24rpx; color: #ff7800;
-
}
-
-
/* 文本输入框位置: 设置到左边隐藏 */
-
.input_control {
-
position: relative; left: -300rpx; bottom: 0; width: 100rpx; height: 100rpx;
-
}
小程序工具提供多类型商城/门店小程序制作,,,可视化编辑 1秒天生5步上线。。。。。。通过拖拽、拼接??榻峁剐〕绦蛏坛且趁妫,,所看即所得,,,只需要美工就能做出细腻商城。。。。。。更多小程序请审查:小程序市肆
【本站声明】
1、本站文章中所选用的图片及文字泉源于网络以及用户投稿,,,由于未联系到知识产权人或未发明有关知识产权的挂号,,,若有知识产权人并不肯意我们使用,,,若是有侵权请连忙联系。。。。。。
2、本网站差池文章中所涉及的内容真实性、准确性、可靠性认真,,,仅系客观性形貌,,,如您需要相识该类商品/服务详细的资讯,,,请您直接与该类商品/服务的提供者联系。。。。。。
KESION pp电子软件
KESION pp电子软件是海内领先的在线教育软件及私域社交电商软件服务提供商,,,恒久专注于为企业提供在线教育软件及社交电商SaaS平台解决方案。。。。。。
公司焦点产品云开店SaaS社交电商服务平台、在线教育SaaS服务平台、教育企业数字化SaaS云平台、企微营销助手、私有化自力安排品牌网校和在线教育咨询等。。。。。。KESION 一直通过手艺立异,,,提供产品和服务,,,助力企业向数字化转型,,,通过科技驱动商业刷新,,,让商业变得更智慧!