const app = getApp() Page({ data: { qrcodeUrl: '/static/images/qrcode/default_qrcode.png', userAvatar: '/static/images/avatar/default_avatar.png', userNickname: '推广达人', userId: '123456' }, onLoad(options) { // 获取用户信息和推广二维码 this.getUserProfile() this.getPromotionQRCode() }, // 获取用户信息 getUserProfile() { wx.getUserProfile({ desc: '获取用户信息', success: (res) => { this.setData({ userAvatar: res.userInfo.avatarUrl, userNickname: res.userInfo.nickName }) }, fail: (err) => { console.log('获取用户信息失败', err) } }) }, // 获取推广二维码 getPromotionQRCode() { // 模拟获取推广二维码 wx.request({ url: 'https://your-api.com/get_qrcode', method: 'GET', success: (res) => { this.setData({ qrcodeUrl: res.data.qrcodeUrl || '/static/images/qrcode/default_qrcode.png' }) }, fail: (err) => { console.log('获取推广二维码失败', err) } }) }, // 预览二维码 previewQRCode() { wx.previewImage({ urls: [this.data.qrcodeUrl], current: this.data.qrcodeUrl }) }, // 保存二维码 saveQRCode() { wx.downloadFile({ url: this.data.qrcodeUrl, success: (res) => { wx.saveImageToPhotosAlbum({ filePath: res.tempFilePath, success: () => { wx.showToast({ title: '保存成功', icon: 'success' }) }, fail: (err) => { wx.showToast({ title: '保存失败', icon: 'none' }) } }) }, fail: (err) => { wx.showToast({ title: '下载失败', icon: 'none' }) } }) }, // 分享二维码 shareQRCode() { wx.shareFileMessage({ filePath: this.data.qrcodeUrl, success: () => { wx.showToast({ title: '分享成功', icon: 'success' }) }, fail: (err) => { wx.showToast({ title: '分享失败', icon: 'none' }) } }) } })