qrcode.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // pages/ticketBuy/qrcode.js
  2. const utils = require('../../utils/util.js')
  3. import drawQrcode from '../../utils/weapp.qrcode.esm.js'
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. recordId: '',
  10. qrcodeUrl: ''
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: function (options) {
  16. this.setData({
  17. recordId: options.recordId
  18. })
  19. this.drawQrcode('qrcode')
  20. },
  21. //详情
  22. toDetail() {
  23. wx.redirectTo({
  24. url: '/pages/ticketBuy/detail?recordId=' + this.data.recordId
  25. })
  26. },
  27. //二维码
  28. drawQrcode(canvasId) {
  29. wx.showLoading({
  30. title: '二维码加载中...',
  31. mask: true
  32. })
  33. drawQrcode({
  34. width: 250,
  35. height: 250,
  36. canvasId: canvasId,
  37. text: 'https://app.taxbk.cn:9443/qrcode/#/invoiceTodo?recordId='+this.data.recordId,
  38. callback: () => {
  39. //安卓机上不准确,生成的二维码无法扫描,加延时解决
  40. setTimeout(() => {
  41. wx.canvasToTempFilePath({
  42. canvasId: canvasId,
  43. success: res => {
  44. wx.hideLoading()
  45. this.setData({
  46. qrcodeUrl: res.tempFilePath
  47. })
  48. }
  49. }, this)
  50. }, 500)
  51. }
  52. })
  53. },
  54. //长按保存
  55. save() {
  56. wx.getImageInfo({
  57. src: this.data.qrcodeUrl,
  58. success: res => {
  59. utils.savePhoto(res.path)
  60. }
  61. })
  62. },
  63. /**
  64. * 生命周期函数--监听页面初次渲染完成
  65. */
  66. onReady: function () {
  67. },
  68. /**
  69. * 生命周期函数--监听页面显示
  70. */
  71. onShow: function () {
  72. },
  73. /**
  74. * 生命周期函数--监听页面隐藏
  75. */
  76. onHide: function () {
  77. },
  78. /**
  79. * 生命周期函数--监听页面卸载
  80. */
  81. onUnload: function () {
  82. },
  83. /**
  84. * 页面相关事件处理函数--监听用户下拉动作
  85. */
  86. onPullDownRefresh: function () {
  87. },
  88. /**
  89. * 页面上拉触底事件的处理函数
  90. */
  91. onReachBottom: function () {
  92. },
  93. /**
  94. * 用户点击右上角分享
  95. */
  96. onShareAppMessage: function () {
  97. return {
  98. title: '诺信云',
  99. path: '/pages/index/index'
  100. }
  101. }
  102. })