Skip to content

Commit bebac3c

Browse files
committed
update crop compress
1 parent 08375ee commit bebac3c

File tree

4 files changed

+22
-28
lines changed

4 files changed

+22
-28
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<template>
22
<div class="components">
33
<h3>裁剪图片</h3>
4-
<p>插件支持图片的裁剪,你可以指定图片裁剪的宽高,图片的的最大宽度和高度这些。</p>
5-
<p>图片裁剪完有两种选择,选择<strong>本地裁剪<code>local</code></strong>或者<strong>服务端裁剪 <code>server</code></strong>。你可以设置 <code>crop</code>的值来开启裁剪</p>
4+
<p>你可以通过设置 <code>crop</code>,来实现图片的裁剪。你可以指定图片裁剪的宽高,以及它的最大宽度和高度这些参数。</p>
5+
<p class="warnning"> 设置图片裁剪后,批量上传将不再生效。</p>
6+
<p>图片裁剪完有两种选择,选择<strong>本地裁剪<code>local</code></strong>或者<strong>服务端裁剪 <code>server</code></strong>。</p>
67
<h4>本地裁剪</h4>
7-
<p>你可以将 crop 设置为 local 来实现本地裁剪。裁剪完成后会发送裁剪完成后的图片到服务端。</p>
8+
<p>你可以将 crop 设置为 local 来实现本地裁剪。本地裁剪完成后发送给服务端接口的图片便是已经裁剪好的图片。</p>
89
<div class="center">
910
<div class="user">
1011
<img class="avatar" :src="cropSrc"/>
@@ -16,6 +17,7 @@
1617
url="http://101.198.151.190/api/crop.php"
1718
extensions="png,jpeg,jpg"
1819
text="Crop Image"
20+
compress="20"
1921
@imageuploaded="crpoServerImageUploaded">
2022
</vue-core-image-upload>
2123
</div>
@@ -41,7 +43,7 @@
4143
<vue-core-image-upload
4244
crop-ratio="1:1"
4345
:class="['btn', 'btn-primary']"
44-
crop="true"
46+
crop="server"
4547
url="http://101.198.151.190/api/crop.php"
4648
extensions="png,gif,jpeg,jpg"
4749
text="Crop Image"
@@ -69,14 +71,15 @@
6971
<pre v-highlightjs><code class="HTML">&lt;vue-core-image-upload
7072
crop-ratio="1:1"
7173
:class="['btn', 'btn-primary']"
72-
:crop="true"
74+
crop="server"
7375
url="http://101.198.151.190/api/crop.php"
7476
extensions="png,gif,jpeg,jpg"
7577
text="Crop Image"
7678
@imageuploaded="crpoServerImageUploaded"&gt;
7779
&lt;/vue-core-image-upload&gt;
7880

7981
</code></pre>
82+
<a href>View Code Source</a>
8083
</div>
8184
</template>
8285

site/client/less/modules/m-type.less

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,4 +358,11 @@ margin on the iframe, cause it breaks stuff. */
358358

359359
.fluid-width-video-wrapper iframe {
360360
margin: 0;
361-
}
361+
}
362+
.warnning{
363+
border-left: 3px solid #f39c12;
364+
padding-left: 15px;
365+
padding-top: 10px;
366+
padding-bottom: 10px;
367+
background-color: #ddd;
368+
}

site/src/lib/canvas-helper.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,7 @@ export default {
5151
const ctx = cvs.getContext('2d').drawImage(image, options.toCropImgX, options.toCropImgY, options.toCropImgW, options.toCropImgH, 0 , 0, w, h);
5252
const mimeType = this._getImageType(image.src);
5353
const data = cvs.toDataURL(mimeType, options.compress/100);
54-
console.log(data);
55-
const targetImage = new Image();
56-
targetImage.src = data;
57-
return targetImage;
58-
} else {
59-
callback();
54+
callback(data);
6055
}
6156
},
6257

site/src/vue-core-image-upload.vue

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,6 @@
5656
return this.inputOfFile + '[]';
5757
}
5858
return this.inputOfFile;
59-
},
60-
61-
compress() {
62-
if (this.compress >= 100) {
63-
return 99;
64-
}
65-
if(this.compress <= 0) {
66-
return 0;
67-
}
68-
return this.compress;
6959
}
7060
7161
},
@@ -155,7 +145,6 @@
155145
const newCSSObj = cropBox.getCropData();
156146
157147
for (const k of Object.keys(newCSSObj)) {
158-
console.log(k);
159148
this.data[k] = newCSSObj[k];
160149
}
161150
if (this.maxWidth) {
@@ -164,17 +153,17 @@
164153
if (this.maxHeight) {
165154
this.data['maxHeight'] = this.maxHeight;
166155
}
167-
const upload = () => {
156+
const upload = (code) => {
168157
this.tryAjaxUpload(() => {
169158
btn.value = btn.value.replace('...','');
170159
btn.disabled = false;
171-
});
160+
}, true, code);
172161
};
173162
if (this.crop === 'local') {
174163
const targetImage = cropBox.getCropImage();
175-
this.data.compress = 100 - this.compress;
176-
return canvasHelper.crop(targetImage, this.data, () => {
177-
// upload();
164+
this.data.comprose = 100 - this.compress;
165+
return canvasHelper.crop(targetImage, this.data, (code) => {
166+
upload(code);
178167
})
179168
}
180169
upload();

0 commit comments

Comments
 (0)