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

95
<script type="text/javascript" src="js/jquery.similar.msgbox.js"></script>	
94
<script type="text/javascript" src="js/jquery.similar.msgbox.js"></script>	
96
<script type="text/javascript"src="js/jquery.cookie.js"></script>
95
<script type="text/javascript"src="js/jquery.cookie.js"></script>
97
<script type="text/javascript">
96
<script type="text/javascript">
106
    $('#smallImage').attr("style","");
105
    $('#smallImage').attr("style","");
107
	var id = $.cookie('userid');
106
	var id = $.cookie('userid');
108
	var cacheImageKey=null;
107
	var cacheImageKey=null;
108
	var fileId = null;
109
	if(id){
109
	if(id){
110
		$("#headImage").attr("src","/images/head/"+id+"_l.jpg");
110
		$("#headImage").attr("src","/images/head/"+id+"_l.jpg");
111
		$("#smallImage").attr("src","/images/head/"+id+"_s.jpg");
111
		$("#smallImage").attr("src","/images/head/"+id+"_s.jpg");
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
		    var $li = $(
143
		    var $li = $(
144
		            '<div id="' + file.id + '" class="file-item thumbnail">' +
144
		            '<div id="' + file.id + '" class="file-item thumbnail">' +
145
		                '<img>' +
145
		                '<img>' +
194
		// 文件上传成功,给item添加成功class, 用样式标记上传成功。
194
		// 文件上传成功,给item添加成功class, 用样式标记上传成功。
195
		cacheImageKey=null;
195
		cacheImageKey=null;
196
		uploader.on( 'uploadSuccess', function(file,data) {
196
		uploader.on( 'uploadSuccess', function(file,data) {
197
		
197
		console.log(file.id);
198
		$("#jcropdiv").show();
198
		$("#jcropdiv").show();
199
		$(".load").hide();
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
		$("#middleImage").attr("src","/images/tmp/"+cacheImageKey);
204
		$("#middleImage").attr("src","/images/tmp/"+cacheImageKey);
205
		$("#largeImage").attr("src","/images/tmp/"+cacheImageKey);
205
		$("#largeImage").attr("src","/images/tmp/"+cacheImageKey);
206
		  $('#largeImage').attr("style","");
206
		  $('#largeImage').attr("style","");
207
  		 $('#middleImage').attr("style","");
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
		/*$('#uploadInput').live('change',function(){ 
211
		/*$('#uploadInput').live('change',function(){ 
242
    
239
    
243
    //保存
240
    //保存
244
	$("#saveImage").on("click",function(){
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
		if(cacheImageKey){
255
		if(cacheImageKey){
250
			$.ajax({
256
			$.ajax({
251
				url:"../ajax/image/head",
257
				url:"../ajax/image/head",
268

274

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