锘?*
*浣滆€咃細涓€浜涗簨鎯
*鏃堕棿锛?015-4-28
*闇€瑕佺粨鍚坖query.Jcrop涓€璧蜂娇鐢
----------------------------------------------------------*/
var jcrop_api, boundx, boundy;
//鍒濆鍖朩ebUploader
function initWebUploader(webpath) {
var parentObj = $("#upload-box");
var btnObj = $('
涓婁紶
').appendTo(parentObj);
var uploader = WebUploader.create({
auto: true, //鑷姩涓婁紶
swf: webpath + 'scripts/webuploader/uploader.swf', //SWF璺緞
server: webpath + 'tools/upload_ajax.ashx?action=SingleFile', //涓婁紶鍦板潃
pick: {
id: btnObj,
multiple: false
},
accept: {
title: 'Images',
extensions: 'jpg,jpeg,png,gif,zip,rar,doc,docx,pdf',
mimeTypes: '*'
},
formData: {
'DelFilePath': '' //瀹氫箟鍙傛暟
},
fileVal: 'Filedata', //涓婁紶鍩熺殑鍚嶇О
sendAsBinary: true, //浜岃繘鍒舵祦涓婁紶
fileSingleSizeLimit: 2048 * 1024 //鏂囦欢澶у皬
});
//褰搗alidate涓嶉€氳繃鏃讹紝浼氫互娲鹃€侀敊璇簨浠剁殑褰㈠紡閫氱煡
uploader.on('error', function (type) {
switch (type) {
case 'Q_EXCEED_NUM_LIMIT':
alert("閿欒锛氫笂浼犳枃浠舵暟閲忚繃澶氾紒");
break;
case 'Q_EXCEED_SIZE_LIMIT':
alert("閿欒锛氭枃浠舵€诲ぇ灏忚秴鍑洪檺鍒讹紒");
break;
case 'F_EXCEED_SIZE':
alert("閿欒锛氭枃浠跺ぇ灏忚秴鍑洪檺鍒讹紒");
break;
case 'Q_TYPE_DENIED':
alert("閿欒锛氬綋鍓嶇姝笂浼犺绫诲瀷鏂囦欢锛?);
break;
case 'F_DUPLICATE':
alert("閿欒锛氳鍕块噸澶嶄笂浼犺鏂囦欢锛?);
break;
default:
alert('閿欒浠g爜锛? + type);
break;
}
});
//褰撴湁鏂囦欢娣诲姞杩涙潵鐨勬椂鍊
uploader.on('fileQueued', function (file) {
uploader.options.formData.DelFilePath = $('#hideFileName').val();
//闃叉閲嶅鍒涘缓
if (parentObj.children(".upload-progress").length == 0) {
//鍒涘缓杩涘害鏉
var fileProgressObj = $('').appendTo(parentObj);
var progressText = $('姝e湪涓婁紶锛岃绋嶅€?..').appendTo(fileProgressObj);
var progressBar = $('').appendTo(fileProgressObj);
var progressCancel = $('鍏抽棴').appendTo(fileProgressObj);
//缁戝畾鐐瑰嚮浜嬩欢
progressCancel.click(function () {
uploader.cancelFile(file);
fileProgressObj.remove();
});
}
});
//鏂囦欢涓婁紶杩囩▼涓垱寤鸿繘搴︽潯瀹炴椂鏄剧ず
uploader.on('uploadProgress', function (file, percentage) {
var progressObj = parentObj.children(".upload-progress");
progressObj.children(".txt").html(file.name);
progressObj.find(".bar b").width(percentage * 100 + "%");
});
//褰撴枃浠朵笂浼犲嚭閿欐椂瑙﹀彂
uploader.on('uploadError', function (file, reason) {
uploader.removeFile(file); //浠庨槦鍒椾腑绉婚櫎
alert(file.name + "涓婁紶澶辫触锛岄敊璇唬鐮侊細" + reason);
});
//褰撴枃浠朵笂浼犳垚鍔熸椂瑙﹀彂
uploader.on('uploadSuccess', function (file, data) {
$('#jianli').attr('value', data.path);
});
//涓嶇鎴愬姛鎴栬€呭け璐ワ紝鏂囦欢涓婁紶瀹屾垚鏃惰Е鍙
uploader.on('uploadComplete', function (file) {
var progressObj = parentObj.children(".upload-progress");
progressObj.children(".txt").html("涓婁紶瀹屾垚");
//濡傛灉闃熷垪涓虹┖锛屽垯绉婚櫎杩涘害鏉
if (uploader.getStats().queueNum == 0) {
progressObj.remove();
}
});
}
//鎻愪氦瑁佸壀
function CropSubmit(obj) {
if ($("#hideFileName").val() == '') {
dialog({ title: '鎻愮ず', content: '璇峰厛涓婁紶涓€寮犲浘鐗囧啀鎻愪氦淇濆瓨锛?, okValue: '纭畾', ok: function () { } }).showModal();
return false;
}
var btnTxt = $(obj).val();
$.ajax({
type: "post",
url: $("#uploadForm").attr("url"),
data: $("#uploadForm").serialize(),
dataType: "json",
beforeSend: function (formData, jqForm, options) {
$(obj).prop("disabled", true).val("璇风◢鍊?.");
},
success: function (data, textStatus) {
if (data.status == 1) {
var d = dialog({ content: '澶村儚涓婁紶鎴愬姛锛? }).show();
setTimeout(function () {
d.close().remove();
location.reload();
}, 2000);
} else {
dialog({ title: '鎻愮ず', content: data.msg, okValue: '纭畾', ok: function () { } }).showModal();
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
dialog({ title: '鎻愮ず', content: "鐘舵€侊細" + textStatus + "锛涘嚭閿欐彁绀猴細" + errorThrown, okValue: '纭畾', ok: function () { } }).showModal();
},
complete: function (XMLHttpRequest, textStatus) {
$(obj).prop("disabled", false).val(btnTxt);
},
timeout: 20000
});
return false;
}
//鍒濆鍖朖crop
function InitJcrop() {
$("#target").Jcrop({
onChange: updatePreview,
onSelect: updatePreview,
aspectRatio: 1,
boxWidth: 350,
boxHeight: 350
}, function () {
jcrop_api = this;
});
};
//澶村儚棰勮鍥
function updatePreview(c) {
if (parseInt(c.w) > 0) {
var rx = 180 / c.w;
var ry = 180 / c.h;
$('#preview').css({
width: Math.round(rx * boundx) + 'px',
height: Math.round(ry * boundy) + 'px',
marginLeft: '-' + Math.round(rx * c.x) + 'px',
marginTop: '-' + Math.round(ry * c.y) + 'px'
});
$('#hideX1').val(Math.round(c.x));
$('#hideY1').val(Math.round(c.y));
$('#hideWidth').val(Math.round(c.w));
$('#hideHeight').val(Math.round(c.h));
}
};