提交代码
This commit is contained in:
parent
abc9013b89
commit
6e4a7249a4
|
|
@ -71,18 +71,15 @@
|
|||
</view>
|
||||
</view>
|
||||
</mescroll-body>
|
||||
|
||||
<rule-pop ref="rulePop"></rule-pop>
|
||||
|
||||
<uni-popup ref="posterPopup" type="center">
|
||||
<canvas canvas-id="myPoster" style="width: 650rpx; height: 950rpx;">
|
||||
<view class="view_poster">
|
||||
<!-- <canvas id="qrcode" canvas-id="qrcode"
|
||||
style="width: 150px;height: 150px; position: absolute; bottom: 180rpx; left: 200rpx;"></canvas> -->
|
||||
</view>
|
||||
</canvas>
|
||||
<view style="width:650rpx;height:950rpx;">
|
||||
<image :src="getHaiBao()" style="width: 100%;"></image>
|
||||
</view>
|
||||
<view style="text-align: center;">
|
||||
<image style="width: 48px;height: 48px;" @click="saveImageToPhotosAlbum()" :src="getXiaZai()"></image>
|
||||
</view>
|
||||
</uni-popup>
|
||||
|
||||
</view>
|
||||
</template>
|
||||
|
||||
|
|
@ -116,9 +113,57 @@
|
|||
},
|
||||
onLoad() {
|
||||
console.log(uni.getStorageSync('userinfo').ID)
|
||||
onReady();
|
||||
},
|
||||
methods: {
|
||||
saveImageToPhotosAlbum() {
|
||||
const imageUrl = this.getHaiBao(); // 替换为你的网络图片地址
|
||||
// 下载图片到本地
|
||||
wx.downloadFile({
|
||||
url: imageUrl,
|
||||
success: (res) => {
|
||||
if (res.statusCode === 200) {
|
||||
const tempFilePath = res.tempFilePath; // 获取临时文件路径
|
||||
// 保存图片到相册
|
||||
wx.saveImageToPhotosAlbum({
|
||||
filePath: tempFilePath,
|
||||
success: () => {
|
||||
uni.showToast({
|
||||
title: '保存成功',
|
||||
icon: 'success',
|
||||
});
|
||||
},
|
||||
fail: (err) => {
|
||||
uni.showToast({
|
||||
title: '保存失败',
|
||||
icon: 'none',
|
||||
});
|
||||
console.error('保存失败', err);
|
||||
},
|
||||
});
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: '图片下载失败',
|
||||
icon: 'none',
|
||||
});
|
||||
console.error('图片下载失败', res);
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
uni.showToast({
|
||||
title: '图片下载失败',
|
||||
icon: 'none',
|
||||
});
|
||||
console.error('图片下载失败', err);
|
||||
},
|
||||
});
|
||||
},
|
||||
getHaiBao() {
|
||||
return this.$baseUrl + '/api/generate_urllinks?userId=' + uni.getStorageSync('userinfo').ID;
|
||||
},
|
||||
getXiaZai() {
|
||||
return this.$baseUrl + '/dow.png';
|
||||
|
||||
},
|
||||
/*下拉刷新的回调 */
|
||||
downCallback() {
|
||||
this.mescroll.resetUpScroll()
|
||||
|
|
@ -160,48 +205,7 @@
|
|||
//海报弹窗
|
||||
showPosterPopup() {
|
||||
this.$refs.posterPopup.open();
|
||||
this.drawAndExport();
|
||||
},
|
||||
|
||||
onReady() {
|
||||
// 获取uQRCode实例
|
||||
var qr = new UQRCode();
|
||||
// 设置二维码内容
|
||||
qr.data = "https://uqrcode.cn/doc";
|
||||
// 设置二维码大小,必须与canvas设置的宽高一致
|
||||
qr.size = 150;
|
||||
// 调用制作二维码方法
|
||||
qr.make();
|
||||
// 获取canvas上下文
|
||||
var canvasContext = uni.createCanvasContext('qrcode', this); // 如果是组件,this必须传入
|
||||
// 设置uQRCode实例的canvas上下文
|
||||
qr.canvasContext = canvasContext;
|
||||
// 调用绘制方法将二维码图案绘制到canvas上
|
||||
qr.drawCanvas();
|
||||
},
|
||||
|
||||
drawAndExport() {
|
||||
const ctx = uni.createCanvasContext('myPoster', this);
|
||||
ctx.setFillStyle('red');
|
||||
ctx.fillRect(10, 10, 150, 75);
|
||||
ctx.setFontSize(18);
|
||||
ctx.setFillStyle('black');
|
||||
ctx.fillText('Hello, Canvas!', 50, 50);
|
||||
ctx.draw(false, () => {
|
||||
uni.canvasToTempFilePath({
|
||||
canvasId: 'myPoster',
|
||||
success: res => {
|
||||
console.log('图片路径:', res.tempFilePath);
|
||||
// 在这里处理生成的图片路径,比如下载、显示或上传
|
||||
},
|
||||
fail: err => {
|
||||
console.error('生成图片失败:', err);
|
||||
}
|
||||
});
|
||||
});
|
||||
uni.showToast({
|
||||
title: "图片"
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user