export default { data() { return { text: '', base64:null } }, methods: { copyFn() { let ww, hh; const query = uni.createSelectorQuery().in(this); query.select('#sss').boundingClientRect(data => { ww = data.width; hh = data.height var ctx = uni.createCanvasContext('myCanvas') ctx.drawImage('../../static/132.png', 0, 0, ww, hh); ctx.setFillStyle('#000') ctx.setFontSize(30); ctx.setTextAlign('center') ctx.fillText(this.text,ww/2,hh/2+55) ctx.setFillStyle('red') ctx.setFontSize(20); ctx.setTextAlign('center') ctx.fillText('我就试试',ww/2,hh/2+80) ctx.draw(); uni.showLoading({ mask:true }) setTimeout(()=>{ uni.canvasToTempFilePath({ canvasId:'myCanvas', success: (res) => { this.base64=res.tempFilePath } }) uni.hideLoading(); },1200) }).exec(); }, bcFn(){ uni.saveImageToPhotosAlbum({ filePath:this.base64, success: (res) => { uni.showToast({ title:'保存成功', }) } }) } } }
|