No Description

photo-set.html 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7. <title>头像上传</title>
  8. <link href="css/reset.css" rel="stylesheet" type="text/css" />
  9. <link href="css/basic.css" rel="stylesheet" type="text/css" />
  10. <link href="css/jquery.Jcrop.css" rel="stylesheet" type="text/css" />
  11. <link type="text/css" href="css/login.css" rel="stylesheet">
  12. </head>
  13. <body>
  14. <div class="coverbox">
  15. <div class="photo-box">
  16. <div class="photo-title">头像设置</div>
  17. <div class="photo-set">
  18. <div class="photo-upload">
  19. <!--点击上传按钮-->
  20. <div class="load">
  21. <div class="upbtn" style="Margin:auto" ><span class="plus">+</span>本地上传<input type="file" class="filebtn" name="file" id="uploadInput" ></div>
  22. <p>只支持JPG、PNG,大小不超过5M</p>
  23. </div>
  24. <!---->
  25. <!--选择图片尺寸-->
  26. <div class="wrap" id="jcropdiv">
  27. <div class="wl">
  28. <div class="jc-demo-box" data="0">
  29. <div id="target" class="jcrop_w" >
  30. <img src="" width="602" height="400" id="headImage" />
  31. </div>
  32. </div>
  33. <!-- <div class="jy-up-ch" >
  34. <a id="idLeft" href="" class="bch bch1"></a>
  35. <a id="idSmall" href="" class="bch bch2"></a>
  36. <a id="idBig" href="" class="bch bch3"></a>
  37. <a id="idRight" href="" class="bch bch4"></a>
  38. </div> -->
  39. </div>
  40. </div>
  41. <!---->
  42. </div>
  43. <div class="photo-size">
  44. <div class="wr" id="preview-pane">
  45. <div class="preview-container">
  46. <p>头像预览</p>
  47. <div class="pre-1">
  48. <img src="" class="jcrop-preview jcrop_preview_s" alt="" id="largeImage"/>
  49. </div>
  50. <p>200px*200px</p>
  51. <div class="pre-2">
  52. <img src="" class="jcrop-preview jcrop_preview_s" alt="" id="middleImage"/>
  53. </div>
  54. <p>66px*66px</p>
  55. <div class="pre-3">
  56. <img src="" class="jcrop-preview jcrop_preview_s" alt="" id="smallImage"/>
  57. </div>
  58. <p>30px*30px</p>
  59. </div>
  60. </div>
  61. </div>
  62. </div>
  63. <input id="x" type="hidden"/>
  64. <input id="y" type="hidden"/>
  65. <input id="w" type="hidden"/>
  66. <input id="h" type="hidden"/>
  67. <div class="upload-file">
  68. <!--<div class="fl">
  69. <div class="upbtn"><span class="plus">+</span>本地上传<input type="file" class="filebtn" name="file" id="uploadInput" ></div>
  70. <p>只支持JPG、PNG、GIF,大小不超过5M</p>
  71. </div>
  72. <div class="fl">
  73. <button type="button" id="uploadBtn">UPLOAD</button>
  74. </div>
  75. -->
  76. <div class="clear"></div>
  77. </div>
  78. <input type="button" value="保存" class="inputtxt inputtxtbtn save" id="saveImage">
  79. <input type="button" value="取消" class="inputtxt inputtxtbtn close" >
  80. <input type="button" value="返回" class="inputtxt inputtxtbtn " id="back" >
  81. </div>
  82. </div>
  83. <div id="header"></div>
  84. <div id="footer"></div>
  85. <script type="text/javascript" src="js/jquery-1.11.1.js"></script>
  86. <script type="text/javascript" src="js/jquery.HeadP.js"> </script>
  87. <script type="text/javascript" src="js/jquery.Jcrop.js"> </script>
  88. <script type="text/javascript" src="js/basic.js"> </script>
  89. <script type="text/javascript" src="/js/ajaxfileupload.js"></script>
  90. <script type="text/javascript" src="js/jquery.similar.msgbox.js"></script>
  91. <script type="text/javascript"src="js/jquery.cookie.js"></script>
  92. <script type="text/javascript">
  93. $(function (){
  94. var _widht = document.documentElement.clientWidth; //屏幕宽
  95. var _height = document.documentElement.clientHeight; //屏幕高
  96. var boxWidth = $(".photo-box").width();
  97. var boxHeight = $(".photo-box").height();
  98. $(".photo-box").css({ top:"40px", left: (_widht - boxWidth) / 2 + "px" });
  99. $('#largeImage').attr("style","");
  100. $('#middleImage').attr("style","");
  101. $('#smallImage').attr("style","");
  102. var id = $.cookie('userid');
  103. var cacheImageKey=null;
  104. if(id){
  105. $("#headImage").attr("src","/images/head/"+id+"_l.jpg");
  106. $("#smallImage").attr("src","/images/head/"+id+"_s.jpg");
  107. $("#middleImage").attr("src","/images/head/"+id+"_m.jpg");
  108. $("#largeImage").attr("src","/images/head/"+id+"_l.jpg");
  109. $('#uploadInput').live('change',function(){
  110. $("#jcropdiv").show();
  111. $(".load").hide();
  112. $.ajaxFileUpload({
  113. url:"../ajax/cachedFileUpload",
  114. secureuri:false,
  115. fileElementId:"uploadInput",
  116. dataType:"json",
  117. success:function($data){
  118. console.log($data);
  119. if($data.success){
  120. cacheImageKey =$data.data[0].cacheKey;
  121. console.log(cacheImageKey);
  122. $("#headImage").attr("src","/images/tmp/"+cacheImageKey);
  123. $("#smallImage").attr("src","/images/tmp/"+cacheImageKey);
  124. $("#middleImage").attr("src","/images/tmp/"+cacheImageKey);
  125. $("#largeImage").attr("src","/images/tmp/"+cacheImageKey);
  126. }else{
  127. $.MsgBox.Alert("message",$data.msg);
  128. }
  129. },
  130. error:function(){
  131. $.MsgBox.Alert("message","upload error");
  132. }
  133. });
  134. });
  135. }
  136. //保存
  137. $("#saveImage").on("click",function(){
  138. var x = parseInt($("#x").val()/395*100);
  139. var y = parseInt($("#y").val()/340*100);
  140. var w = parseInt($("#w").val()/395*100);
  141. var h = parseInt($("#h").val()/340*100);
  142. if(cacheImageKey){
  143. $.ajax({
  144. url:"../ajax/image/head",
  145. type:"POST",
  146. data:{"id":id,"fn":cacheImageKey,"x":x,"y":y,"w":w,"h":h},
  147. dataType:"json",
  148. success:function($data){
  149. console.log($data);
  150. if($data.success){
  151. $.MsgBox.Alert("消息","上传成功");
  152. location.reload(true);
  153. }else{
  154. $.MsgBox.Alert("message",$data.msg);
  155. }
  156. }
  157. });
  158. }
  159. });
  160. //取消
  161. $(".close").on("click",function(){
  162. $(".load").show();
  163. $("#jcropdiv").hide();
  164. $("#headImage").attr("src","");
  165. $("#smallImage").attr("src","");
  166. $("#middleImage").attr("src","");
  167. $("#largeImage").attr("src","");
  168. })
  169. //返回
  170. $("#back").on("click",function(){
  171. location.href="index.html";
  172. })
  173. })
  174. </script>
  175. </body>
  176. </html>