当前位置: 首页 > article >正文

身份证阅读器API模式 VUE Dorado7

VUE 新框架

// 身份证扫描
readIdCard(type) {
  // 1.连接
  axios.get('http://localhost:19196/openDevice').then(res => {
    if (res.data.resultFlag === 0) {
      // 2.读卡
      axios.get('http://localhost:19196/readCard').then((res) => {
        if (res.data.resultFlag === 0) {
          // this.$message.success('读卡成功')
          // 信息处理
          this.form.name = res.data.partyName
          this.form.idCard = res.data.certNumber
          this.form.nationality = res.data.nation
          this.form.birthday = res.data.bornDay
          this.form.sex = res.data.gender === '男' ? 1 : res.data.gender === '女' ? 2 : 0
          this.form.expDate = res.data.expDate
          this.form.residence = res.data.certOrg
          this.form.addr = res.data.certAddress
          this.form.photo = 'data:image/jpeg;base64,' + res.data.identityPic

          // 签到打卡
          if (type === 'in') {
            this.loading = true
            trainClassApi.signIn({ idCard: this.form.idCard }).then(res => {
              this.loading = false
              if (res.code !== 200) {
                this.$message.error(res.msg)
                return
              }
              this.$message.success(res.msg)
              this.getByPage()
            }).catch(() => {
              this.loading = false
            })
          } else if (type === 'off') { // 签退打卡
            this.loading = true
            trainClassApi.signOff({ idCard: this.form.idCard }).then(res => {
              this.loading = false
              if (res.code !== 200) {
                this.$message.error(res.msg)
                return
              }
              this.$message.success(res.msg)
              this.getByPage()
            }).catch(() => {
              this.loading = false
            })
          }

          // 3.断开
          axios.get('http://localhost:19196/CloseDevice').then(res => {
            /* if (res.data.resultFlag !== 0) {
              this.$alert('断开失败', '提示', { type: 'error' })
            } */
          })
        } else {
          this.$alert('读卡失败', '提示', { type: 'error' })
        }
      })
    } else {
      this.$alert('连接失败', '提示', { type: 'error' })
    }
  })
},

Dorado7 新版身份证阅读器API模式

/**
 * 身份证阅读器(API模式)【注意:需使用https模式才行 否者会被跨域拦截】
 * like12 add,20240913
 */
// @Bind #idCardApiBtn.onClick
!function(self, employeeForm, employeeDataSet){
	// 1.连接
	var xhr = new XMLHttpRequest();
	xhr.open('GET', 'http://127.0.0.1:19196/OpenDevice', true);
	// xhr.withCredentials = true; // 如果需要的话
	xhr.onreadystatechange = function() {
	    if (xhr.readyState === 4 && xhr.status === 200) {
	    	var resData = JSON.parse(xhr.responseText);
	        // console.log(resData);
	        if(resData.resultFlag == 0){
	        	// 2.读卡
	        	xhr.open('GET', 'http://127.0.0.1:19196/readCard', true);
	        	xhr.onreadystatechange = function() {
	        	    if (xhr.readyState === 4 && xhr.status === 200) {
	        	    	var resData = JSON.parse(xhr.responseText);
	        	        // console.log(resData);
	        	        if(resData.resultFlag == 0){
	        	        	// 信息处理
	        	            var name = resData.partyName;
	        	            var idCard = resData.certNumber;
	        	            var nationality = resData.nation;
	        	            var birthday = resData.bornDay;
	        	            var sex = resData.gender === '男' ? 1 : resData.gender === '女' ? 0 : 2; // 本系统为1男0女2未知
	        	            /*var expDate = resData.expDate;
	        	            var residence = resData.certOrg;*/
	        	            var addr = resData.certAddress;
	        	            var photo = resData.identityPic;
	        	            // var photo = 'data:image/jpeg;base64,' + resData.identityPic;
	        	            /*console.log(name);
	        	            console.log(idCard);
	        	            console.log(nationality);
	        	            console.log(birthday);
	        	            console.log(sex);
	        	            console.log(expDate);
	        	            console.log(residence);
	        	            console.log(addr);
	        	            // console.log(photo);*/
	        	            
	        	            // 出生日期格式转换
	        	    		var birthdayStr = birthday.substr(0, 4) + '-' + birthday.substr(4, 2) + '-' + birthday.substr(6, 2);

	        	    		// 赋值
	        	    		employeeDataSet.getData("#").set('employeeName', name);
	        	    		employeeDataSet.getData("#").set('employeeSex', sex);
	        	    		employeeDataSet.getData("#").set('idCard', idCard);
	        	    		employeeDataSet.getData("#").set('employeeBirthday', birthdayStr);
	        	    		employeeDataSet.getData("#").set('nationality', nationality);
	        	    		employeeDataSet.getData("#").set('registeredResidence', addr);
	        	    		
	        	    		// 保存图片
	        	    		var saveAction = view.get("#saveIdCardPhotoAction");
	        	    		saveAction.set("parameter", {
	        	    			"photo": photo,
	        	    			"idCard": idCard
	        	    		});
	        	    		saveAction.execute(function(returnVal){
	        	    			if(returnVal.indexOf(".jpg") != -1){
	        	    				// 保存图片地址
	        	    				employeeDataSet.getData("#").set('employeePhoto', returnVal);
	        	    				employeeForm.refreshData();
	        	    				// 显示照片
	        	    				view.set('#photoContainer.content', getImage(returnVal));
	        	    			}
	        	    		});
	        	        	
	        	        	// 3.断开
	        	        	xhr.open('GET', 'http://127.0.0.1:19196/CloseDevice', true);
	        	        	xhr.onreadystatechange = function() {};
	        	        	xhr.send();
	        	        }
	        	    }
	        	};
	        	xhr.send();
	        }
	    }
	};
	xhr.send();
};


http://www.kler.cn/news/309862.html

相关文章:

  • 计数服务怎么设计?
  • 【AI学习】AI绘画发展简史
  • nginx进阶篇(二)
  • C++ 常用设计模式
  • 【.net core】线程的创建和方法调用
  • LineageOS源码下载和编译(Xiaomi Mi 6X,wayne)
  • linux Command
  • HT3163 免电感滤波25W AB/D类音频功放
  • 图数据库 neo4j 安装
  • RocketMQ实战与集群架构详解
  • C# 在WPF中实现图表生成
  • 大数据时代下会计数字化的思考与建议
  • 实战04-http请求
  • flutter集成百度地图定位 ‘BMKLocationManager.h‘ file not found报错
  • 消防指挥中心控制台:守护安全的关键枢纽
  • TCP/IP协议概述
  • 【乐吾乐大屏可视化组态编辑器】使用手册
  • Android 用线程池实现一个简单的任务队列(Kotlin)
  • 红队打点的思路与信息收集
  • android.view.InflateException: Binary XML file line #7: Error inflating class
  • xilinx vivado PULLMODE 设置思路
  • linux 使用SSH密钥配置免密登录
  • 我要走遍三山五岳之---嵩山
  • 问题:WINCC 7.5 结构变量只能是内部变量吗?
  • linux 获取指定端口的PID netsat awk
  • 构建未来教育:智慧校园的功能与特色
  • MacOS安装MAT教程
  • 经典sql题(一)求连续登录不少于三天用户
  • Android 源码多个Launcher设置默认Launcher
  • 栈和队列OJ题C语言版