邃芒智像相册
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

205 lines
4.0 KiB

  1. const app = getApp()
  2. import request from '../../utils/request'
  3. import Dialog from '@vant/weapp/dialog/dialog';
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. topTitle: "请添加一张正面照片",
  10. showScanLine: false,
  11. isUploaded: false,
  12. isSuccess: false,
  13. tempFilePath: "",
  14. onlineFilePath: "",
  15. id: ""
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad(options) {
  21. if (options.id) {
  22. this.setData({
  23. id: options.id
  24. })
  25. }
  26. },
  27. /**
  28. * 生命周期函数--监听页面显示
  29. */
  30. onShow() {
  31. app.tokenCallBack = res => {
  32. this.setData({
  33. isLogin: res
  34. })
  35. }
  36. },
  37. chooseImage(e) {
  38. const that = this
  39. wx.chooseMedia({
  40. mediaType: ['image'],
  41. sourceType: ['camera'],
  42. camera: 'back',
  43. success: res => {
  44. that.setData({
  45. tempFilePath: res.tempFiles[0].tempFilePath,
  46. showScanLine: true,
  47. isUploaded: true,
  48. isSuccess: false
  49. })
  50. that.imgCheckByFace()
  51. }
  52. })
  53. },
  54. // 检查图片是否符合人脸规范
  55. imgCheckByFace() {
  56. const that = this
  57. const filePath = that.data.tempFilePath
  58. const BaseUrl = request.baseUrl
  59. wx.uploadFile({
  60. filePath,
  61. url: BaseUrl + "/api/userDigital/checkPhoto",
  62. name: 'file',
  63. formData: {
  64. user: "test",
  65. },
  66. success: res => {
  67. const code = JSON.parse(res.data).code
  68. if (code == 200) {
  69. that.imgCheckByBaidu()
  70. } else {
  71. that.setData({
  72. showScanLine: false
  73. })
  74. wx.showToast({
  75. title: '图片不合规范,请重新上传',
  76. icon: "none"
  77. })
  78. }
  79. },
  80. fail: err => {
  81. wx.showToast({
  82. title: '上传失败,请稍后再试',
  83. icon: "none"
  84. })
  85. }
  86. })
  87. },
  88. // 检查图片合法性
  89. imgCheckByBaidu() {
  90. const that = this
  91. const filePath = that.data.tempFilePath
  92. const BaseUrl = request.baseUrl
  93. wx.uploadFile({
  94. filePath,
  95. url: BaseUrl + "/api/baidu/checkPhoto",
  96. name: 'file',
  97. formData: {
  98. user: "test",
  99. },
  100. success: res => {
  101. const code = JSON.parse(res.data).code
  102. if (code == 200) {
  103. that.doUploadImg()
  104. } else {
  105. that.setData({
  106. showScanLine: false
  107. })
  108. wx.showToast({
  109. title: '图片不合规范,请重新上传',
  110. icon: "none"
  111. })
  112. }
  113. },
  114. fail: err => {
  115. wx.showToast({
  116. title: '上传失败,请稍后再试',
  117. icon: "none"
  118. })
  119. }
  120. })
  121. },
  122. // 上传图片
  123. doUploadImg() {
  124. const that = this
  125. const filePath = that.data.tempFilePath
  126. const BaseUrl = request.baseUrl
  127. wx.uploadFile({
  128. filePath,
  129. url: BaseUrl + "/api/upload/awsImgUpload",
  130. name: 'file',
  131. formData: {
  132. user: "test",
  133. },
  134. header: {
  135. "Content-Type": "multipart/form-data"
  136. },
  137. success: res => {
  138. console.log(res, 'res');
  139. const code = JSON.parse(res.data).code
  140. if (code == 200) {
  141. that.setData({
  142. showScanLine: false,
  143. isSuccess: true
  144. })
  145. wx.showToast({
  146. title: '上传成功!',
  147. icon: "success"
  148. })
  149. } else {
  150. wx.showToast({
  151. title: '服务器繁忙,请稍后再试',
  152. icon: "none"
  153. })
  154. that.setData({
  155. showScanLine: false
  156. })
  157. }
  158. },
  159. fail: err => {
  160. wx.showToast({
  161. title: '上传失败,请稍后再试',
  162. icon: "none"
  163. })
  164. }
  165. })
  166. },
  167. // 确认照片
  168. confirmImage() {
  169. },
  170. /**
  171. * 页面相关事件处理函数--监听用户下拉动作
  172. */
  173. onPullDownRefresh() {
  174. },
  175. /**
  176. * 页面上拉触底事件的处理函数
  177. */
  178. onReachBottom() {
  179. },
  180. /**
  181. * 用户点击右上角分享
  182. */
  183. onShareAppMessage() {
  184. }
  185. })