提交代码

This commit is contained in:
zpc 2025-03-03 21:37:24 +08:00
parent abc9013b89
commit 6e4a7249a4

View File

@ -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
// uQRCodecanvas
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: "图片"
})
}
}
}