camera.js 958 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. Page({
  2. onShareAppMessage() {
  3. return {
  4. title: 'camera',
  5. path: 'page/component/pages/camera/camera'
  6. }
  7. },
  8. data: {
  9. src: '',
  10. videoSrc: '',
  11. position: 'back',
  12. mode: 'scanCode',
  13. result: {}
  14. },
  15. onLoad() {
  16. this.ctx = wx.createCameraContext()
  17. },
  18. takePhoto() {
  19. this.ctx.takePhoto({
  20. quality: 'high',
  21. success: (res) => {
  22. this.setData({
  23. src: res.tempImagePath
  24. })
  25. }
  26. })
  27. },
  28. startRecord() {
  29. this.ctx.startRecord({
  30. success: () => {
  31. console.log('startRecord')
  32. }
  33. })
  34. },
  35. stopRecord() {
  36. this.ctx.stopRecord({
  37. success: (res) => {
  38. this.setData({
  39. src: res.tempThumbPath,
  40. videoSrc: res.tempVideoPath
  41. })
  42. }
  43. })
  44. },
  45. togglePosition() {
  46. this.setData({
  47. position: this.data.position === 'front'
  48. ? 'back' : 'front'
  49. })
  50. },
  51. error(e) {
  52. console.log(e.detail)
  53. }
  54. })