Commit 556a23ed by xinla

--no commit message

1 parent 769453ca
...@@ -89,35 +89,39 @@ export default { ...@@ -89,35 +89,39 @@ export default {
} }
if (this.maxImgPx) { if (this.maxImgPx) {
await new Promise((resolve) => { try {
let width, height await new Promise((resolve) => {
let image = new Image() let width, height
//加载图片获取图片真实宽度和高度 let image = new Image()
image.onload = () => { //加载图片获取图片真实宽度和高度
width = image.width image.onload = () => {
height = image.height width = image.width
if (width > this.maxImgPx[0]) { height = image.height
isSize = false if (width > this.maxImgPx[0]) {
this.$message.error('图片“宽”度超限,请重新选择') isSize = false
} else if (height > this.maxImgPx[1]) { this.$message.error('图片“宽”度超限,请重新选择')
this.$message.error('图片“高”度超限,请重新选择') } else if (height > this.maxImgPx[1]) {
isSize = false this.$message.error('图片“高”度超限,请重新选择')
isSize = false
}
window.URL && window.URL.revokeObjectURL(image.src)
resolve()
} }
window.URL && window.URL.revokeObjectURL(image.src) if (window.URL) {
resolve() let url = window.URL.createObjectURL(file)
} image.src = url
if (window.URL) { } else if (window.FileReader) {
url = window.URL.createObjectURL(file) let reader = new FileReader()
image.src = url reader.onload = function(e) {
} else if (window.FileReader) { let data = e.target.result
let reader = new FileReader() image.src = data
reader.onload = function(e) { }
let data = e.target.result reader.readAsDataURL(file)
image.src = data
} }
reader.readAsDataURL(file) })
} } catch (e) {
}) console.error(e)
}
} }
} else if (this.type === '1') { } else if (this.type === '1') {
// 语音 // 语音
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!