Skip to content

Commit 874fe19

Browse files
authored
Update vue-core-image-upload.vue
1 parent 0e390f2 commit 874fe19

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

src/vue-core-image-upload.vue

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
<div class="g-core-image-corp-container" v-bind:id="'vciu-modal-' + formID" v-show="hasImage">
88
<crop ref="cropBox" :is-resize="resize && !crop" :ratio="cropRatio"></crop>
99
<div class="info-aside">
10+
<p class="btn-groups rotate-groups" v-if="crop">
11+
<button type="button" v-on:click="doRotate" class="btn btn-rotate">↺</button>
12+
<button type="button" v-on:click="doReverseRotate" class="btn btn-reverserotate">↻</button>
13+
</p>
1014
<p class="btn-groups" v-if="crop">
1115
<button type="button" v-on:click="doCrop" class="btn btn-upload">{{cropBtn.ok}}</button>
1216
<button type="button" v-on:click="cancel" class="btn btn-cancel">{{cropBtn.cancel}}</button>
@@ -78,7 +82,7 @@
7882
if(extensionsArr.length>1) {
7983
var reg = new RegExp('^[' + extensionsArr.join('|') + ']+$','i');
8084
if (!reg.test(fileExt)) {
81-
return this.__dispatch('errorhandle','TYPE ERROR');
85+
return this.__dispatch('errorhandle','图片格式错误!');
8286
}
8387
}
8488
if (e.target.files[0].size > this.maxFileSize) {
@@ -91,7 +95,7 @@
9195
formatSize = options.maxFileSize.toFixed(2) + 'Byte';
9296
}
9397
console.warn('FILE IS TOO LARGER MAX FILE IS ' + formatSize);
94-
return this.__dispatch('errorhandle','FILE IS TOO LARGER MAX FILE IS ' + formatSize);
98+
return this.__dispatch('errorhandle','图片不能大于' + formatSize);
9599
}
96100
97101
this.files = e.target.files;
@@ -133,7 +137,9 @@
133137
const cropBox = this.$refs.cropBox;
134138
pic.onload= function() {
135139
self.image.minProgress = self.minWidth / pic.naturalWidth;
136-
self.imgChangeRatio = cropBox.setImage(src, pic.naturalWidth, pic.naturalHeight);
140+
canvasHelper.init(src, (src) => {
141+
self.imgChangeRatio = cropBox.setImage(src, pic.naturalWidth, pic.naturalHeight);
142+
});
137143
}
138144
},
139145
@@ -142,6 +148,26 @@
142148
cropBox.resizeImage(progress);
143149
},
144150
151+
doRotate(e) {
152+
let self = this;
153+
const cropBox = this.$refs.cropBox;
154+
const targetImage = cropBox.getCropImage();
155+
this.data.comprose = 100 - this.compress;
156+
return canvasHelper.rotate(targetImage, 1, (src) => {
157+
self.__initImage(src)
158+
})
159+
},
160+
161+
doReverseRotate(e) {
162+
let self = this;
163+
const cropBox = this.$refs.cropBox;
164+
const targetImage = cropBox.getCropImage();
165+
this.data.comprose = 100 - this.compress;
166+
return canvasHelper.rotate(targetImage, -1, (src) => {
167+
self.__initImage(src)
168+
})
169+
},
170+
145171
doCrop(e) {
146172
this.__setData('crop');
147173
const cropBox = this.$refs.cropBox;
@@ -159,7 +185,7 @@
159185
},
160186
161187
doResize(e) {
162-
this.__setData('reszie');
188+
this.__setData('resize');
163189
const cropBox = this.$refs.cropBox;
164190
const upload = this.__setUpload(e.target);
165191
if (this.resize === 'local') {
@@ -258,6 +284,7 @@
258284
}
259285
}
260286
}
287+
console.log(data);
261288
xhr('POST',this.url, this.headers, data, done, errorUpload, isBinary);
262289
},
263290
},

0 commit comments

Comments
 (0)