ocr.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. const _my = require("../../__antmove/api/index.js")(my);
  2. const wx = _my;
  3. // pages/ocr/ocr.js
  4. const tip_en = require("../../international/ocr_scence/index");
  5. const app = getApp();
  6. const upload_image = require("../../utils/upload/upload_image");
  7. const {
  8. getPassportDetail
  9. } = require("../../utils/api/make_appointment");
  10. Page({
  11. /**
  12. * 页面的初始数据
  13. */
  14. data: {
  15. // 中英文
  16. isChinese: true,
  17. // 翻译包
  18. tip: tip_en,
  19. // 证件类型
  20. type_list: [{
  21. name_ch: "护照",
  22. name_en: "Click here",
  23. type: 13
  24. }
  25. // {name_ch: '往来港澳通行证', name_en: 'Hong Kong and Macao Travel Permit', type: 22},
  26. // {name_ch: '往来台湾通行证', name_en: 'Taiwan Travel Permit', type: 29},
  27. // {name_ch: '香港居民身份证', name_en: 'Hong Kong Identity Card', type: 1001},
  28. ],
  29. type_index: 0,
  30. type: 13
  31. },
  32. // 选择证件类型
  33. chooseType(e) {
  34. this.setData({
  35. type_index: e.detail.value,
  36. type: this.data.type_list[e.detail.value].type
  37. });
  38. },
  39. /**
  40. * 生命周期函数--监听页面加载
  41. */
  42. onLoad: function (options) {
  43. if (app.data.language == "ch") {
  44. this.setData({
  45. isChinese: true
  46. });
  47. } else {
  48. this.setData({
  49. isChinese: false
  50. });
  51. }
  52. // (过审专用,禁止删除)- start
  53. app.data.fake = false;
  54. // (过审专用,禁止删除)- end
  55. },
  56. // 护照验证
  57. doOCR() {
  58. var that = this;
  59. if (!this.data.type) {
  60. wx.showToast({
  61. title: this.data.isChinese ? "请选择证件类型~" : "Please select the id type~",
  62. icon: "none"
  63. });
  64. return;
  65. }
  66. wx.chooseImage({
  67. count: 1,
  68. sizeType: ["original", "compressed"],
  69. sourceType: ["album", "camera"],
  70. success(res) {
  71. var image = {
  72. url: res.tempFilePaths[0]
  73. };
  74. wx.showLoading({
  75. title: that.data.isChinese ? "上传中~" : "uploading..."
  76. });
  77. upload_image(image).then(img => {
  78. wx.hideLoading();
  79. var data = {
  80. passportUrl: img.url,
  81. type: that.data.type
  82. };
  83. wx.showLoading({
  84. title: that.data.isChinese ? "识别中..." : "recognizing.."
  85. });
  86. getPassportDetail(data).then(result => {
  87. if (result.code == 200) {
  88. wx.hideLoading();
  89. result.passportImage = img.url;
  90. let userInfo = {
  91. username: result.data.name,
  92. avatar: result.data.avatar,
  93. idNumber: result.data.passportCode,
  94. phone: app.data.phone
  95. };
  96. app.data.temporary_userInfo = userInfo;
  97. wx.showToast({
  98. title: that.data.isChinese ? "识别成功" : "recognize success"
  99. });
  100. wx.navigateTo({
  101. url: "/pages/faceCheck/faceCheck"
  102. });
  103. } else {
  104. wx.hideLoading();
  105. wx.showToast({
  106. title: res.msg
  107. });
  108. }
  109. }).catch(err => {
  110. wx.hideLoading();
  111. });
  112. }).catch(() => {
  113. wx.hideLoading();
  114. });
  115. }
  116. });
  117. },
  118. /**
  119. * 生命周期函数--监听页面初次渲染完成
  120. */
  121. onReady: function () {},
  122. /**
  123. * 生命周期函数--监听页面显示
  124. */
  125. onShow: function () {},
  126. /**
  127. * 生命周期函数--监听页面隐藏
  128. */
  129. onHide: function () {},
  130. /**
  131. * 生命周期函数--监听页面卸载
  132. */
  133. onUnload: function () {},
  134. /**
  135. * 页面相关事件处理函数--监听用户下拉动作
  136. */
  137. onPullDownRefresh: function () {},
  138. /**
  139. * 页面上拉触底事件的处理函数
  140. */
  141. onReachBottom: function () {},
  142. /**
  143. * 用户点击右上角分享
  144. */
  145. onShareAppMessage: function () {},
  146. antmoveAction: function () {
  147. //执行时动态赋值,请勿删除
  148. }
  149. });