var Public = Public || {}; var Business = Business || {}; Public.isIE6 = !window.XMLHttpRequest; //ie6 define(["jquery", "plugins", "grid", "dialog", "datepicker"], function(require, exports){ var $ = require("jquery"); // 加载jQuery插件 require("plugins"); require("grid"); require("dialog"); //require("datepicker"); $(function(){ //菜单按钮 $('.ui-btn-menu .menu-btn').on('mouseenter.menuEvent',function(e){ if($(this).hasClass("ui-btn-dis")) { return false; } $(this).parent().addClass('ui-btn-menu-cur'); $(this).blur(); e.preventDefault(); }); $(document).on('click.menu',function(e){ var target = e.target || e.srcElement; $('.ui-btn-menu').each(function(){ var menu = $(this); if($(target).closest(menu).length == 0 && $('.con',menu).is(':visible')){ menu.removeClass('ui-btn-menu-cur'); } }) }); }); //设置表格宽高 Public.setGrid = function(adjustH, adjustW){ var defaultPage = Public.getDefaultPage(); if(defaultPage.SYSTEM.skin === 'green'){ var adjustH = adjustH || 70; } else { var adjustH = adjustH || 65; }; var adjustW = adjustW || 20; var gridW = $(window).width() - adjustW, gridH = $(window).height() - $(".grid-wrap").offset().top - adjustH; return { w : gridW, h : gridH } }; //重设表格宽高 Public.resizeGrid = function(adjustH, adjustW){ var grid = $("#grid"); var gridWH = Public.setGrid(adjustH, adjustW); grid.jqGrid('setGridHeight', gridWH.h); grid.jqGrid('setGridWidth', gridWH.w); }; //表格宽度自适应 Public.autoGrid = function($grid){ $grid.jqGrid('setGridWidth', $grid.closest('.grid-wrap').innerWidth() -2 );//去掉border的宽度 } //自定义报表宽高初始化以及自适应 Public.initCustomGrid = function(tableObj){ //去除报表原始定义的宽度 $(tableObj).css("width") && $(tableObj).attr("width","auto"); //获取报表宽度当做最小宽度 var _minWidth = $(tableObj).outerWidth(); $(tableObj).css("min-width",_minWidth+"px"); //获取当前window对象的宽度作为报表原始的宽度 $(tableObj).width($(window).width() - 74); $(tableObj).closest('.mod-report').height($(window).height() - 66); //设置resize事件 var _throttle = function(method,context){ clearTimeout(method.tid); method.tid = setTimeout(function(){ method.call(context); },100) }; var _resize = function(){ $(tableObj).width($(window).width() - 74); $(tableObj).closest('.mod-report').height($(window).height() - 66); }; $(window).resize(function() { _throttle(_resize); }); } /** * 节点赋100%高度 * * @param {object} obj 赋高的对象 */ Public.setAutoHeight = function(obj){ if(!obj || obj.length < 1){ return ; } Public._setAutoHeight(obj); $(window).bind('resize', function(){ Public._setAutoHeight(obj); }); } Public._setAutoHeight = function(obj){ obj = $(obj); //parent = parent || window; var winH = $(window).height(); var h = winH - obj.offset().top - (obj.outerHeight() - obj.height()); obj.height(h); } //操作项格式化,适用于有“修改、删除”操作的表格 Public.operFmatter = function (val, opt, row) { var html_con = '
'; return html_con; }; Public.billsOper = function (val, opt, row) { var html_con = '
'; return html_con; }; Public.billsOper_goods = function (val, opt, row) { var html_con = '
'; return html_con; }; Public.dateCheck = function(){ $('.ui-datepicker-input').bind('focus', function(e){ $(this).data('original', $(this).val()); }).bind('blur', function(e){ var reg = /((^((1[8-9]\d{2})|([2-9]\d{3}))(-)(10|12|0?[13578])(-)(3[01]|[12][0-9]|0?[1-9])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(-)(11|0?[469])(-)(30|[12][0-9]|0?[1-9])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(-)(0?2)(-)(2[0-8]|1[0-9]|0?[1-9])$)|(^([2468][048]00)(-)(0?2)(-)(29)$)|(^([3579][26]00)(-)(0?2)(-)(29)$)|(^([1][89][0][48])(-)(0?2)(-)(29)$)|(^([2-9][0-9][0][48])(-)(0?2)(-)(29)$)|(^([1][89][2468][048])(-)(0?2)(-)(29)$)|(^([2-9][0-9][2468][048])(-)(0?2)(-)(29)$)|(^([1][89][13579][26])(-)(0?2)(-)(29)$)|(^([2-9][0-9][13579][26])(-)(0?2)(-)(29)$))/; var _self = $(this); setTimeout(function(){ if(!reg.test(_self.val())) { parent.Public.tips({type:1, content : '日期格式有误!如:2013-08-08。'}); _self.val(_self.data('original')); }; }, 10) }); } //日期格式化 Date.prototype.format = function(format){ if(!format){ format = 'yyyy-MM-dd';//默认1997-01-01这样的格式 } var o = { "M+" : this.getMonth()+1, //month "d+" : this.getDate(), //day "h+" : this.getHours(), //hour "m+" : this.getMinutes(), //minute "s+" : this.getSeconds(), //second "q+" : Math.floor((this.getMonth()+3)/3), //quarter "S" : this.getMilliseconds() //millisecond } if(/(y+)/.test(format)) { format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); } for(var k in o) { if(new RegExp("("+ k +")").test(format)) { format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length)); } } return format; } Date.prototype.addMonths= function(m) { var d = this.getDate(); this.setMonth(this.getMonth() + m); if (this.getDate() < d) this.setDate(0); }; Date.prototype.addDays = function(d) { this.setDate(this.getDate() + d); }; Public.getHostName = function(){ var defaultPage = Public.getDefaultPage(); var result = defaultPage.location.hostname; if(!/.com/.test(result)){ //是IP形式的,兼容内网 result += ':'+defaultPage.location.port; } return result }; //根据之前的编码生成下一个编码 Public.getSuggestNum = function(prevNum){ if (prevNum == '' || !prevNum) { return ''; } var reg = /^([a-zA-Z0-9\-_]*[a-zA-Z\-_]+)?(\d+)$/; var match = prevNum.match(reg); if (match) { var prefix = match[1] || ''; var prevNum = match[2]; var num = parseInt(prevNum, 10) + 1; var delta = prevNum.toString().length - num.toString().length; if (delta > 0) { for (var i = 0; i < delta; i++) { num = '0' + num; } } return prefix + num; } else { return ''; } }; Public.bindEnterSkip = function(obj, func){ var args = arguments; $(obj).on('keydown', 'input:visible:not(:disabled)', function(e){ if (e.keyCode == '13') { var inputs = $(obj).find('input:visible:not(:disabled)'); var idx = inputs.index($(this)); idx = idx + 1; if (idx >= inputs.length) { if (typeof func == 'function') { var _args = Array.prototype.slice.call(args, 2 ); func.apply(null,_args); } } else { inputs.eq(idx).focus(); } } }); }; /*获取URL参数值*/ Public.getRequest = Public.urlParam = function() { var param, url = location.search, theRequest = {}; if (url.indexOf("?") != -1) { var str = url.substr(1); strs = str.split("&"); for(var i = 0, len = strs.length; i < len; i ++) { param = strs[i].split("="); theRequest[param[0]]=decodeURIComponent(param[1]); } } return theRequest; }; /** * [ajax description] * @param {[type]} ajaxOpts [description] * 默认json格式 * 默认post方式 * @return {[type]} [description] */ Public.ajax = function(ajaxOpts){ var opts = { type: "POST", dataType: "json", error: function(err){ parent.Public.tips({type: 1, content : '服务端响应错误!'}); } }; $.extend(true, opts, ajaxOpts); var success = ajaxOpts.success; opts.success = function(data, status){ /*if(data.status != 200){ var defaultPage = Public.getDefaultPage(); var msg = data.msg || '出错了=. =||| ,请点击这里拷贝错误信息 :)'; var errorStr = msg; if(data.data.error){ var errorStr = '' } defaultPage.Public.tips({type:1, content:errorStr}); return; }*/ success && success(data, status); } $.ajax(opts); }; /* 通用post请求,返回json url:请求地址, params:传递的参数{...}, callback:请求成功回调 */ Public.ajaxPost = function(url, params, callback, errCallback){ $.ajax({ type: "POST", url: url, data: params, dataType: "json", success: function(data, status){ /*if(data.status != 200){ var defaultPage = Public.getDefaultPage(); var msg = data.msg || '出错了=. =||| ,请点击这里拷贝错误信息 :)'; var errorStr = msg; if(data.data.error){ var errorStr = '' } defaultPage.Public.tips({type:1, content:errorStr}); return; }*/ callback(data); }, error: function(err,ms){ parent.Public.tips({type: 1, content : '服务端响应错误!'}); errCallback && errCallback(err); } }); }; //扩展对象方法 $.fn.extend({ //为对象新增ajaxPost方法 ajaxPost:function(url, params, callback, errCallback){ var $this = $(this); var loading; var myTimer; var preventTooFast = 'ui-btn-dis'; var ajaxOpts = { type: "POST", url: url, data: params, dataType: "json", success: function(data, status){ callback(data); }, error: function(err){ parent.Public.tips({type: 1, content : '服务端响应错误!'}); errCallback && errCallback(err); } } $.extend(true, ajaxOpts, { timeout : 20000, beforeSend : function(){ $this.addClass(preventTooFast); myTimer = setTimeout(function(){ $this.removeClass(preventTooFast); },2000) loading = $.dialog.tips('提交中,请稍候...', 1000, 'loading.gif', true); }, success : function(data){ /*if(data.status != 200){ var defaultPage = Public.getDefaultPage(); var msg = data.msg || '出错了=. =||| ,请点击这里拷贝错误信息 :)'; var errorStr = msg; if(data.data.error){ var errorStr = '' } defaultPage.Public.tips({type:1, content:errorStr}); return; }*/ callback(data); }, complete : function(){ loading.close(); }, error: function(err){ parent.Public.tips({type: 2, content : '操作无法成功,请稍后重试!'}); errCallback && errCallback(err); } }); if($this.hasClass(preventTooFast)){ return; } $.ajax(ajaxOpts); } }); Public.ajaxGet = function(url, params, callback, errCallback){ $.ajax({ type: "GET", url: url, dataType: "json", data: params, success: function(data, status){ /*if(data.status != 200){ var defaultPage = Public.getDefaultPage(); var msg = data.msg || '出错了=. =||| ,请点击这里拷贝错误信息 :)'; var errorStr = msg; if(data.data.error){ var errorStr = '' } defaultPage.Public.tips({type:1, content:errorStr}); return; }*/ callback(data); }, error: function(err){ parent.Public.tips({type: 1, content : '服务端响应错误!'}); errCallback && errCallback(err); } }); }; /*操作提示*/ Public.tips = function(options){ return new Public.Tips(options); } Public.Tips = function(options){ var defaults = { renderTo: 'body', type : 0, autoClose : true, removeOthers : true, time : undefined, top : 10, onClose : null, onShow : null } this.options = $.extend({},defaults,options); this._init(); !Public.Tips._collection ? Public.Tips._collection = [this] : Public.Tips._collection.push(this); } Public.Tips.removeAll = function(){ try { for(var i=Public.Tips._collection.length-1; i>=0; i--){ Public.Tips._collection[i].remove(); } }catch(e){} } Public.Tips.prototype = { _init : function(){ var self = this,opts = this.options,time; if(opts.removeOthers){ Public.Tips.removeAll(); } this._create(); if(opts.autoClose){ time = opts.time || opts.type == 1 ? 5000 : 3000; window.setTimeout(function(){ self.remove(); },time); } }, _create : function(){ var opts = this.options, self = this; if(opts.autoClose) { this.obj = $('
').append(opts.content); } else { this.obj = $('
').append(opts.content); this.closeBtn = this.obj.find('.close'); this.closeBtn.bind('click',function(){ self.remove(); }); }; switch(opts.type){ case 0 : this.obj.addClass('ui-tips-success'); break ; case 1 : this.obj.addClass('ui-tips-error'); break ; case 2 : this.obj.addClass('ui-tips-warning'); break ; default : this.obj.addClass('ui-tips-success'); break ; } this.obj.appendTo('body').hide(); this._setPos(); if(opts.onShow){ opts.onShow(); } }, _setPos : function(){ var self = this, opts = this.options; if(opts.width){ this.obj.css('width',opts.width); } var h = this.obj.outerHeight(),winH = $(window).height(),scrollTop = $(window).scrollTop(); //var top = parseInt(opts.top) ? (parseInt(opts.top) + scrollTop) : (winH > h ? scrollTop+(winH - h)/2 : scrollTop); var top = parseInt(opts.top) + scrollTop; this.obj.css({ position : Public.isIE6 ? 'absolute' : 'fixed', left : '50%', top : top, zIndex : '9999', marginLeft : -self.obj.outerWidth()/2 }); window.setTimeout(function(){ self.obj.show().css({ marginLeft : -self.obj.outerWidth()/2 }); },150); if(Public.isIE6){ $(window).bind('resize scroll',function(){ var top = $(window).scrollTop() + parseInt(opts.top); self.obj.css('top',top); }) } }, remove : function(){ var opts = this.options; this.obj.fadeOut(200,function(){ $(this).remove(); if(opts.onClose){ opts.onClose(); } }); } }; //数值显示格式转化 Public.numToCurrency = function(val, dec) { val = parseFloat(val); dec = dec || 2; //小数位 if(val === 0 || isNaN(val)){ return ''; } val = val.toFixed(dec).split('.'); var reg = /(\d{1,3})(?=(\d{3})+(?:$|\D))/g; return val[0].replace(reg, "$1,") + '.' + val[1]; }; //数值显示 Public.currencyToNum = function(val){ var val = String(val); if ($.trim(val) == '') { return ''; } val = val.replace(/,/g, ''); val = parseFloat(val); return isNaN(val) ? 0 : val; }; //只允许输入数字 Public.numerical = function(e){ var allowed = '0123456789.-', allowedReg; allowed = allowed.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'); allowedReg = new RegExp('[' + allowed + ']'); var charCode = typeof e.charCode != 'undefined' ? e.charCode : e.keyCode; var keyChar = String.fromCharCode(charCode); if(!e.ctrlKey && charCode != 0 && ! allowedReg.test(keyChar)){ e.preventDefault(); }; }; //限制只能输入允许的字符,不支持中文的控制 Public.limitInput = function(obj, allowedReg){ var ctrlKey = null; obj.css('ime-mode', 'disabled').on('keydown',function(e){ ctrlKey = e.ctrlKey; }).on('keypress',function(e){ allowedReg = typeof allowedReg == 'string' ? new RegExp(allowedReg) : allowedReg; var charCode = typeof e.charCode != 'undefined' ? e.charCode : e.keyCode; var keyChar = $.trim(String.fromCharCode(charCode)); if(!ctrlKey && charCode != 0 && charCode != 13 && !allowedReg.test(keyChar)){ e.preventDefault(); } }); }; //限制输入的字符长度 Public.limitLength = function(obj, count){ obj.on('keyup',function(e){ if(count < obj.val().length){ e.preventDefault(); obj.val(obj.val().substr(0,count)); } }); }; /*批量绑定页签打开*/ Public.pageTab = function() { $(document).on('click', '[rel=pageTab]', function(e){ e.preventDefault(); var right = $(this).data('right'); if (right && !Business.verifyRight(right)) { return false; }; var tabid = $(this).attr('tabid'), url = $(this).attr('href'), showClose = $(this).attr('showClose'), text = $(this).attr('tabTxt') || $(this).text(),parentOpen = $(this).attr('parentOpen'); if(parentOpen){ parent.tab.addTabItem({tabid: tabid, text: text, url: url, showClose: showClose}); } else { tab.addTabItem({tabid: tabid, text: text, url: url, showClose: showClose}); } }); }; $.fn.artTab = function(options) { var defaults = {}; var opts = $.extend({}, defaults, options); var callback = opts.callback || function () {}; this.each(function(){ var $tab_a =$("dt>a",this); var $this = $(this); $tab_a.bind("click", function(){ var target = $(this); target.siblings().removeClass("cur").end().addClass("cur"); var index = $tab_a.index(this); var showContent = $("dd>div", $this).eq(index); showContent.siblings().hide().end().show(); callback(target, showContent, opts); }); if(opts.tab) $tab_a.eq(opts.tab).trigger("click"); if(location.hash) { var tabs = location.hash.substr(1); $tab_a.eq(tabs).trigger("click"); } }); }; //文本列表滚动 Public.txtSlide = function(opt){ var def = { notice: '#notices > ul', size: 1, //显示出来的条数 pause_time: 3000, //每次滚动后停留的时间 speed: 'fast', //滚动动画执行的时间 stop: true //鼠标移到列表时停止动画 }; opt = opt || {}; opt = $.extend({}, def, opt); var $list = $(opt.notice), $lis = $list.children(), height = $lis.eq(0).outerHeight() * opt.size, interval_id; if($lis.length <= opt.size) return; interval_id = setInterval(begin, opt.pause_time); opt.stop && $list.on({ 'mouseover': function(){ clearInterval(interval_id); $list.stop(true,true); }, 'mouseleave': function(){ interval_id = setInterval(begin, opt.pause_time); } }); function begin(){ $list.stop(true, true).animate({marginTop: -height}, opt.speed, function(){ for(var i=0; i0); }catch(e){ return win; } return win; }; //权限验证 Business.verifyRight = function(right){ var system = Public.getDefaultPage().SYSTEM; var isAdmin = system.isAdmin; var siExperied = system.siExpired; var rights = system.rights; if (isAdmin && !siExperied) { return true; }; if(siExperied) { if(rights[right]) { return true; } else { var html = [ '
', '

谢谢您使用本产品,您的当前服务已经到期,到期3个月后数据将被自动清除,如需继续使用请购买/续费!

', '

(续费后请刷新页面或重新登录。)

', '
' ].join(''); $.dialog({ width: 280, title: '系统提示', icon: 'alert.gif', fixed: true, lock: true, resize: false, ok: true, content: html }); return false; } } else { if (rights[right]) { return true; } else { var html = [ '
', '

您没有该功能的使用权限哦!

', '

请联系管理员为您授权!

', '
' ].join(''); $.dialog({ width: 240, title: '系统提示', icon: 'alert.gif', fixed: true, lock: true, resize: false, ok: true, content: html }); return false; } }; }; //获取文件 Business.getFile = function(url, args, isNewWinOpen){ if (typeof url != 'string') { return ; } var url = url.indexOf('?') == -1 ? url += '?' : url; if(args.id) { url += '&id=' + args.id + '&random=' + new Date().getTime(); } else { url += '&random=' + new Date().getTime(); }; var downloadForm = parent.$('form#downloadForm'); if (downloadForm.length == 0) { downloadForm = parent.$('
').attr('id', 'downloadForm').hide().appendTo('body'); } else { downloadForm.empty(); } downloadForm.attr('action', url); for( k in args){ $('').attr({name: k, value: args[k]}).appendTo(downloadForm); } if (isNewWinOpen) { downloadForm.attr('target', '_blank'); } else{ var downloadIframe = $('iframe#downloadIframe'); if (downloadIframe.length == 0) { downloadIframe = $('