faceRecognition.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // pages/faceRecognition/faceRecognition.js
  2. const util = require('../../utils/util.js');
  3. Page({
  4. data: {
  5. photo: ''
  6. },
  7. uploadPhoto() {
  8. wx.showLoading({
  9. title: '上传中',
  10. })
  11. wx.chooseImage({
  12. count: 1,
  13. sizeType: ['compressed'],
  14. sourceType: ['camera'],
  15. success: (res) => {
  16. let tempFilePaths = res.tempFilePaths
  17. wx.uploadFile({
  18. url: util.globalData.publicUrl + '/sys/user/upload',
  19. filePath: tempFilePaths[0],
  20. name: 'uploadFile',
  21. formData: {
  22. "user": "test",
  23. },
  24. header: {
  25. appletsId: wx.getStorageSync('openId'),
  26. },
  27. success: (res) => {
  28. let datas = JSON.parse(res.data)
  29. this.setData({
  30. photo: datas.data
  31. })
  32. console.log(this.data.photo)
  33. }
  34. })
  35. },
  36. complete: (e) => {
  37. wx.hideLoading();
  38. }
  39. })
  40. },
  41. submit() {
  42. wx.showLoading({
  43. title: '上传中',
  44. })
  45. wx.request({
  46. url: util.globalData.publicUrl + '/user/userFaceComparison',
  47. method: "post",
  48. header: {
  49. appletsId: wx.getStorageSync('openId')
  50. },
  51. data: {
  52. photoPath: this.data.photo
  53. },
  54. success: (res) => {
  55. wx.hideLoading();
  56. console.log(res)
  57. if (res.data.code == 0) {
  58. wx.showModal({
  59. showCancel: false,
  60. content: '比对成功',
  61. success(res) {
  62. if (res.confirm) {
  63. wx.switchTab({
  64. url: '/pages/index/index',
  65. })
  66. }
  67. }
  68. })
  69. }else{
  70. wx.hideLoading();
  71. wx.showToast({
  72. title: '面部识别不通过,请重新上传',
  73. icon: 'none',
  74. duration: 2000,
  75. })
  76. }
  77. },
  78. // complete:()=>{
  79. // wx.hideLoading();
  80. // }
  81. })
  82. },
  83. /**
  84. * 生命周期函数--监听页面加载
  85. */
  86. onLoad: function (options) {
  87. },
  88. /**
  89. * 生命周期函数--监听页面初次渲染完成
  90. */
  91. onReady: function () {
  92. },
  93. /**
  94. * 生命周期函数--监听页面显示
  95. */
  96. onShow: function () {
  97. },
  98. /**
  99. * 生命周期函数--监听页面隐藏
  100. */
  101. onHide: function () {
  102. },
  103. /**
  104. * 生命周期函数--监听页面卸载
  105. */
  106. onUnload: function () {
  107. },
  108. /**
  109. * 页面相关事件处理函数--监听用户下拉动作
  110. */
  111. onPullDownRefresh: function () {
  112. },
  113. /**
  114. * 页面上拉触底事件的处理函数
  115. */
  116. onReachBottom: function () {
  117. },
  118. /**
  119. * 用户点击右上角分享
  120. */
  121. onShareAppMessage: function () {
  122. }
  123. })