LIL-588 При создании курса висит браузер из-за загрузки больших фотографий

remotes/origin/hotfix/LIL-661
gzbender 8 years ago
parent 69fd329cce
commit f1b86d0fc7
  1. 22
      web/src/components/blocks/Image.vue
  2. 18
      web/src/sass/_common.sass

@ -1,5 +1,5 @@
<template> <template>
<div class="kit__photo"> <div class="kit__photo" :class="{'loading': loading}">
<svg class="icon icon-add-plus" v-if="!imageUrl"> <svg class="icon icon-add-plus" v-if="!imageUrl">
<use xlink:href="/static/img/sprite.svg#icon-add-plus"></use> <use xlink:href="/static/img/sprite.svg#icon-add-plus"></use>
</svg> </svg>
@ -23,10 +23,24 @@
methods: { methods: {
onImageAdded(event) { onImageAdded(event) {
this.loading = true; this.loading = true;
const maxSize = 1600;
let file = event.target.files[0]; let file = event.target.files[0];
let reader = new FileReader(); const reader = new FileReader();
reader.onload = () => { reader.onload = () => {
downscale(reader.result, 2000, 2000).then((dataURL) => { 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) api.uploadImage(dataURL, this.accessToken)
.then((response) => { .then((response) => {
this.loading = false; this.loading = false;
@ -38,6 +52,8 @@
console.log('error', error); console.log('error', error);
}); });
}); });
}
img.src = reader.result;
}; };
if (file) { if (file) {
reader.readAsDataURL(file); reader.readAsDataURL(file);

@ -3463,6 +3463,24 @@ a.grey-link
.icon .icon
font-size: 20px font-size: 20px
fill: #B5B5B5 fill: #B5B5B5
&.loading &-image
visibility: hidden
&.loading
.icon
visibility: hidden
&:after
content: ''
position: absolute
top: 50%
left: 50%
width: 24px
height: 24px
margin: -12px 0 0 -12px
border: 3px solid #B5B5B5
border-left: 3px solid transparent
border-radius: 50%
animation: loading .6s infinite linear
&__file &__file
position: absolute position: absolute
top: 0 top: 0

Loading…
Cancel
Save