Default User 1 week ago
parent
commit
8d4f0cd90c
  1. 62
      pages/qrcode/index.js
  2. 1
      pages/qrcode/index.wxml

62
pages/qrcode/index.js

@ -223,6 +223,68 @@ Page({
}); });
} }
}); });
},
// 分享二维码
shareQRCode: function () {
const { qrCodeUrl } = this.data;
if (!qrCodeUrl) {
wx.showToast({
title: '请先生成二维码',
icon: 'none',
duration: 2000
});
return;
}
// 显示加载提示
wx.showLoading({
title: '准备分享...',
mask: true
});
// 下载图片到本地临时文件
wx.downloadFile({
url: qrCodeUrl,
success: (res) => {
if (res.statusCode === 200) {
wx.hideLoading();
// 打开分享面板
wx.showShareImageMenu({
path: res.tempFilePath,
success: () => {
console.log('分享成功');
},
fail: (err) => {
console.error('分享失败:', err);
wx.showToast({
title: '分享失败,请重试',
icon: 'none',
duration: 2000
});
}
});
} else {
wx.hideLoading();
console.error('下载图片失败,状态码:', res.statusCode);
wx.showToast({
title: '下载图片失败,请重试',
icon: 'none',
duration: 2000
});
}
},
fail: (err) => {
wx.hideLoading();
console.error('下载图片失败:', err);
wx.showToast({
title: '分享失败,请重试',
icon: 'none',
duration: 2000
});
}
});
} }
}); });

1
pages/qrcode/index.wxml

@ -51,6 +51,7 @@
<view class="action-buttons"> <view class="action-buttons">
<button class="action-btn primary" bindtap="generateQRCode">生成邀请二维码</button> <button class="action-btn primary" bindtap="generateQRCode">生成邀请二维码</button>
<button wx:if="{{qrCodeUrl}}" class="action-btn primary" bindtap="shareQRCode">分享二维码</button>
</view> </view>
<view class="footer"> <view class="footer">

Loading…
Cancel
Save