|
@@ -18,13 +18,13 @@
|
|
|
<input type="button" id="btnCrop" class="Btnsty_peyton" value="裁切" />
|
|
|
<input type="button" id="btnZoomIn" class="Btnsty_peyton" value="+" />
|
|
|
<input type="button" id="btnZoomOut" class="Btnsty_peyton" value="-" />
|
|
|
- <input type="button" id="blobSubmit" class="Btnsty_peyton" value="提交" />
|
|
|
</div>
|
|
|
<div class="cropped"></div>
|
|
|
</div>
|
|
|
<div th:include="include::footer"></div>
|
|
|
<script th:src="@{/ajax/libs/cropbox/cropbox.js}"></script>
|
|
|
<script type="text/javascript">
|
|
|
+var cropper;
|
|
|
$(window).load(function() {
|
|
|
var avatar = '[[${user.avatar}]]';
|
|
|
var options = {
|
|
@@ -32,9 +32,8 @@ $(window).load(function() {
|
|
|
spinner: '.spinner',
|
|
|
imgSrc: $.common.isEmpty(avatar) ? ctx + 'img/profile.jpg' : ctx + 'profile/avatar/' + avatar
|
|
|
}
|
|
|
- var cropper = $('.imageBox').cropbox(options);
|
|
|
- $('#avatar').on('change',
|
|
|
- function() {
|
|
|
+ cropper = $('.imageBox').cropbox(options);
|
|
|
+ $('#avatar').on('change', function() {
|
|
|
var reader = new FileReader();
|
|
|
reader.onload = function(e) {
|
|
|
options.imgSrc = e.target.result;
|
|
@@ -47,22 +46,7 @@ $(window).load(function() {
|
|
|
}
|
|
|
reader.readAsDataURL(this.files[0]);
|
|
|
})
|
|
|
- $('#blobSubmit').on('click', function(){
|
|
|
- var img = cropper.getBlob();
|
|
|
- var formdata = new FormData();
|
|
|
- formdata.append("avatarfile", img);
|
|
|
- formdata.append("userId", $("#userId").val());
|
|
|
- $.ajax({
|
|
|
- url: ctx + "system/user/profile/updateAvatar",
|
|
|
- data: formdata,
|
|
|
- type: "post",
|
|
|
- processData: false,
|
|
|
- contentType: false,
|
|
|
- success: function(result) {
|
|
|
- $.operate.saveSuccess(result);
|
|
|
- }
|
|
|
- })
|
|
|
- })
|
|
|
+
|
|
|
$('#btnCrop').on('click', function(){
|
|
|
var img = cropper.getDataURL();
|
|
|
$('.cropped').html('');
|
|
@@ -70,13 +54,32 @@ $(window).load(function() {
|
|
|
$('.cropped').append('<img src="'+img+'" align="absmiddle" style="width:128px;margin-top:4px;border-radius:128px;box-shadow:0px 0px 12px #7E7E7E;"><p>128px*128px</p>');
|
|
|
$('.cropped').append('<img src="'+img+'" align="absmiddle" style="width:180px;margin-top:4px;border-radius:180px;box-shadow:0px 0px 12px #7E7E7E;"><p>180px*180px</p>');
|
|
|
})
|
|
|
+
|
|
|
$('#btnZoomIn').on('click', function(){
|
|
|
cropper.zoomIn();
|
|
|
})
|
|
|
+
|
|
|
$('#btnZoomOut').on('click', function(){
|
|
|
cropper.zoomOut();
|
|
|
})
|
|
|
});
|
|
|
+
|
|
|
+function submitHandler() {
|
|
|
+ var img = cropper.getBlob();
|
|
|
+ var formdata = new FormData();
|
|
|
+ formdata.append("avatarfile", img);
|
|
|
+ formdata.append("userId", $("#userId").val());
|
|
|
+ $.ajax({
|
|
|
+ url: ctx + "system/user/profile/updateAvatar",
|
|
|
+ data: formdata,
|
|
|
+ type: "post",
|
|
|
+ processData: false,
|
|
|
+ contentType: false,
|
|
|
+ success: function(result) {
|
|
|
+ $.operate.saveSuccess(result);
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
</script>
|
|
|
</body>
|
|
|
</html>
|