vue实现键盘输入支付密码功能
2018-03-02 09:21
459 查看
支付密码功能界面如下图:
主要代码如下:
<template>
<div class="pay-tool">
<div class="pay-tool-title border-bottom">
<span class="icon icon-back" @click="backHandle"></span><strong>请输入交易密码</strong>
</div>
<div class="pay-tool-content">
<div class="pay-tool-inputs">
<div class="item" v-for="i in items"><span class="icon_dot" v-if="password[i]"></span></div>
</div>
<div class="pay-tool-link"><router-link class="link" to="/getP">忘记密码?</router-link></div>
</div>
<div class="pay-tool-keyboard">
<ul>
<li @click="keyUpHandle($event)" v-for="val in keys">
{{ val }}
</li>
<li class="del" @click="delHandle"><span class="icon-del"><</span></li>
</ul>
</div>
</div>
</template>
<script>
const keys = () => [1, 2, 3, 4, 5, 6, 7, 8, 9, '', 0]
// let sendFlag = true // 防止重复发送密码
export default {
data () {
return {
items: [0, 1, 2, 3, 4, 5],
keys: keys(),
password: []
}
},
methods: {
backHandle () {
this.clearPasswordHandle() // 返回时清除password
this.$emit('backFnc') // 返回上级
},
keyUpHandle (e) {
let text = e.currentTarget.innerText
let len = this.password.length
if (!text || len >= 6) return
this.password.push(text)
this.ajaxData()
},
delHandle () {
if (this.password.length <= 0) return false
this.password.shift()
},
ajaxData () {
if (this.password.length >= 6) {
console.log(parseInt(this.password.join(' ').replace(/\s/g, '')))
}
return false
},
clearPasswordHandle: function () {
this.password = []
}
}
}
</script>
<style lang="less" scoped>
.pay-tool {
position: relative;
height: 18.93333333rem;
background-color: #fff;
overflow: hidden;
&-title {
width: 100%;
height: 2.08888888rem;
padding: 0 0.8rem;
line-height: 2.08888888rem;
text-align: center;
overflow: hidden;
.icon {
float: left;
margin-top: 0.72222222rem;
}
strong {
font-size: 0.8rem;
}
}
&-content {
.pay-tool-inputs {
width: 14.46666666rem;
height: 2.31111111rem;
margin: 1.28888888rem auto 0;
border: 1px solid #b9b9b9;
border-radius: 0.26666666rem;
box-shadow: 0 0 1px #e6e6e6;
display: flex;
.item {
width: 16.66666666%;
height: 2.31111111rem;
border-right: 1px solid #b9b9b9;
line-height: 2.31111111rem;
text-align: center;
&:last-child {
border-right: none;
}
.icon_dot {
display: inline-block;
width: 0.51111111rem;
height: 0.51111111rem;
background: url("../../assets/images/icon_dot.png") no-repeat;
background-size: cover;
}
}
}
.pay-tool-link {
padding: 0.53333333rem 0.8rem 0;
text-align: right;
.link {
font-size: 0.66666666rem;
color: #3c8cfb;
}
}
}
.pay-tool-keyboard {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
ul {
width: 100%;
display: flex;
flex-wrap: wrap;
li {
width: 33.3333%;
height: 2.25442834rem;
line-height: 2.25442834rem;
text-align: center;
border-right: 1px solid #aeaeae;
border-bottom: 1px solid #aeaeae;
font-size: 0.8rem;
font-weight: bold;
&:nth-child(1), &:nth-child(2), &:nth-child(3) {
border-top: 1px solid #eee;
}
&:nth-child(3), &:nth-child(6), &:nth-child(9), &:nth-child(12) {
border-right: none;
}
&:nth-child(10), &:nth-child(11), &:nth-child(12) {
border-bottom: none;
}
&:nth-child(10), &:nth-child(12), &:active {
background-color: #d1d4dd;
}
&:nth-child(12):active {
background-color: #fff;
}
}
}
}
}
</style>
注意:页面使用rem布局,根html的font-size为45px。
主要代码如下:
<template>
<div class="pay-tool">
<div class="pay-tool-title border-bottom">
<span class="icon icon-back" @click="backHandle"></span><strong>请输入交易密码</strong>
</div>
<div class="pay-tool-content">
<div class="pay-tool-inputs">
<div class="item" v-for="i in items"><span class="icon_dot" v-if="password[i]"></span></div>
</div>
<div class="pay-tool-link"><router-link class="link" to="/getP">忘记密码?</router-link></div>
</div>
<div class="pay-tool-keyboard">
<ul>
<li @click="keyUpHandle($event)" v-for="val in keys">
{{ val }}
</li>
<li class="del" @click="delHandle"><span class="icon-del"><</span></li>
</ul>
</div>
</div>
</template>
<script>
const keys = () => [1, 2, 3, 4, 5, 6, 7, 8, 9, '', 0]
// let sendFlag = true // 防止重复发送密码
export default {
data () {
return {
items: [0, 1, 2, 3, 4, 5],
keys: keys(),
password: []
}
},
methods: {
backHandle () {
this.clearPasswordHandle() // 返回时清除password
this.$emit('backFnc') // 返回上级
},
keyUpHandle (e) {
let text = e.currentTarget.innerText
let len = this.password.length
if (!text || len >= 6) return
this.password.push(text)
this.ajaxData()
},
delHandle () {
if (this.password.length <= 0) return false
this.password.shift()
},
ajaxData () {
if (this.password.length >= 6) {
console.log(parseInt(this.password.join(' ').replace(/\s/g, '')))
}
return false
},
clearPasswordHandle: function () {
this.password = []
}
}
}
</script>
<style lang="less" scoped>
.pay-tool {
position: relative;
height: 18.93333333rem;
background-color: #fff;
overflow: hidden;
&-title {
width: 100%;
height: 2.08888888rem;
padding: 0 0.8rem;
line-height: 2.08888888rem;
text-align: center;
overflow: hidden;
.icon {
float: left;
margin-top: 0.72222222rem;
}
strong {
font-size: 0.8rem;
}
}
&-content {
.pay-tool-inputs {
width: 14.46666666rem;
height: 2.31111111rem;
margin: 1.28888888rem auto 0;
border: 1px solid #b9b9b9;
border-radius: 0.26666666rem;
box-shadow: 0 0 1px #e6e6e6;
display: flex;
.item {
width: 16.66666666%;
height: 2.31111111rem;
border-right: 1px solid #b9b9b9;
line-height: 2.31111111rem;
text-align: center;
&:last-child {
border-right: none;
}
.icon_dot {
display: inline-block;
width: 0.51111111rem;
height: 0.51111111rem;
background: url("../../assets/images/icon_dot.png") no-repeat;
background-size: cover;
}
}
}
.pay-tool-link {
padding: 0.53333333rem 0.8rem 0;
text-align: right;
.link {
font-size: 0.66666666rem;
color: #3c8cfb;
}
}
}
.pay-tool-keyboard {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
ul {
width: 100%;
display: flex;
flex-wrap: wrap;
li {
width: 33.3333%;
height: 2.25442834rem;
line-height: 2.25442834rem;
text-align: center;
border-right: 1px solid #aeaeae;
border-bottom: 1px solid #aeaeae;
font-size: 0.8rem;
font-weight: bold;
&:nth-child(1), &:nth-child(2), &:nth-child(3) {
border-top: 1px solid #eee;
}
&:nth-child(3), &:nth-child(6), &:nth-child(9), &:nth-child(12) {
border-right: none;
}
&:nth-child(10), &:nth-child(11), &:nth-child(12) {
border-bottom: none;
}
&:nth-child(10), &:nth-child(12), &:active {
background-color: #d1d4dd;
}
&:nth-child(12):active {
background-color: #fff;
}
}
}
}
}
</style>
注意:页面使用rem布局,根html的font-size为45px。
相关文章推荐
- vue实现键盘输入支付密码功能
- android 利用accessibilityservice 实现自动发红包功能 (让收红包的人手抽筋)(密码不能自动输入,可以开启指纹支付)
- oc,UITextFiled,怎么实现点击屏幕键盘自动隐藏和输入密码加密功能
- js仿支付宝填写支付密码效果实现多方框输入密码
- Android编程实现打勾显示输入密码功能
- 实现简单输入支付密码的输入
- java web 开发 如何实现 输入密码三次错误 后 锁定账户功能。
- vue实现密码显示隐藏切换功能
- C语言实现密码输入显示星号 VS2010 亲测通过 功能加强版
- Shell脚本中调用expect,实现自动输入密码的功能
- Android 钱包支付之输入支付密码的实现步骤
- jQuery实现手机上输入后隐藏键盘功能
- 1怎样让输入的text文本填写的部分只添加数字、2怎样将输入的数字一次性全部删除 3怎样选择密码 让它不显示 4 怎样实现在没有return的情况下点击button的情况下就能够使键盘页面下落5 怎样实现点击指定的button来对使指定的text进行键盘弹出 6怎样改变button按钮的状态
- 微信小程序6位或多位验证码密码输入框功能的实现代码
- vue项目实现表单登录页保存账号和密码到cookie功能
- vue 实现边输入边搜索功能的实例讲解
- vue 实现边输入边搜索功能
- Android模拟键盘输入功能的实现
- vue项目实现表单登录页保存账号和密码到cookie功能
- 用switch 语句实现简单的计算器功能(要求从键盘输入操作数和运算符)。 例如:输入: 3 * 4 输出:12