微信小店联盟带货小程序

qrcode.js 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. const app = getApp()
  2. Page({
  3. data: {
  4. qrcodeUrl: '/static/images/qrcode/default_qrcode.png',
  5. userAvatar: '/static/images/avatar/default_avatar.png',
  6. userNickname: '推广达人',
  7. userId: '123456'
  8. },
  9. onLoad(options) {
  10. // 获取用户信息和推广二维码
  11. this.getUserProfile()
  12. this.getPromotionQRCode()
  13. },
  14. // 获取用户信息
  15. getUserProfile() {
  16. wx.getUserProfile({
  17. desc: '获取用户信息',
  18. success: (res) => {
  19. this.setData({
  20. userAvatar: res.userInfo.avatarUrl,
  21. userNickname: res.userInfo.nickName
  22. })
  23. },
  24. fail: (err) => {
  25. console.log('获取用户信息失败', err)
  26. }
  27. })
  28. },
  29. // 获取推广二维码
  30. getPromotionQRCode() {
  31. // 模拟获取推广二维码
  32. wx.request({
  33. url: 'https://your-api.com/get_qrcode',
  34. method: 'GET',
  35. success: (res) => {
  36. this.setData({
  37. qrcodeUrl: res.data.qrcodeUrl || '/static/images/qrcode/default_qrcode.png'
  38. })
  39. },
  40. fail: (err) => {
  41. console.log('获取推广二维码失败', err)
  42. }
  43. })
  44. },
  45. // 预览二维码
  46. previewQRCode() {
  47. wx.previewImage({
  48. urls: [this.data.qrcodeUrl],
  49. current: this.data.qrcodeUrl
  50. })
  51. },
  52. // 保存二维码
  53. saveQRCode() {
  54. wx.downloadFile({
  55. url: this.data.qrcodeUrl,
  56. success: (res) => {
  57. wx.saveImageToPhotosAlbum({
  58. filePath: res.tempFilePath,
  59. success: () => {
  60. wx.showToast({
  61. title: '保存成功',
  62. icon: 'success'
  63. })
  64. },
  65. fail: (err) => {
  66. wx.showToast({
  67. title: '保存失败',
  68. icon: 'none'
  69. })
  70. }
  71. })
  72. },
  73. fail: (err) => {
  74. wx.showToast({
  75. title: '下载失败',
  76. icon: 'none'
  77. })
  78. }
  79. })
  80. },
  81. // 分享二维码
  82. shareQRCode() {
  83. wx.shareFileMessage({
  84. filePath: this.data.qrcodeUrl,
  85. success: () => {
  86. wx.showToast({
  87. title: '分享成功',
  88. icon: 'success'
  89. })
  90. },
  91. fail: (err) => {
  92. wx.showToast({
  93. title: '分享失败',
  94. icon: 'none'
  95. })
  96. }
  97. })
  98. }
  99. })