|
|
|
|
@ -1,5 +1,5 @@ |
|
|
|
|
<template> |
|
|
|
|
<div class="kit__photo"> |
|
|
|
|
<div class="kit__photo" :class="{'loading': loading}"> |
|
|
|
|
<svg class="icon icon-add-plus" v-if="!imageUrl"> |
|
|
|
|
<use xlink:href="/static/img/sprite.svg#icon-add-plus"></use> |
|
|
|
|
</svg> |
|
|
|
|
@ -23,21 +23,37 @@ |
|
|
|
|
methods: { |
|
|
|
|
onImageAdded(event) { |
|
|
|
|
this.loading = true; |
|
|
|
|
const maxSize = 1600; |
|
|
|
|
let file = event.target.files[0]; |
|
|
|
|
let reader = new FileReader(); |
|
|
|
|
const reader = new FileReader(); |
|
|
|
|
reader.onload = () => { |
|
|
|
|
downscale(reader.result, 2000, 2000).then((dataURL) => { |
|
|
|
|
api.uploadImage(dataURL, this.accessToken) |
|
|
|
|
.then((response) => { |
|
|
|
|
this.loading = false; |
|
|
|
|
this.$emit('update:imageId', response.data.id); |
|
|
|
|
this.$emit('update:imageUrl', response.data.image); |
|
|
|
|
}) |
|
|
|
|
.catch((error) => { |
|
|
|
|
this.loading = false; |
|
|
|
|
console.log('error', error); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
let img = document.createElement('img'); |
|
|
|
|
img.onload = () => { |
|
|
|
|
let w = 0; |
|
|
|
|
let h = 0; |
|
|
|
|
if(img.width > img.height) { |
|
|
|
|
w = maxSize; |
|
|
|
|
h = 0; |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
w = 0; |
|
|
|
|
h = maxSize; |
|
|
|
|
} |
|
|
|
|
downscale(img.src, w, h).then((dataURL) => { |
|
|
|
|
img = null; |
|
|
|
|
api.uploadImage(dataURL, this.accessToken) |
|
|
|
|
.then((response) => { |
|
|
|
|
this.loading = false; |
|
|
|
|
this.$emit('update:imageId', response.data.id); |
|
|
|
|
this.$emit('update:imageUrl', response.data.image); |
|
|
|
|
}) |
|
|
|
|
.catch((error) => { |
|
|
|
|
this.loading = false; |
|
|
|
|
console.log('error', error); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
img.src = reader.result; |
|
|
|
|
}; |
|
|
|
|
if (file) { |
|
|
|
|
reader.readAsDataURL(file); |
|
|
|
|
|