faceRecognition.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. console.log(res)
  56. if (res.data.code == 0) {
  57. wx.showModal({
  58. showCancel: false,
  59. content: '比对成功',
  60. success(res) {
  61. if (res.confirm) {
  62. wx.switchTab({
  63. url: '/pages/index/index',
  64. })
  65. }
  66. }
  67. })
  68. }else{
  69. wx.showToast({
  70. title: '人脸识别失败',
  71. icon: 'none',
  72. duration: 2000,
  73. })
  74. }
  75. },
  76. complete:()=>{
  77. wx.hideLoading();
  78. }
  79. })
  80. },
  81. /**
  82. * 生命周期函数--监听页面加载
  83. */
  84. onLoad: function (options) {
  85. },
  86. /**
  87. * 生命周期函数--监听页面初次渲染完成
  88. */
  89. onReady: function () {
  90. },
  91. /**
  92. * 生命周期函数--监听页面显示
  93. */
  94. onShow: function () {
  95. },
  96. /**
  97. * 生命周期函数--监听页面隐藏
  98. */
  99. onHide: function () {
  100. },
  101. /**
  102. * 生命周期函数--监听页面卸载
  103. */
  104. onUnload: function () {
  105. },
  106. /**
  107. * 页面相关事件处理函数--监听用户下拉动作
  108. */
  109. onPullDownRefresh: function () {
  110. },
  111. /**
  112. * 页面上拉触底事件的处理函数
  113. */
  114. onReachBottom: function () {
  115. },
  116. /**
  117. * 用户点击右上角分享
  118. */
  119. onShareAppMessage: function () {
  120. }
  121. })