Skip to content

Commit 6939923

Browse files
committed
fixed original src bug
1 parent 7d9cf4c commit 6939923

19 files changed

+97
-33
lines changed

dist/crop.vue

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ import GIF_LOADING_SRC from './lib/loading-gif';
133133
import helper from './lib/helper';
134134
import canvasHelper from './lib/canvas-helper';
135135
import ResizeBar from './resize-bar.vue';
136-
import RotateBar from './rotate-bar.vue';
136+
import RotateBar from './rotate-bar';
137137
// set cropbox size in image
138138
const CROPBOX_PERCENT = 75;
139139
const isMobile = helper.isMobile;
@@ -186,7 +186,7 @@ export default {
186186
setImage(src, w, h) {
187187
this.src = src;
188188
if (!this.originSrc) {
189-
this.originSrc = this.src;
189+
this.setOriginalSrc(this.src);
190190
}
191191
if (this.ratio.indexOf(':') > 0) {
192192
this.ratioW = this.ratio.split(':')[0];
@@ -208,6 +208,11 @@ export default {
208208
}
209209
return this.imgChangeRatio;
210210
},
211+
212+
setOriginalSrc(src) {
213+
this.originSrc = src;
214+
},
215+
211216
resizeImage(progress) {
212217
let w,
213218
h;
@@ -366,13 +371,13 @@ export default {
366371
};
367372
this.el = $el;
368373
this.container = $container;
374+
const maxCoor = this._getMaxCropAreaWidth();
369375
const move = function (ev) {
370376
const newCropStyle = resize(ev, self.el, $container, coor, self.ratioVal);
371-
if (newCropStyle) {
377+
if (newCropStyle && (newCropStyle.width <= maxCoor.maxWidth || newCropStyle.height <= maxCoor.maxHeight)) {
372378
self.cropCSS.width = newCropStyle.width;
373379
self.cropCSS.height = newCropStyle.height;
374380
}
375-
376381
};
377382
const end = function (ev) {
378383
this.el = null;
@@ -391,6 +396,20 @@ export default {
391396
document.addEventListener('mouseup', end, false);
392397
},
393398
399+
_getMaxCropAreaWidth() {
400+
const $cropBox = this.__find('.crop-box');
401+
if (this.width > this.height) {
402+
return {
403+
maxWidth: this.height * this.ratioW / this.ratioH,
404+
maxHeight: this.height,
405+
}
406+
}
407+
return {
408+
maxWidth: this.width,
409+
maxHeight: this.width * this.ratioH / this.ratioW,
410+
};
411+
},
412+
394413
drag(e) {
395414
e.preventDefault();
396415
const $el = this.__find('.image-wrap');

dist/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
import VueCoreImageUpload from './vue-core-image-upload.vue';
1+
import VueCoreImageUpload from 'vue-core-image-upload';
22
export default VueCoreImageUpload;

dist/lib/resize.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/props.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/resize-bar.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div class="g-resize-bar">
33
<div class="g-resize-highlight" :style="{width: left + '%',}"></div>
4-
<button type="button" class="circle-btn" @touchstart.self="drag" @mousedown.self="drag" :style="{left: left + '%',}"></button>
4+
<button class="circle-btn" @touchstart.self="drag" @mousedown.self="drag" :style="{left: left + '%',}"></button>
55
</div>
66
</template>
77

dist/rotate-bar.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
</style>
3535

3636
<script>
37-
module.exports = {
37+
export default {
3838
data() {
3939
return {
4040
rotateDegree: 0,

dist/vue-core-image-upload.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@
209209
this.hasImage = false;
210210
document.body.style.overflow = overflowVal;
211211
this.files = '';
212+
const cropBox = this.$refs.cropBox;
213+
cropBox.setOriginalSrc(null);
212214
document.querySelector('#g-core-upload-input-' + this.formID).value = '';
213215
},
214216

index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-core-image-upload",
3-
"version": "2.3.3",
3+
"version": "2.3.4",
44
"description": "a vue plgin for image upload and crop",
55
"main": "dist/vue-core-image-upload.vue",
66
"dependencies": {

site/client/components/doc/en/CropImage.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<img class="avatar" :src="src"/>
1313
</div>
1414
<vue-core-image-upload
15+
crop-ratio="1:1"
1516
crop="local"
1617
resize="local"
1718
url="http://101.198.151.190/api/upload.php"

0 commit comments

Comments
 (0)