邃芒智像相册
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 

241 linhas
4.8 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. console.log(options, 'options');
  22. if (options.scene) {
  23. this.setData({
  24. id: options.scene
  25. })
  26. }
  27. },
  28. /**
  29. * 生命周期函数--监听页面显示
  30. */
  31. onShow() {
  32. app.tokenCallBack = res => {
  33. this.setData({
  34. isLogin: res
  35. })
  36. }
  37. },
  38. chooseImage(e) {
  39. const that = this
  40. const action = e.currentTarget.dataset.action
  41. if (action && that.data.tempFilePath) {
  42. that.setData({
  43. showScanLine: true,
  44. isUploaded: true,
  45. isSuccess: false
  46. })
  47. that.imgCheckByFace()
  48. return
  49. }
  50. wx.chooseMedia({
  51. mediaType: ['image'],
  52. sourceType: ['camera'],
  53. camera: 'back',
  54. success: res => {
  55. that.setData({
  56. tempFilePath: res.tempFiles[0].tempFilePath,
  57. showScanLine: true,
  58. isUploaded: true,
  59. isSuccess: false
  60. })
  61. that.imgCheckByFace()
  62. }
  63. })
  64. },
  65. // 检查图片是否符合人脸规范
  66. imgCheckByFace() {
  67. const that = this
  68. const filePath = that.data.tempFilePath
  69. const BaseUrl = request.baseUrl
  70. wx.uploadFile({
  71. filePath,
  72. url: BaseUrl + "/api/userDigital/checkPhoto",
  73. name: 'file',
  74. formData: {
  75. user: "test",
  76. },
  77. success: res => {
  78. const code = JSON.parse(res.data).code
  79. if (code == 200) {
  80. that.imgCheckByBaidu()
  81. } else {
  82. that.setData({
  83. showScanLine: false
  84. })
  85. wx.showToast({
  86. title: '图片不合规范,请重新上传',
  87. icon: "none"
  88. })
  89. }
  90. },
  91. fail: err => {
  92. wx.showToast({
  93. title: '上传失败,请稍后再试',
  94. icon: "none"
  95. })
  96. }
  97. })
  98. },
  99. // 检查图片合法性
  100. imgCheckByBaidu() {
  101. const that = this
  102. const filePath = that.data.tempFilePath
  103. const BaseUrl = request.baseUrl
  104. wx.uploadFile({
  105. filePath,
  106. url: BaseUrl + "/api/baidu/checkPhoto",
  107. name: 'file',
  108. formData: {
  109. user: "test",
  110. },
  111. success: res => {
  112. const code = JSON.parse(res.data).code
  113. if (code == 200) {
  114. that.doUploadImg()
  115. } else {
  116. that.setData({
  117. showScanLine: false
  118. })
  119. wx.showToast({
  120. title: '图片不合规范,请重新上传',
  121. icon: "none"
  122. })
  123. }
  124. },
  125. fail: err => {
  126. wx.showToast({
  127. title: '上传失败,请稍后再试',
  128. icon: "none"
  129. })
  130. }
  131. })
  132. },
  133. // 上传图片
  134. doUploadImg() {
  135. const that = this
  136. const filePath = that.data.tempFilePath
  137. const BaseUrl = request.baseUrl
  138. wx.uploadFile({
  139. filePath,
  140. url: BaseUrl + "/api/upload/awsImgUpload",
  141. name: 'file',
  142. formData: {
  143. user: "test",
  144. },
  145. header: {
  146. "Content-Type": "multipart/form-data"
  147. },
  148. success: res => {
  149. console.log(res, 'res');
  150. const data = JSON.parse(res.data)
  151. if (data.code == 200) {
  152. that.setData({
  153. showScanLine: false,
  154. isSuccess: true,
  155. onlineFilePath: data.data.url
  156. })
  157. wx.showToast({
  158. title: '上传成功!',
  159. icon: "success"
  160. })
  161. } else {
  162. wx.showToast({
  163. title: '服务器繁忙,请稍后再试',
  164. icon: "none"
  165. })
  166. that.setData({
  167. showScanLine: false
  168. })
  169. }
  170. },
  171. fail: err => {
  172. wx.showToast({
  173. title: '上传失败,请稍后再试',
  174. icon: "none"
  175. })
  176. }
  177. })
  178. },
  179. // 确认照片
  180. confirmImage() {
  181. const that = this
  182. const data = {
  183. id: this.data.id,
  184. image: this.data.onlineFilePath
  185. }
  186. request.post({
  187. url: "/api/screenImg/addImage",
  188. data
  189. }).then(res => {
  190. console.log(res, 'res');
  191. if (res.code == 200) {
  192. wx.showToast({
  193. title: '照片上传成功!请在终端机上查看!',
  194. icon: "none"
  195. })
  196. that.setData({
  197. topTitle: "上传成功!"
  198. })
  199. }
  200. }).catch(err => {
  201. console.log(err, 'err');
  202. })
  203. },
  204. /**
  205. * 页面相关事件处理函数--监听用户下拉动作
  206. */
  207. onPullDownRefresh() {
  208. },
  209. /**
  210. * 页面上拉触底事件的处理函数
  211. */
  212. onReachBottom() {
  213. },
  214. /**
  215. * 用户点击右上角分享
  216. */
  217. onShareAppMessage() {
  218. }
  219. })