|
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>头像上传</title>
<link href="css/basic.css" rel="stylesheet" type="text/css" />
<link href="css/jquery.Jcrop.css" rel="stylesheet" type="text/css" />
<link type="text/css" href="css/login.css" rel="stylesheet">
</head>
<body>
<div id="header"></div>
<div class="photo-box">
<div class="photo-title">头像设置</div>
<div class="photo-set">
<div class="photo-upload">
<!--点击上传按钮-->
<div class="load">
<div class="upbtn" style="Margin:auto" ><span class="plus">+</span>本地上传<input type="file" class="filebtn" name="file" id="uploadInput" ></div>
<p>只支持JPG、PNG、GIF,大小不超过5M</p>
</div>
<!---->
<!--选择图片尺寸-->
<div class="wrap" id="jcropdiv">
<div class="wl">
<div class="jc-demo-box" data="0">
<div id="target" class="jcrop_w" >
<img src="" width="602" height="400" id="headImage" />
</div>
</div>
<div class="jy-up-ch">
<a id="idLeft" href="" class="bch bch1"></a>
<a id="idSmall" href="" class="bch bch2"></a>
<a id="idBig" href="" class="bch bch3"></a>
<a id="idRight" href="" class="bch bch4"></a>
</div>
</div>
</div>
<!---->
</div>
<div class="photo-size">
<div class="wr" id="preview-pane">
<div class="preview-container">
<p>头像预览</p>
<div class="pre-1">
<img src="" class="jcrop-preview jcrop_preview_s" alt="" id="largeImage"/>
</div>
<p>200px*200px</p>
<div class="pre-2">
<img src="" class="jcrop-preview jcrop_preview_s" alt="" id="middleImage"/>
</div>
<p>50px*50px</p>
<div class="pre-3">
<img src="" class="jcrop-preview jcrop_preview_s" alt="" id="smallImage"/>
</div>
<p>26px*26px</p>
</div>
</div>
</div>
</div>
<input id="x" type="hidden"/>
<input id="y" type="hidden"/>
<input id="w" type="hidden"/>
<input id="h" type="hidden"/>
<div class="upload-file">
<!--<div class="fl">
<div class="upbtn"><span class="plus">+</span>本地上传<input type="file" class="filebtn" name="file" id="uploadInput" ></div>
<p>只支持JPG、PNG、GIF,大小不超过5M</p>
</div>
<div class="fl">
<button type="button" id="uploadBtn">UPLOAD</button>
</div>
-->
<div class="clear"></div>
</div>
<input type="button" value="保存" class="save" id="saveImage">
<input type="button" value="取消" class="close" >
<input type="button" value="返回" id="back" >
</div>
<script type="text/javascript" src="js/jquery-1.11.1.js"></script>
<script type="text/javascript" src="js/jquery.HeadP.js"> </script>
<script type="text/javascript" src="js/jquery.Jcrop.js"> </script>
<script type="text/javascript" src="js/basic.js"> </script>
<script type="text/javascript" src="/js/ajaxfileupload.js"></script>
<script type="text/javascript" src="js/jquery.similar.msgbox.js"></script>
<script type="text/javascript">
$(function (){
var id = '358FE958561241DA8A8DFC996388893C';
var cacheImageKey=null;
var servPath = "http://121.42.53.174:80";
if(id){
$("#headImage").attr("src",servPath+"/images/head/"+id+"_l.jpg");
$("#smallImage").attr("src",servPath+"/images/head/"+id+"_l.jpg");
$("#middleImage").attr("src",servPath+"/images/head/"+id+"_l.jpg");
$("#largeImage").attr("src",servPath+"/images/head/"+id+"_l.jpg");
$('#uploadInput').live('change',function(){
$("#jcropdiv").show();
$(".load").hide();
$.ajaxFileUpload({
url:"../ajax/cachedFileUpload",
secureuri:false,
fileElementId:"uploadInput",
dataType:"json",
success:function($data){
if($data.success){
cacheImageKey =$data.data[0].cacheKey
$("#headImage").attr("src",servPath+"/images/tmp/"+cacheImageKey);
$("#smallImage").attr("src",servPath+"/images/tmp/"+cacheImageKey);
$("#middleImage").attr("src",servPath+"/images/tmp/"+cacheImageKey);
$("#largeImage").attr("src",servPath+"/images/tmp/"+cacheImageKey);
}else{
alert($data.msg);
}
},
error:function(){
$.MsgBox.Alert("message","upload error");
}
});
});
}
$("#saveImage").on("click",function(){
var x = parseInt($("#x").val()/395*100);
var y = parseInt($("#y").val()/340*100);
var w = parseInt($("#w").val()/395*100);
var h = parseInt($("#h").val()/340*100);
if(cacheImageKey){
$.ajax({
url:"../ajax/image/head",
type:"POST",
data:{"id":id,"fn":cacheImageKey,"x":x,"y":y,"w":w,"h":h},
dataType:"json",
success:function($data){
if($data.success){
alert("上传成功");
location.reload(true);
}else{
alert($data.msg);
}
}
});
}
});
$(".close").on("click",function(){
$(".load").show();
$("#jcropdiv").hide();
$("#headImage").attr("src","");
$("#smallImage").attr("src","");
$("#middleImage").attr("src","");
$("#largeImage").attr("src","");
})
$("#back").on("click",function(){
location.href="index.html";
})
})
</script>
<div id="footer"></div>
</body>
</html>
|