<template>
<view class="gui-padding">
<view class="gui-margin-top">
<text class="gui-h5 gui-color-gray">二维码生成</text>
</view>
<!-- -->
<view class="gui-margin-top-large gui-flex gui-rows gui-justify-content-center">
<canvas canvas-id="canvas" id="canvas"
style="width:360rpx; height:360rpx;" @longpress="saveQrcode"></canvas>
</view>
<view class="gui-margin-top gui-text-center">
<text class="gui-text-small gui-color-gray gui-italic">https://www.graceui.com 请长按保存</text>
</view>
</view>
</template>
<script>
var QRCode = require('@/GraceUI5/js/qrcode.js');
export default {
data() {
return {
// 二维码绘制对象
qrcode : null,
// 二维码尺寸,单位 rpx
qrcodeSize : 360,
// 二维码数据
qrcodeContent : 'https://www.graceui.com',
// 二维码背景颜色
qrcodeBgColor : '#FFFFFF',
// 二维码颜色
qrcodeColor : '#008AFF',
// 画布 id
qrcodeId : 'canvas'
}
},
onReady: function (options) {
uni.showLoading({
mask:true,
title:'loading ...'
});
setTimeout(()=>{
this.qrcode = new QRCode(this.qrcodeId, {
text : this.qrcodeContent,
width : uni.upx2px(this.qrcodeSize),
height : uni.upx2px(this.qrcodeSize),
colorDark : this.qrcodeColor,
colorLight : this.qrcodeBgColor,
correctLevel : QRCode.CorrectLevel.H
});
uni.hideLoading();
},1000);
},
methods: {
saveQrcode : function () {
uni.canvasToTempFilePath({
x : 0,
y : 0,
width : uni.upx2px(this.qrcodeSize),
height : uni.upx2px(this.qrcodeSize),
destWidth : uni.upx2px(this.qrcodeSize),
destHeight : uni.upx2px(this.qrcodeSize),
canvasId : this.qrcodeId,
success: (res) => {
uni.saveImageToPhotosAlbum({
filePath : res.tempFilePath,
fail : function (e) {
console.log(e);
},
success:()=>{
uni.showToast({
title:"图片已经保存到您的相册~"
})
}
});
}
});
}
}
}
</script>
<style>
</style>
因底层原因,暂不支持 nvue,请使用 .vue 完成此页面功能;