<canvas style='width:{{canvasWidth}}px;height:{{canvasHeight}}px' canvas-id='myCanvas'></canvas>
var ctx = ""
var leftMargin = ""
var topMargin = ""
Pages({
data:{
title: '订单信息',
salary: '',
rtype: '',
rmoney: '',
canvasWidth: '',
canvasHeight: '',
},
handleSave() {
let _this = this;
wx.getSetting({
success(res) {
if (!res.authSetting['scope.writePhotosAlbum']) {
wx.authorize({
scope: 'scope.writePhotosAlbum',
success() {
_this.tempFilePath()
}
})
} else {
_this.tempFilePath()
}
}
})
},
img(imgSrc) {
let _this = this
var imgSrc = imgSrc
wx.downloadFile({
url: imgSrc,
success(res) {
wx.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success() {
wx.showToast({
title: '保存成功',
duration: 2000
})
_this.setData({
showPrintInfo: false
})
},
fail(err) {
console.log(err);
if (err.errMsg === "saveImageToPhotosAlbum:fail auth deny") {
wx.openSetting({
success(settingdata) {
console.log(settingdata)
if (settingdata.authSetting['scope.writePhotosAlbum']) {
wx.showToast({
title: '图片已保存',
icon: 'none',
duration: 2000
})
console.log('获取权限成功,给出再次点击图片保存到相册的提示。')
} else {
console.log('获取权限失败,给出不给权限就无法正常使用的提示')
}
}
})
}
}
})
}
})
},
addImage() {
var context = wx.createContext();
var that = this;
var path = "../../components/images/share.jpg";
ctx.drawImage(path, 0, 0, this.data.canvasWidth, this.data.canvasHeight);
this.addTitle()
this.addRtype()
this.addRmoney()
this.addSalary()
ctx.draw()
},
addTitle() {
var str = this.data.title
ctx.font = 'normal bold 20px sans-serif';
ctx.setTextAlign('center');
ctx.setFillStyle("#222222");
ctx.fillText(str, this.data.canvasWidth / 2, 65)
},
addRtype() {
var str = this.data.rtype
ctx.setFontSize(16)
ctx.setFillStyle("#222");
ctx.setTextAlign('center');
ctx.fillText(str, this.data.canvasWidth / 2, topMargin * 0.5)
},
addRmoney() {
var str = this.data.rmoney
ctx.setFontSize(16)
ctx.setFillStyle("#222");
ctx.setTextAlign('center');
ctx.fillText(str, this.data.canvasWidth / 2, topMargin * 0.6)
},
addSalary() {
var str = this.data.salary
ctx.setFontSize(16)
ctx.setFillStyle("#222");
ctx.setTextAlign('center');
ctx.fillText(str, this.data.canvasWidth / 2, topMargin * 0.71)
},
tempFilePath() {
let _this = this;
wx.canvasToTempFilePath({
canvasId: 'myCanvas',
success(res) {
_this.img(res.tempFilePath)
}
});
},
onReady() {
ctx = wx.createCanvasContext('myCanvas')
this.addImage()
},
onLoad(options) {
if (options.code) {
this.setData({
code: options.code
})
} else {
console.log("no scene");
}
this.queryCleanOrder()
let _this = this
wx.getSystemInfo({
success(res) {
_this.setData({
canvasWidth: res.windowWidth,
canvasHeight: res.windowWidth * 0.8
})
leftMargin = res.windowWidth
topMargin = res.windowWidth * 0.8
},
})
},
})