提交 9dc28abb 编写于 作者: Q qiang

fix: 修复 app-v3 uni.canvasToTempFilePath fileType 参数不生效的问题

上级 549d450b
...@@ -63,9 +63,10 @@ export const canvasPutImageData = { ...@@ -63,9 +63,10 @@ export const canvasPutImageData = {
} }
} }
const fileType = { const fileTypes = {
PNG: 'png', PNG: 'png',
JPG: 'jpeg' JPG: 'jpg',
JPEG: 'jpg'
} }
export const canvasToTempFilePath = { export const canvasToTempFilePath = {
...@@ -103,7 +104,7 @@ export const canvasToTempFilePath = { ...@@ -103,7 +104,7 @@ export const canvasToTempFilePath = {
type: String, type: String,
validator (value, params) { validator (value, params) {
value = (value || '').toUpperCase() value = (value || '').toUpperCase()
params.fileType = value in fileType ? fileType[value] : fileType.PNG params.fileType = value in fileTypes ? fileTypes[value] : fileTypes.PNG
} }
}, },
quality: { quality: {
......
<template> <template>
<uni-canvas <uni-canvas
:canvas-id="canvasId" :canvas-id="canvasId"
:disable-scroll="disableScroll" :disable-scroll="disableScroll"
v-on="_listeners"> v-on="_listeners">
<canvas <canvas
ref="canvas" ref="canvas"
width="300" width="300"
height="150" /> height="150" />
<div style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; overflow: hidden;"> <div style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; overflow: hidden;">
<slot /> <slot />
</div> </div>
<v-uni-resize-sensor <v-uni-resize-sensor
ref="sensor" ref="sensor"
@resize="_resize" /> @resize="_resize" />
</uni-canvas> </uni-canvas>
</template> </template>
...@@ -121,15 +121,15 @@ export default { ...@@ -121,15 +121,15 @@ export default {
method(data) method(data)
} }
}, },
_resize () { _resize () {
var canvas = this.$refs.canvas var canvas = this.$refs.canvas
if (canvas.width > 0 && canvas.height > 0) { if (canvas.width > 0 && canvas.height > 0) {
var context = canvas.getContext('2d') var context = canvas.getContext('2d')
var imageData = context.getImageData(0, 0, canvas.width, canvas.height) var imageData = context.getImageData(0, 0, canvas.width, canvas.height)
wrapper(this.$refs.canvas) wrapper(this.$refs.canvas)
context.putImageData(imageData, 0, 0) context.putImageData(imageData, 0, 0)
} else { } else {
wrapper(this.$refs.canvas) wrapper(this.$refs.canvas)
} }
}, },
_touchmove (event) { _touchmove (event) {
...@@ -549,7 +549,8 @@ export default { ...@@ -549,7 +549,8 @@ export default {
const img = new Image() const img = new Image()
img.onload = () => { img.onload = () => {
const canvas = getTempCanvas(destWidth, destHeight) const canvas = getTempCanvas(destWidth, destHeight)
if (fileType === 'jpeg') { if (fileType === 'jpeg' || fileType === 'jpg') {
fileType = 'jpeg'
c2d.fillStyle = '#fff' c2d.fillStyle = '#fff'
c2d.fillRect(0, 0, destWidth, destHeight) c2d.fillRect(0, 0, destWidth, destHeight)
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册