123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- 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'
- })
- }
- })
- }
- })
|