Browse Source

修改图片上传

lipengtao 8 years ago
parent
commit
992d04b5b7
1 changed files with 26 additions and 19 deletions
  1. 26 19
      src/main/webapp/photo-set.html

+ 26 - 19
src/main/webapp/photo-set.html

@ -57,7 +57,7 @@
57 57
                             <div class="pre-1">
58 58
                                 <img  src="" class="jcrop-preview jcrop_preview_s" alt="" id="largeImage"/>
59 59
                             </div>
60
                             <p>200px*200px</p>
60
                             <p>160px*160px</p>
61 61
                             <div class="pre-2">
62 62
                                 <img src="" class="jcrop-preview jcrop_preview_s" alt="" id="middleImage"/>
63 63
                             </div>
@ -91,7 +91,6 @@
91 91
<script type="text/javascript" src="js/jquery.HeadP.js"> </script>
92 92
<script type="text/javascript" src="js/jquery.Jcrop.js"> </script>
93 93
<script type="text/javascript" src="js/basic.js"> </script>
94

95 94
<script type="text/javascript" src="js/jquery.similar.msgbox.js"></script>	
96 95
<script type="text/javascript"src="js/jquery.cookie.js"></script>
97 96
<script type="text/javascript">
@ -106,6 +105,7 @@ $(function (){
106 105
    $('#smallImage').attr("style","");
107 106
	var id = $.cookie('userid');
108 107
	var cacheImageKey=null;
108
	var fileId = null;
109 109
	if(id){
110 110
		$("#headImage").attr("src","/images/head/"+id+"_l.jpg");
111 111
		$("#smallImage").attr("src","/images/head/"+id+"_s.jpg");
@ -138,8 +138,8 @@ $(function (){
138 138
		});
139 139
	
140 140
		// 当有文件添加进来的时候
141
		uploader.on( 'fileQueued', function( file ) {	
142
			/* alert(file.name); */		
141
		uploader.on( 'fileQueued', function( file ) {				
142
			 fileId = file.id;			
143 143
		    var $li = $(
144 144
		            '<div id="' + file.id + '" class="file-item thumbnail">' +
145 145
		                '<img>' +
@ -194,21 +194,18 @@ $(function (){
194 194
		// 文件上传成功,给item添加成功class, 用样式标记上传成功。
195 195
		cacheImageKey=null;
196 196
		uploader.on( 'uploadSuccess', function(file,data) {
197
		
197
		console.log(file.id);
198 198
		$("#jcropdiv").show();
199 199
		$(".load").hide();
200
			cacheImageKey =data.data[0].cacheKey;
201
			console.log(cacheImageKey);
202
			$("#headImage").attr("src","/images/tmp/"+cacheImageKey);
203
			$("#smallImage").attr("src","/images/tmp/"+cacheImageKey);
200
		uploader.removeFile(fileId);
201
		cacheImageKey =data.data[0].cacheKey;			
202
		$("#headImage").attr("src","/images/tmp/"+cacheImageKey);
203
		$("#smallImage").attr("src","/images/tmp/"+cacheImageKey);
204 204
		$("#middleImage").attr("src","/images/tmp/"+cacheImageKey);
205 205
		$("#largeImage").attr("src","/images/tmp/"+cacheImageKey);
206 206
		  $('#largeImage').attr("style","");
207 207
  		 $('#middleImage').attr("style","");
208
  		 $('#smallImage').attr("style","");
209
			console.log(cacheImageKey);
210
		   // $( '#'+file.id ).addClass('upload-state-done');
211
			$("#filePicker").hide();
208
  		 $('#smallImage').attr("style","");					  
212 209
		});
213 210
		
214 211
		/*$('#uploadInput').live('change',function(){ 
@ -242,10 +239,19 @@ $(function (){
242 239
    
243 240
    //保存
244 241
	$("#saveImage").on("click",function(){
245
		var x = parseInt($("#x").val()/395*100);
246
		var y = parseInt($("#y").val()/340*100);
247
		var w = parseInt($("#w").val()/395*100);
248
		var h = parseInt($("#h").val()/340*100);
242
	if(cacheImageKey==null) {
243
		$.MsgBox.Alert("消息","请选择图片");
244
		return;
245
	}
246
		var iw = $('.jcrop_w>img').width(),ih = $('.jcrop_w>img').height(),ow = (395 - iw) / 2,oh = (340 - ih) / 2;
247
		var x = parseInt(($("#x").val()-ow)/395*100);
248
		var y = parseInt(($("#y").val()-oh)/340*100);
249
		var w = parseInt($("#w").val()/(395-ow-ow)*100);
250
		var h = parseInt($("#h").val()/(340-oh-oh)*100);
251
		if(x<0 || y<0 || ((w+x)>100) || ((h+y)>100)){
252
		   $.MsgBox.Alert("消息","裁剪超出图片,请重新裁剪");
253
			return;			
254
		}
249 255
		if(cacheImageKey){
250 256
			$.ajax({
251 257
				url:"../ajax/image/head",
@ -268,13 +274,14 @@ $(function (){
268 274

269 275
    //取消
270 276
	$(".close").on("click",function(){
277
	
271 278
		$(".load").show();
272 279
		$("#jcropdiv").hide();
273
		$("#filePicker").show();
280
		//$("#filePicker").show();
274 281
		$("#headImage").attr("src","");
275 282
		$("#smallImage").attr("src","");
276 283
		$("#middleImage").attr("src","");
277
		$("#largeImage").attr("src","");
284
		$("#largeImage").attr("src","");		
278 285
	})
279 286
    
280 287
    //返回