scan.js 938 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import Router from '../../../utils/routes'
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. show: 'scan'
  8. },
  9. /**
  10. * 生命周期函数--监听页面加载
  11. */
  12. onLoad: function (options) {
  13. this.camera = wx.createCameraContext()
  14. },
  15. takePhoto () {
  16. this.camera.takePhoto({
  17. success: (res) => {
  18. const tempImagePath = res.tempImagePath
  19. this.setData({
  20. filePath: tempImagePath,
  21. show: 'confirm'
  22. })
  23. }
  24. })
  25. },
  26. selectPhoto () {
  27. wx.chooseImage({
  28. count: 1,
  29. success: (res) => {
  30. const tempImagePath = res.tempFilePaths[0]
  31. this.setData({
  32. filePath: tempImagePath,
  33. })
  34. this.recongnize()
  35. }
  36. })
  37. },
  38. recongnize () {
  39. Router.push({
  40. url: 'scanResult',
  41. query: {
  42. filePath: this.data.filePath
  43. }
  44. })
  45. },
  46. reTake () {
  47. this.setData({
  48. show: 'scan'
  49. })
  50. }
  51. })