scan-code.js 692 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. Page({
  2. onShareAppMessage() {
  3. return {
  4. title: '扫码',
  5. path: 'packageAPI/pages/device/scan-code/scan-code'
  6. }
  7. },
  8. data: {
  9. theme: 'light',
  10. result: ''
  11. },
  12. scanCode() {
  13. const that = this
  14. wx.scanCode({
  15. scanType: ['barCode', 'qrCode', 'datamatrix', 'pdf417'],
  16. success(res) {
  17. that.setData({
  18. result: res.result
  19. })
  20. },
  21. fail(err) {
  22. console.log('scanCode fail: ', err)
  23. }
  24. })
  25. },
  26. onLoad() {
  27. this.setData({
  28. theme: wx.getSystemInfoSync().theme || 'light'
  29. })
  30. if (wx.onThemeChange) {
  31. wx.onThemeChange(({theme}) => {
  32. this.setData({theme})
  33. })
  34. }
  35. }
  36. })