- 点击上传图片,拍照上传,确认图片后,加载中然后就没有了,没有上传图片
- 应该是打印出返回的data
"pages/upPoto/main"
- 提供一个最简复现 Demo
data () {
return {
imgMaxWidth: 1500,
imgMaxHeight: 1500}
},
methods: {
getSaoyiSao (id) {
var taskid = Number(id)
var that = this
var FSM = wx.getFileSystemManager()
wx.chooseImage({
count: 1, // 默认9
sizeType: ['compressed'], // 指定只能为压缩图,首先进行一次默认压缩
sourceType: ['camera'], // 可以指定来源是相册还是相机,默认二者都有
success: function (photo) {
wx.getImageInfo({
src: photo.tempFilePaths[0],
success: function (res) {
var imgHeight = 0
var imgWidth = 0
var containerRatio = that.imgMaxWidth / that.imgMaxHeight
var imgRatio = res.width / res.height
if (imgRatio > containerRatio) {
imgWidth = that.imgMaxWidth
imgHeight = that.imgMaxWidth / imgRatio
} else if (imgRatio < containerRatio) {
imgHeight = that.imgMaxHeight
imgWidth = that.imgMaxHeight * imgRatio
}
that.cWidth = Math.min(imgWidth, res.width)
that.cHeight = Math.min(imgHeight, res.height)
var ctx = wx.createCanvasContext('canvas')
ctx.drawImage(res.path, 0, 0, that.cWidth, that.cHeight)
ctx.draw(false, setTimeout(function () {
wx.canvasToTempFilePath({
fileType: 'jpg',
canvasId: 'canvas',
destWidth: that.cWidth,
destHeight: that.cHeight,
success: function (res) {
FSM.readFile({
filePath: res.tempFilePath,
encoding: 'base64',
success: function (data) {
console.log(data)
}
})
},
fail: function (res) {
console.log(res.errMsg)
}
})
}, 300))
}
})
}
})
}
}