先看看效果
Html代碼
關閉 請輸入您的支付密碼
Css代碼
.payPass_box1{ font-size: 26rpx; color: #333; width: 640rpx; text-align: center; margin-top: 40rpx; height:400rpx; position: fixed; left: 50%; top: 30%; transform: translate(-50%,-50%); border: 2rpx #d1d1d1 solid; background: #fff; opacity: .9; } .payPass_box_t{ margin-top: 100rpx; } .payPass_box_m{ margin-top: 80rpx; width: 100%; display: flex; align-items: center; justify-content: center; position: relative; } .payPass_box_m_in{ display: flex; align-items: center; justify-content: center; position: relative; z-index: 10; } .payPass_box_m_in_in{ width: 70rpx; height: 70rpx; border:4rpx #bfbfbf solid; display: flex; justify-content: center; align-items: center; margin-right:8rpx; } .indexTopInput{ position: absolute; height: 100%; background: #000; opacity: 0.5; z-index: 2; left: 0rpx; background: red; left: -150%; } .indexTopInput input{ width: 100%; height: 100%; } .qiueBtn{ position: absolute; right: 20rpx; top: 10rpx; width: 80rpx; height: 60rpx; text-align: right; color: #999 }
組件的js代碼????? ??
// components/sixpass/sixpass.js var http = require('../../utils/http.js'); Component({ /** * 組件的屬性列表 */ properties: { }, /** * 組件的初始數據 */ data: { allinputF1:true, inputArr:[], inputStr:'', focusF:[], allinput:'', }, /** * 組件的方法列表 */ methods: { passInput(e){ var that = this; var value = e.detail.value; var num = e.detail.cursor-1; this.triggerEvent("passInput") var inputArr = []; for(let i=0;i=6){ that.setData({ inputSrr:value, inputArr:inputArr, allinput:value, }) console.log('密碼輸入完成 '+inputArr) }else{ that.setData({ inputSrr:value, inputArr:inputArr, allinput:'' }) } }, allInputBtn(e){ var that = this; var index = e.target.dataset.index; var focusF = http.forC(that.data.focusF); var inputArr = that.data.inputArr; var value = e.detail.value if(inputArr[index]){ inputArr[index] = ''; focusF[index] = '1'; }else{ inputArr[index] = value; focusF[index+1] = '1'; } that.setData({focusF:focusF,inputArr:inputArr}) }, // 點擊關閉密碼框 hideBox(){ this.setData({allinputF1:false}) }, show(){ this.setData({allinputF1:true}) }, focusInput(){ console.log(this.data.inputStr) this.setData({allinputF1:true}) }, } })
json代碼
{ "component": true, "usingComponents": {} }
在需要的地方引入組件
{ "usingComponents": { "sixpass": "/components/sixpass/sixpass" }, "navigationBarTitleText": "錢包-提現" }
這樣就是引入成功了
然后開始在頁面調用sixpass這個六位密碼的組件
頁面js的引用
// 1.6.3以上模板組件寫法 passInput(e){ console.log(this.sixpass.data.allinput); if(this.sixpass.data.allinput.length>=6){ console.log('已經完成'+this.sixpass.data.allinput) }else{ console.log('還差點 '+this.sixpass.data.allinput) } },
值得注意的是小程序1.6.3以上才支持模板的寫法,需要低版本兼容的這個就不好用了所以也可以用模板寫法來實現就是用的時候少寫一遍CSS與HTML
模板的HTML
關閉 請輸入您的支付密碼
模板的Css
/*密碼*/ .payPass_box1{ font-size: 26rpx; color: #333; width: 640rpx; text-align: center; margin-top: 40rpx; height:400rpx; position: fixed; left: 50%; top: 30%; transform: translate(-50%,-50%); border: 2rpx #d1d1d1 solid; background: #fff; opacity: .9; } .payPass_box_t{ margin-top: 100rpx; } .payPass_box_m{ margin-top: 80rpx; width: 100%; display: flex; align-items: center; justify-content: center; position: relative; } .payPass_box_m_in{ display: flex; align-items: center; justify-content: center; position: relative; z-index: 10; } .payPass_box_m_in_in{ width: 70rpx; height: 70rpx; border:4rpx #bfbfbf solid; display: flex; justify-content: center; align-items: center; margin-right:8rpx; } .indexTopInput{ position: absolute; height: 100%; background: #000; opacity: 0.5; z-index: 2; left: 0rpx; background: red; left: -150%; } .indexTopInput input{ width: 100%; height: 100%; } .qiueBtn{ position: absolute; right: 20rpx; top: 10rpx; width: 80rpx; height: 60rpx; text-align: right; color: #999 }
模板寫法的js
傳入data數據
passObj:{
? ? ? focusF:['1'] //第一個焦點獲取,
? ? ? inputArr:[]//六位密碼的數組,
? ? ? inputStr:""http://六位密碼,
? ? ? allinputF1:false//是否顯示當前的六位密碼框,
? ? },
下面的 JS思路寫法與組件一致就不在CTRL+C=>V了,各位大佬應該都看得懂。愛掏網 - it200.com
感謝各位有閑情看完此篇博客,不足之處還望指點~!
聲明:所有內容來自互聯網搜索結果,不保證100%準確性,僅供參考。如若本站內容侵犯了原著者的合法權益,可聯系我們進行處理。