/**
* 判断是否发生异常
* @param json
* @returns {Boolean}
*/
function areActionOrFieldErrorInJson(json) {
var errorsExist = false;
if ( json != null && ( json.actionErrors != null || json.fieldErrors != null ) ) {
errorsExist = true;
}
return errorsExist;
}
/**
* 获取下载组件对象
* @param icon 上传图片展示的jquery选择器字符串
* @param input 上传图片返回的文件名要放置在某个input隐藏域,这个隐藏域的jquery选择器字符串
* @param btnStyle 选择图片按钮属性
* @param successHandler 图片load完成时调用此方法
* @returns {SWFUpload}
*/
function upLoadUtil(icon,input,btnStyle, successHandler){
if(btnStyle == undefined)btnStyle = {};
if(btnStyle.id == undefined)btnStyle.id = "spanButtonPlaceHolder";
if(btnStyle.label == undefined)btnStyle.label = "";
if(btnStyle.bgIcon == undefined)btnStyle.bgIcon = "/images/upload_pic.gif";
if(btnStyle.width == undefined)btnStyle.width = "85px";
if(btnStyle.height == undefined)btnStyle.height = "22px";
if(btnStyle.padLeft == undefined)btnStyle.padLeft = 12;
if(btnStyle.padTop == undefined)btnStyle.padTop = 3;
var settings = {
flash_url : ctx+"/js/swfupload.swf",
upload_url: ctx+"/ajax/upload.action",
file_size_limit : "2 MB",
file_types : "*.jpg;*.png;*.gif",
file_types_description : "Images Files",
debug: false,
// Button settings
button_image_url: ctx+btnStyle.bgIcon,
button_width: btnStyle.width,
button_height: btnStyle.height,
button_placeholder_id: btnStyle.id,
button_text: ""+btnStyle.label+"",
button_text_style: ".theFont {color: #C17B3C; font-size: 12px;}",
button_text_left_padding: btnStyle.padLeft,
button_text_top_padding: btnStyle.padTop,
file_dialog_complete_handler : function(numFilesSelected, numFilesQueued,file){
this.startUpload();
if(file != 'undefined' && file != null && file == 0){
alert("您上传的图片不符合规则,请上传JPG/GIF/PNG格式的图片且每张图片大小不超过2MB。");
}
},
upload_success_handler : function(file, serverData){
var btnStyle = $.parseJSON(serverData);
if (typeof successHandler == "function")successHandler(file, serverData);
$(icon).attr("src","").removeAttr("style");
$(icon).attr("src",getImageURL(btnStyle.savename));
$(input).val(btnStyle.savename);
$(input).focus();
$(input).blur();
}
};
return new SWFUpload(settings);
}
/**
* 内网获取下载组件对象
* @param icon 上传图片展示的jquery选择器字符串
* @param input 上传图片返回的文件名要放置在某个input隐藏域,这个隐藏域的jquery选择器字符串
* @param btnStyle 选择图片按钮属性
* @param successHandler 图片load完成时调用此方法
* @returns {SWFUpload}
*/
function upLoadUtilLocal(icon,input,btnStyle, successHandler){
if(btnStyle == undefined)btnStyle = {};
if(btnStyle.id == undefined)btnStyle.id = "spanButtonPlaceHolder";
if(btnStyle.label == undefined)btnStyle.label = "";
if(btnStyle.bgIcon == undefined)btnStyle.bgIcon = "/images/upload_pic.gif";
if(btnStyle.width == undefined)btnStyle.width = "85px";
if(btnStyle.height == undefined)btnStyle.height = "22px";
if(btnStyle.padLeft == undefined)btnStyle.padLeft = 12;
if(btnStyle.padTop == undefined)btnStyle.padTop = 3;
var settings = {
flash_url : ctx+"/js/swfupload.swf",
upload_url: ctx+"/ajax/uploadLocal.action",
file_size_limit : "2 MB",
file_types : "*.jpg;*.png;*.gif",
file_types_description : "Images Files",
debug: false,
// Button settings
button_image_url: ctx+btnStyle.bgIcon,
button_width: btnStyle.width,
button_height: btnStyle.height,
button_placeholder_id: btnStyle.id,
button_text: ""+btnStyle.label+"",
button_text_style: ".theFont {color: #C17B3C; font-size: 12px;}",
button_text_left_padding: btnStyle.padLeft,
button_text_top_padding: btnStyle.padTop,
file_dialog_complete_handler : function(numFilesSelected, numFilesQueued){
this.startUpload();
},
upload_success_handler : function(file, serverData){
var btnStyle = $.parseJSON(serverData);
if (typeof successHandler == "function")successHandler(file, serverData);
$(icon).attr("src","").removeAttr("style");
$(icon).attr("src",getImageURL(btnStyle.savename));
$(input).val(btnStyle.savename);
$(input).focus();
$(input).blur();
}
};
return new SWFUpload(settings);
}
function getImageURL(savename){
if(nofileserver){
return ctx+"/download.action"+"?savename=" + savename;
}else{
try{
var strs = savename.split("group");
var beforeUrl = strs[0];
var lastUrl = strs[1];
lastUrl = lastUrl.substr(lastUrl.indexOf("/")+1);
return beforeUrl+lastUrl;
}catch(e){
return "";
}
}
}
/**
* 切割图片
* @param cutCond 切割条件,切割条件中应包含 x1,y1,width,height四个属性
* @param oldfilename 大图文件名
* @param successHandler 切割成功后的回调方法
*/
function cutImg(cutCond, oldfilename, successHandler){
if(!cutCond){
alert("切割条件错误");
return;
}
$.ajax({
type: "POST",
url:ctx+"/ajax/cutImage.action",
dataType : 'json',
//data:{"pager.pageNum":$("#pagenum").val(),"pager.length":$("#length").val()},
data:{"x":cutCond.x1, "y":cutCond.y1, "width":cutCond.width, "height":cutCond.height, "finalWidth":cutCond.finalWidth, "finalHeight":cutCond.finalHeight, "Filename":oldfilename, "createThumnail":true},
success: function(data){
if(areActionOrFieldErrorInJson(data)){
YC.showTipInfo(0,data.actionErrors[0],200,3000);
}else {
successHandler(data);
}
}
});
}
/**
* 格式化数字
* @param f 值
* @param dec 小数点后几位
* @param isFloat 是否返回浮点数
* @returns
*/
function tofloat(f,dec,isFloat){
if(f == null || f == undefined || f == "")f = 0;
if(dec<0)return "Error:dec<0!";
var result=parseInt(f)+(dec==0?"":".");
f-=parseInt(f);
if(f==0)
for(var i=0;i limit){
$(obj).html(value.substring(0,limit)+"...");
$(obj).attr("title",value);
}else{
$(obj).html(value);
}
}
/**
* 以固定宽度展示文字
* @param obj
* @param value
* @param limit
*/
function showLengthWord(value,limit,url){
if(limit == undefined || limit == null)limit = 5;
value = $.trim(value);
if(value.length > limit){
var html = value.substring(0,limit)+"..."
return ""+html+""
}else{
return ""+value+""
}
}
/**
* 以固定宽度展示文字
* @param obj
* @param value
* @param limit
*/
function showFixLengthWord(value,limit,url){
if(limit == undefined || limit == null)limit = 5;
value = $.trim(value);
if(value.length > limit){
var html = value.substring(0,limit)+"..."
return ""+html+""
}else{
return ""+value+""
}
}
/**
* 获取固定长度文字
* @param value
* @param limit
*/
function getStrWithFixLength(value,limit){
if(limit == undefined || limit == null)limit = 5;
value = $.trim(value);
if(value.length > limit){
return value.substring(0,limit)+"...";
}else{
return value;
}
}
/**
* AJAX POST FUNCTION
* @param args {url:请求路径,data:传递的json参数,resFunc:回调函数,endFunc:完成函数}
* @returns resFunc(reData)
*/
function PostAjax(args){
var url=ctx+args.url,
data=args.data,
resFunc=args.resFunc,
endFunc=args.endFunc;
$.ajax({
url:url,
data:JSON.stringify(data),
type:"post",
dataType:"json",
//contentType:'application/json',
success:function(data){
if(data.result==1){
resFunc(data.reData);
if(typeof endFunc=="function")endFunc();
}else if(data.result==2){//未登录
location.href=ctx+'/index.jsp?tips=您的会话失效,请重新登录!';
}else if(data.result==0){//失败
YC.showTipInfo(0,data.reData,200,3000);
}
}
});
}