//需要引入bootstrap.min.js 和 sweetalert.min.js /** * 涉及到文件上传的ajax提交 * @param formId * @param fun_success * @param fun_error */ function ajaxFormUploadForBootStrap(formId,transCode,fun_success, fun_error) { url = sysWebAppName + 'TransServlet?transCode=' +transCode + '&clientToken=' + $.__token + '&channelNo=service'; var form = new FormData(document.getElementById(formId)); $.ajax({ type : "post", data : form, processData : false, contentType : false, /* * $("#" + formId).form( 'submit', { */ url : encodeURI(url), timeout : ajaxTimeout, async : false, traditional : false, cache : false, ajaxSubmit : function() { return true; }, success : function(result) { var data = (new Function("return " + result))(); if (data.returnCode == 'EB8000006') { swal({ title: "用户异常提示", text: "用户异常,是否重新登录!", type: "warning", showCancelButton: true, confirmButtonColor: "#DD6B55", confirmButtonText: "重新登录!", cancelButtonText: "取消!", closeOnConfirm: false }, function(){ $(".leftcurtain", window.parent.document).stop() .animate({ width : '50%' }, 1500); $(".rightcurtain", window.parent.document).stop() .animate({ width : '51%' }, 1500); $(".login", window.parent.document).show("slow").find( "input[type=password]").val(""); parent.changeImage(); }); } else { if (data.returnCode == successCode) { fun_success && fun_success(data); } else { if (fun_error) { fun_error && fun_error(data); } } } }, onLoadError : function() { //$.messager.alert('系统错误', '网络或系统忙提交失败,请重试!', 'error'); } }); } /** * ajax 通信工具类(本地)--针对bootstrap的页面 * * @param transCode * 交易码 * @param servletName * servlet名称 * @param proNames * proName字段 * @param params * 参数 * @param fun_success * @param fun_error * @param isLoginOut */ function syncAjaxCalllForBootstrap(transCode, servletName, params, fun_success, fun_error, isLoginOut) { if (params == null) { params = {}; } __mask++; if (__mask >= 0) { showLoading(1); } url = sysWebAppName + servletName + '?transCode=' + transCode + '&clientToken=' + $.__token + '&channelNo=service';; $ .ajax({ url : encodeURI(url), data : params || "", type : "POST", contentType : "application/x-www-form-urlencoded; charset=utf-8", dataType : "text", timeout : ajaxTimeout, success : function(data) { data = $.parseJSON(data); __mask--; if (data == null) return; if (__mask == 0) { showLoading(-1); } if (data.returnCode == 'EB8000006') { if (isLoginOut) { fun_success && fun_success(data); } else { if (__login > 0) return; swal({ title: "用户异常提示", text: "用户异常,是否重新登录!", type: "warning", showCancelButton: true, confirmButtonColor: "#DD6B55", confirmButtonText: "重新登录!", cancelButtonText: "取消!", closeOnConfirm: false }, function(data){ if(data){ $(".leftcurtain", window.parent.document) .stop().animate({ width : '50%' }, 1500); $(".rightcurtain", window.parent.document) .stop().animate({ width : '51%' }, 1500); $(".login", window.parent.document).show(); $(".login", window.parent.document).find( "input[type=password]").val(""); $(".login", window.parent.document).find( "input[type=text]").val(""); parent.changeImage(); __login--; }else{ __login--; } }); __login++; } } else { if (data.returnCode == undefined || data.returnCode == successCode || data.success) { fun_success && fun_success(data); } else { if (fun_error) { fun_error && fun_error(data); } } } }, error : function(XMLHttpRequest, textStatus, errorThrown) { __mask--; if (__mask == 0) { showLoading(-1); } if (fun_error) { fun_error && fun_error(XMLHttpRequest, textStatus, errorThrown); } } }); } /** * ajax 通信工具类(本地)--针对bootstrap的页面(调用Manager) * * @param transCode * 交易码 * @param servletName * servlet名称 * @param proNames * proName字段 * @param params * 参数 * @param fun_success * @param fun_error * @param isLoginOut */ function syncAjaxCallManagerForBootstrap(transCode,params, fun_success, fun_error, isLoginOut) { if (params == null) { params = {}; } __mask++; if (__mask >= 0) { showLoading(1); } url = sysWebAppName + 'TransServlet?transCode=' + transCode + '&clientToken=' + $.__token; $ .ajax({ url : encodeURI(url), data : params || '', type : "POST", contentType : "application/x-www-form-urlencoded; charset=utf-8", dataType : "text", timeout : ajaxTimeout, success : function(data) { data = $.parseJSON(data); __mask--; if (data == null) return; if (__mask == 0) { showLoading(-1); } if (data.returnCode == 'EB8000006') { if (isLoginOut) { fun_success && fun_success(data); } else { if (__login > 0) return; swal({ title: "用户异常提示", text: "用户异常,是否重新登录!", type: "warning", showCancelButton: true, confirmButtonColor: "#DD6B55", confirmButtonText: "重新登录!", cancelButtonText: "取消!", closeOnConfirm: false }, function(data){ if(data){ $(".leftcurtain", window.parent.document) .stop().animate({ width : '50%' }, 1500); $(".rightcurtain", window.parent.document) .stop().animate({ width : '51%' }, 1500); $(".login", window.parent.document).show(); $(".login", window.parent.document).find( "input[type=password]").val(""); $(".login", window.parent.document).find( "input[type=text]").val(""); parent.changeImage(); __login--; }else{ __login--; } }); __login++; } } else { if (data.returnCode == undefined || data.returnCode == successCode || data.success) { fun_success && fun_success(data); } else { if (fun_error) { fun_error && fun_error(data); } } } }, error : function(XMLHttpRequest, textStatus, errorThrown) { __mask--; if (__mask == 0) { showLoading(-1); } if (fun_error) { fun_error && fun_error(XMLHttpRequest, textStatus, errorThrown); } } }); } //分页相关: /** * 对想要跳转的页面进行判断 * @param index */ function goPage(index){ var toPage; var currentPage =parseInt($("#page1").val()); var pageRows =parseInt($("#rows1").html()); var total = parseInt($("#total1").html()); var totalPage; if(total % pageRows == 0){ totalPage = total/pageRows; }else{ totalPage = parseInt(total/pageRows) + 1; } if(index == 'front'){ toPage = 1; }else if(index == 'sub'){ toPage = currentPage - 1; if(toPage <= 0){ toPage = 1; } }else if(index == 'add'){ toPage = currentPage + 1; if(toPage >= totalPage){ toPage = totalPage; } }else if(index == 'last'){ toPage = totalPage; }else if(index == 'changerows'){ if(currentPage > totalPage){ toPage = totalPage; }else{ toPage = currentPage; } }else{ if(index < 0){ index = 1; }else if(index > totalPage){ index = totalPage; } toPage = index; } $("#page1").val(toPage); doSearch(true); } /** * 改变分页的参数, 总数,总页数,开始,结束 */ function showPageIndex(total){ var page = parseInt($("#page1").val()); var pageRows =parseInt($("#rows1").html()); var totalPage,startIndex,endIndex; if(total == 0){ totalPage = 0; startIndex = 0; endIndex = 0; $("#page1").val(0); }else{ if(total % pageRows == 0){ totalPage = total/pageRows; }else{ totalPage = parseInt(total/pageRows) + 1; } startIndex = (page - 1)*pageRows + 1; endIndex = page*pageRows; if(endIndex > total){ endIndex = total; } } $("#total1").html(total); $("#totalPage1").html(totalPage); $("#startIndex1").html(startIndex); $("#endIndex1").html(endIndex); } function changeGMKB(numb,n){ if(isNaN(numb)) { return numb; } n = n > 0 && n <= 20 ? n : 2; if(numb>-1 && numb<1024){ return numb.toFixed(n)+'B'; }else if(numb>1023 && numb<1048576){ return (numb/1024).toFixed(n)+'Kb'; }else if(numb>1048575 && numb<1073741824){ return (numb/1048576).toFixed(n)+'M'; }else if(numb>1073741823){ return (numb/1073741824).toFixed(n)+'G'; } else { numb = 0; return numb.toFixed(n)+'B'; } } /** * 更改每页显示的条数 */ function changeRows(index){ $("#rows1").html(index); goPage('changerows'); } /** * 判断钱是否空 * @param id */ function ifMoneyNull(id){ var tempVal = $("#"+id).val(); var temp= tempVal.substr(0,tempVal.indexOf(".")+3); var tempNum= parseFloat(temp); if(temp == "" || temp == undefined || tempNum == 0){ //$('#collapseOne').collapse('hide'); //如果验证不通过,展开 if(! $("#"+id).parents(".panel-collapse").hasClass("in")){ $("#"+id).parents(".panel-collapse").collapse('show'); $("#"+id).focus(); return false; } var options={ trigger:'manual', }; $("#"+id).popover(options); $("#"+id).popover('show'); $("#"+id).focus(); return false; }else{ return true; } } /** * 判断内容是否为空,来显示提示框 * 对应的input必须有popover属性 * @param id * @returns {Boolean} */ function ifNull(id){ var temp = $("#"+id).val(); if(temp.replace(/(^\s*)|(\s*$)/g, "") == ""){ //$('#collapseOne').collapse('hide'); //如果验证不通过,展开 if(! $("#"+id).parents(".panel-collapse").hasClass("in")){ $("#"+id).parents(".panel-collapse").collapse('show'); $("#"+id).focus(); return false; } var options={ trigger:'manual', }; $("#"+id).popover(options); $("#"+id).popover('show'); $("#"+id).focus(); return false; }else{ return true; } } /** * 判断用户是否输入,隐藏提示框 * @param index */ function ifNullInput(index){ var temp = $(index).val(); if(null != temp && undefined != temp){ $(index).popover('hide'); } }; /** * 判断用户是否点击文件选择,隐藏提示框 * @param index */ function fileInpufHide(index){ $(index).popover('hide'); }; /** * 日期格式化 * * @param date * @returns {String} */ function formatterDate2ss(date) { var day = date.getDate() > 9 ? date.getDate() : "0" + date.getDate(); var month = (date.getMonth() + 1) > 9 ? (date.getMonth() + 1) : "0" + (date.getMonth() + 1); var hh = date.getHours() > 9 ? date.getHours() : "0" + date.getHours(); var mm = date.getMinutes() > 9 ? date.getMinutes() : "0" + date.getMinutes(); var ss = date.getSeconds() > 9 ? date.getSeconds() : "0" + date.getSeconds(); return date.getFullYear() + '-' + month + '-' + day + " " + hh+':'+mm+":"+ss; };