小程序自定义数字键盘|仿微信支付、支付宝支付密码键盘

简介:

微信小程序自定义键盘插件wcKeyboard|仿微信数字软键盘|仿支付宝自定义数字键盘|小程序自定义模拟系统键盘

36e544fbd14022b6fe3bc5ce59a13c1e8e3af05e

前段时间有开发过一个html5仿支付宝、微信支付数字键盘,在某些情况下自定义数字键盘应用还是蛮多的,比如 购物商城系统 零钱付款 ,会员卡支付,恰好微信小程序没有内部数字键盘组件,这样输入密码就需要自己做一个自定义软键盘了。于是就在之前插件的基础上试着开发出了这个小程序wcKeyboard数字键盘插件。

17e2422604cfc57ba78c60e7d63ad40aaea04390

551f59efcb4db226fa8d8d6db107f974e48aecbd 99d92e1e49dde6ded25576672fdde039079c57e3

85a58590eb6b6d0d6832d4f6e60c3ea71d8d1e12 3055a8719f4e18816d1298ef1e95fa8f13bbce5b

d228ca7cf2b905a18effa0f2349aac837440d315 71a6ec0da8161a18f3cfbaa0e5da61d69ba2dd7d

989d89e2c44f0b46867bf57ced8add9b92d9da7f 0668062c226d647dfe26368796c16b494054a2fc


init: function () {
console.log('初始化');

var that = this, opt = that.opts;
// 处理传参
__this.setData({
  __options: {
	isCloseCls: null,
	__idx: __idx,
	isShowPopup: true,

	//中间值
	kbVal: '', //设置调试默认值
	err: false, //键盘错误信息提示

	debug: opt.debug,

	id: opt.id,
	type: opt.type,
	len: opt.len,
	complete: opt.complete,
	max: opt.max,
	style: opt.style,
	skin: opt.skin,
	ok: opt.ok,
	oninput: opt.oninput,

	shade: opt.shade,
	shadeClose: opt.shadeClose,
	opacity: opt.opacity,

	anim: opt.anim
  }
});

opt.show && opt.show.call(this);
this.__idx = __idx++;
that.callback();
},
callback: function () {
console.log('事件处理');

var that = this, opt = that.opts;
// 清除上一个timer
clearTimeout(util.timer[that.__idx - 1]);
delete util.timer[that.__idx - 1];

// 错误提示
function chkErr(cls, str){
  __this.setData({ '__options.err': [cls, str] });
  setTimeout(function(){
	__this.setData({ '__options.err': false });
  }, 2500);
}
// 键盘值检测
function chkVal(text){
  if (text.indexOf('.') != -1 && text.substring(text.indexOf('.') + 1, text.length).length == 3) {
	return;
  }
  if (text == '0') {
	return;
  }
  // 输入最大值限制
  if (opt.max) {
	if (parseInt(text) >= opt.max && text.indexOf('.') == -1) {
	  chkErr("error", "最大限制值:" + opt.max.toFixed(2));
	  return;
	}
  }
  // 输入手机号码判断
  if (opt.type && opt.type == 'tel') {
	var tel = text, _len = parseInt(tel.length), reg = /^0?1[3|4|5|8|7][0-9]\d{8}$/;
	if (_len > 11) return;

	if (_len == 11) {
	  if (!reg.test(tel)) {
		chkErr("error", "手机号码格式有误!");
	  } else {
		chkErr("success", "验证通过!");
	  }
	  typeof opt.complete == "function" && opt.complete.call(this, text);
	}
  }
  // 输入密码长度判断
  if (opt.type && opt.type == 'pwd') {
	var _len = parseInt(text.length);
	if (_len > opt.len) return;
	if (_len == opt.len) {
	  typeof opt.complete == "function" && opt.complete.call(this, text);
	}
  }
  return true;
}
// 键盘值输出
function setVal(text){
  __this.setData({ '__options.kbVal': text });

  typeof opt.oninput == "function" && opt.oninput.call(this, text);
}
// 处理数字1-9
__this.tapNum = function(e){
  var kbval = this.data.__options.kbVal, text = e.currentTarget.dataset.text;
  var val = kbval + text;
  if (!chkVal(val)) return;

  setVal(val);
}

// 处理小数点
__this.tapFloat = function(e){
  var kbval = this.data.__options.kbVal, text = e.currentTarget.dataset.text;
  if(kbval == '' || kbval.indexOf('.') != -1){
	return;
  }
  var val = kbval + text;
  setVal(val);
}

// 处理数字0
__this.tapZero = function(e){
  var kbval = this.data.__options.kbVal, text = e.currentTarget.dataset.text;
  var val = kbval + text;
  if (!chkVal(val)) return;

  setVal(val);
}

// 处理删除
__this.tapDel = function(e){
  var val = this.data.__options.kbVal.substring(0, this.data.__options.kbVal.length - 1);
  setVal(val);
}

// 处理确定按钮事件
__this.tapSure = function(e){
  var kbval = this.data.__options.kbVal;
  typeof opt.ok == "function" && opt.ok.call(this, kbval);
}


/*
  ---------------------------------------
*/
// 点击遮罩层关闭
__this.shadeTaped = function (e) {
  if (!opt.shadeClose) return;
  exportAPI.close(that.__idx);
}
// 点击键盘xclose按钮关闭
__this.xcloseTaped = function(e){
  exportAPI.close(that.__idx);
}
// 处理销毁函数
opt.end && (util.end[that.__idx] = opt.end);

}

<!-- //支付宝键盘布局 -->
<view class="ul">
	<view class="li kb-limit nbor {{err[0]}}">{{err[1]}}</view>
	<view class="li kb-pwd nbor" wx:if="{{type&&type=='pwd'}}"><view class="keyboard__panel-pwd"><label class="kb-pwdlbl" wx:for="{{len}}" wx:key="index"><input type="password" maxlength="1" value="{{kbVal[index]}}" disabled /></label></view></view>
	<view class="li kb-result nbor" style="display:{{debug ? 'block' : 'none'}};">{{kbVal}}</view>

	<view class="kb-flexbox flexbox">
	  <view class="kb-one flex1">
		<view class="li kb-number nbor" data-text="1" bind:tap="tapNum">1</view>
		<view class="li kb-number" data-text="2" bind:tap="tapNum">2</view>
		<view class="li kb-number" data-text="3" bind:tap="tapNum">3</view>
		<view class="li kb-number nbor" data-text="4" bind:tap="tapNum">4</view>
		<view class="li kb-number" data-text="5" bind:tap="tapNum">5</view>
		<view class="li kb-number" data-text="6" bind:tap="tapNum">6</view>
		<view class="li kb-number nbor" data-text="7" bind:tap="tapNum">7</view>
		<view class="li kb-number" data-text="8" bind:tap="tapNum">8</view>
		<view class="li kb-number" data-text="9" bind:tap="tapNum">9</view>
		<view class="li kb-float nbor {{type=='tel' || type=='pwd' ? 'disabled' : ''}}" data-text="." bind:tap="tapFloat">.</view>
		<view class="li kb-zero" data-text="0" bind:tap="tapZero">0</view>
		<view class="li kb-xclose" bind:touchstart="xcloseTaped"><image src="/utils/component/wcKeyboard/img/icon__kb-xclose2.png" mode="aspectFit"></image></view>
	  </view>
	  <view class="kb-two">
		<view class="li kb-del" bind:tap="tapDel"><image src="/utils/component/wcKeyboard/img/icon__kb-del.png" mode="aspectFit"></image></view>
		<view class="li kb-sure" bind:tap="tapSure">确定</view>
	  </view>
	</view>
</view>



目录
相关文章
|
4天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的校园水电费管理微信小程序的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的校园水电费管理微信小程序的详细设计和实现
25 0
|
16天前
|
小程序
微信小程序如何实现进入小程序自动连WiFi功能
微信小程序如何实现进入小程序自动连WiFi功能
|
1月前
|
JSON 小程序 数据格式
【微信小程序】-- 自定义组件总结 (四十)
【微信小程序】-- 自定义组件总结 (四十)
|
1月前
|
小程序 JavaScript
【微信小程序】-- 自定义组件 - behaviors(三十九)
【微信小程序】-- 自定义组件 - behaviors(三十九)
|
15天前
|
小程序 JavaScript
【微信小程序】之自定义三宫格一行展示row-grid(简单数据看板)
【微信小程序】之自定义三宫格一行展示row-grid(简单数据看板)
|
4天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的优购电商小程序的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的优购电商小程序的详细设计和实现
23 0
|
4天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的微信课堂助手小程序的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的微信课堂助手小程序的详细设计和实现
28 3
|
4天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的微信阅读网站小程序的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的微信阅读网站小程序的详细设计和实现
24 2
|
4天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的健身管理系统及会员微信小程序的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的健身管理系统及会员微信小程序的详细设计和实现
22 0
|
4天前
|
小程序 JavaScript Java
基于SpringBoot+Vue+uniapp微信小程序的旅游出行必备商城小程序的详细设计和实现
基于SpringBoot+Vue+uniapp微信小程序的旅游出行必备商城小程序的详细设计和实现
27 0

热门文章

最新文章