scan.js 957 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // pages/scan/scan.js
  2. const App = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. navTop:App.globalData.navTop,
  9. },
  10. isOnlyDigits(str) {
  11. const regex = /^[0-9]+$/; return regex.test(str);
  12. },
  13. scanQRCode() {
  14. wx.scanCode({
  15. success: (res) => {
  16. console.log(res,"二维码扫描结果"); // 输出扫描结果
  17. if(this.isOnlyDigits(res.result)){
  18. wx.setStorage({
  19. key: 'exhibition_id',
  20. data: res.result,
  21. })
  22. setTimeout(function () {
  23. wx.switchTab({
  24. url: '../index/index'
  25. })
  26. }, 400)
  27. }else{
  28. wx.showToast({
  29. title: '请扫描正确的二维码!',
  30. icon: 'none',
  31. duration: 2000
  32. });
  33. }
  34. },
  35. fail: (res) => {
  36. console.log(res);
  37. }
  38. });
  39. },
  40. onLoad(options) {
  41. },
  42. })