input框的ocr识别以及复制粘贴功能

<div class="inputBox" @touchstart="touchin()" @touchend="clickhandle()" @click="onlyClick">
	<input type="text">
	<div class="pasteBox" v-if="Loop==0" @click="pasteClick()">粘贴</div>
	<div 
         class="slot-dialog-content"
         @touchstart="copyStart('cardNum')"
         @touchend="copyEnd('cardNum')"
       >
         <p class="slot-dialog-content-p">复制卡号:&nbsp;&nbsp;{{ cardNumFilter }}</p>
         <!-- <p class="slot-dialog-content-p" v-if="cardType == '0'">CVV2:&nbsp;&nbsp;{{ yzm }}</p> -->
       </div>
<img @click.stop="$_photograph" slot="right" class="cameraImg" src="../assets/images/xiangji.png"/>
</div>
<script>
	// 拍照事件
    $_photograph(){
      //  调用ocr
      
        // 如果没有权限
        if(result.notAuthorized){
          // 关闭添加借记卡弹框
          this.dialogNoticeIs = false
          this.textInput = ''
          this.$refs.input0.isInputFocus = false
          this.close()
          // 展示提示弹框
          message: isIOS ? "请在手机'设置'-'隐私'-'相机'里打开权限" : "请在手机“设置”中打开“相机”权限",
        }else{
          this.textInput = this.$_trimValue(result.kCardNumber) || '';
        }
        console.log(JSON.stringify(result.kCardNumber)+"_______________________")
    },
    $_trimValue(value) {
      return value.replace(/\s/g, '')
    },
touchin(){ //  长按事件,按住后等待指定事件触发
      if(isAndroid){
        this.Loop = setTimeout( ()=> {
          this.Loop = 0;
          console.log("长按触发")
        }, 500);
        return false;
      }
    },
    clickhandle() { //  模拟点击事件(点击后迅速抬起)
      if(isAndroid){
        clearTimeout(this.Loop);
        if(this.Loop!==0){
          console.log("点击事件")
        }
        return false;
      }
    },
    // input点击事件
    onlyClick(){
      if(isIOS){
        if(this.$refs.input0.isInputFocus){
          if(!this.isFirst){
            this.Loop = 0;
          }
          this.isFirst = false;
        }
      }
    },
    // 粘贴按钮点击事件
    pasteClick(){
      console.log('粘贴')
      // 隐藏按钮
      this.Loop = 1;
      // 接受粘贴板内容
        const getPasteContent = result.result || '';

        // 用于判断是否包含数字
        const reg = /\d/;
        // 成立代表包含数字,否则toast提示输入内容非法
        if(reg.test(getPasteContent)){
          // 过滤粘贴内容只保留数字
          this.textInput = getPasteContent.replace(/[^\d]/g,"");
          
        }
    },
    copyStart(item) {
      clearTimeout(this.loop);
      this.loop = setTimeout(() => {
        // 去除空格
        const cardNumFormat = this.cardNumFilter.replace(/\s*/g, '');
        if (item === 'cardNum') {
          
        } 
        this.showToast('复制成功');
      }, 500);
    },
    copyEnd(item) {
      clearTimeout(this.loop);
    },
    showToast(content) {
     
    },
</script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值