/** * 公共组件js * 为每个组件页面提供公共js方法 * @author 003598 */ /** 页面通用方法接口*/ var base ={ /** 通用方法-震动棒*/ invalid: function($cue) { //按钮动画效果 $cue.stop().delay(100) .animate({'margin-left':-5}, 100) .animate({'margin-left':5}, 100) .animate({'margin-left':-4}, 100) .animate({'margin-left':4}, 100) .animate({'margin-left':-3}, 100) .animate({'margin-left':0}, 100); }, /*str:{ cope:'' },*/ /** form表单提交 */ setAction : function(action, method, formId, target) { action = basePath + "/" + action; method = method || "post"; formId = "#" + (formId || "mainForm"); target = target || "_self"; $(formId).attr("action", action).attr("method", method).attr("target", target).submit(); }, /** get提交*/ getAction:function(action){ window.location.href= basePath + "/" +action; }, /** 使用AJAX提交返回结果时,判断用户是否失效*/ isUserFail:function($html){ if ($html.find('.login').size()>0){ alert('用户失效,请重新登录'); base.getAction('quit.do'); } }, /** 上傳圖片控件初始化方法 */ initUploadImg : function(_idFile, _idImg, _width, _height,_pic) { var idFile = _idFile || 'idFile_1'; var idImg = _idImg || 'idImg_1'; var width = _width || 200; var height = _height || 130; var pic = _pic || ImagePreview.TRANSPARENT; if (!idFile) { idFile = 'idFile_1'; } if (!idImg) { idImg = 'idImg_1'; } var ip1 = new ImagePreview($$(idFile), $$(idImg), { maxWidth : 200, maxHeight : 200, showWidth : width, showHeight : height, action : basePath + "/picture/imageUp.do" }); ip1.img.src = pic; ip1.file.onchange = function() { ip1.preview(); }; }, /** ajax公共方法 */ WAP_POST : function(action, data,type, callback) { var dataObj = {}; if (data){ dataObj = data; } if(!type){ type = 'json'; } $.ajax({ url : basePath + "/" + action, data : dataObj, type : 'post', dataType : type, async : false, // 取消异步请求 beforeSend : function() { // 可添加提前预处理 }, success : function(o) { if (callback && $.isFunction(callback)) { callback(o); } }, complete : function(XMLHttpRequest, textStatus) { // 可添加完成后处理 }, error : function() { // 可添加请求错误处理 } }); }, // 排序事件 opSort : function(_$){ if(_$.sortable('option','disabled')){ _$.sortable(); _$.sortable('enable'); }else{ _$.sortable('disable'); } }, // 预览公共方法 previewBtn:function(urlTest){ reviewUrl=basePath+"/review.do?"+urlTest; var DialogLocation = base.CalcShowModalDialogLocation(445, 800); window.showModalDialog(reviewUrl, window, DialogLocation); }, CalcShowModalDialogLocation:function(dialogWidth, dialogHeight) { var iWidth = dialogWidth; var iHeight = dialogHeight; var iTop = (window.screen.availHeight - 20 - iHeight) / 2; var iLeft = (window.screen.availWidth - 10 - iWidth) / 2; return 'dialogWidth:' + iWidth + 'px;dialogHeight:' + iHeight + 'px;dialogTop: ' + iTop + 'px; dialogLeft: ' + iLeft + 'px;center:yes;scroll:no;status:no;resizable:0;location:no'; }, /** * 公共删除方法 * * @param tip: 删除提示语 * @param execute: 删除时执行的方法(提交后台方法) */ delGetAction: function(opts) { var ops = { tip : '您确定要删除吗?', execute: null }; opts = $.extend({}, ops, opts); var isDel=window.confirm(opts.tip); if(isDel){ if(opts.execute && $.isFunction(opts.execute)){ opts.execute(); } } }, /** * 转换阿拉伯数字为汉字数字 * @param num * @returns */ chineseNum: function(num) { if(!/^\d*(\.\d*)?$/.test(num)) { alert("你输入的不是数字,请重新输入!"); return false; } var AA = new Array("零","一","二","三","四","五","六","七","八","九"); var BB = new Array("","拾","佰","仟","万","亿","点",""); var a = (""+ num).replace(/(^0*)/g, "").split("."), k = 0, re = ""; for(var i=a[0].length-1; i>=0; i--) { switch(k) { case 0 : re = BB[7] + re; break; case 4 : if(!new RegExp("0{4}\\d{"+ (a[0].length-i-1) +"}$").test(a[0])) { re = BB[4] + re; } break; case 8 : re = BB[5] + re; BB[7] = BB[5]; k = 0; break; } if(k%4 == 2 && a[0].charAt(i)=="0" && a[0].charAt(i+2) != "0"){ re = AA[0] + re; } if(a[0].charAt(i) != 0) { re = AA[a[0].charAt(i)] + BB[k%4] + re; } k++; } if(a.length>1) { re += BB[6]; for(var i=0; i=0; i--) { switch(k) { case 0 : re = BB[7] + re; break; case 4 : if(!new RegExp("0{4}\\d{"+ (a[0].length-i-1) +"}$").test(a[0])) { re = BB[4] + re; } break; case 8 : re = BB[5] + re; BB[7] = BB[5]; k = 0; break; } if(k%4 == 2 && a[0].charAt(i)=="0" && a[0].charAt(i+2) != "0"){ re = AA[0] + re; } if(a[0].charAt(i) != 0) { re = AA[a[0].charAt(i)] + BB[k%4] + re; } k++; } if(a.length>1) { re += BB[6]; for(var i=0; i * 注意:该校验规则集仅对input进行校验,其他输入框的校验,请另行扩展 * * @author wanglei_003598 * @data 20140114 * * @param className 待校验的表单名称 (必填参数) * @param repeatField 校验重复字段的名称,如果该项为空则不做字段重复校验 (可填参数) * @param repeatAction 字段重复校验后台Action (可填参数) * @param activitytype 活动类型(1.微调研,2.微预约,3.优惠劵,4.微投票,5.大转盘,6.刮刮奖) * @param keywordType 关键字设置场景:0.在新增活动的时候设置的关键字,此时用activityid * 1.在关键字设置页面设置的关键字,此时用keywordid校验关键字 * @param isVailTime 是否对时间进行校验 (可填参数) * (校验规则:结束时间不能小于开始时间 * 如有其他时间校验规则,请另行扩展) * @param startTimeId 开始时间id (可填参数), * 注意:如果该参数不填写,即使了开启时间校验,时间校验流程也跳过。 * 开启时间校验选项时,务必设置开始时间的ID。 * @param endTimeId 结束时间Id(可填参数) * @param isVaildExpiryTime 是否对兑奖时间进行校验 (可填参数) * (校验规则:兑奖结束时间不能小于兑奖开始时间 * 兑奖结束时间不能大于活动结束时间 * 兑奖开始时间不能大于活动开始时间 * 如有其他时间校验规则,请另行扩展) * @param expBeginId 兑奖开始时间(可填参数) * @param expEndId 兑奖结束时间(可填参数) * * @returns {Number} 是否可以提交: 1可提交,0:不可提交 */ validForm: function(opts) { var ops = { className: 'mainForm', repeatField : null, repeatAction: null, activitytype: 0, keywordType:0, isVailTime: false, startTimeId: null, endTimeId: null, isVaildExpiryTime: null, expBeginId: null, expEndId: null }; opts = $.extend({}, ops, opts); // 提交标示:1可提交,0:不可提交 var xxx = 1; var cope = ''; var cue = '.{0} tr'; $('.' + opts.className).find('input:text:visible').each(function(_, e){ var _me = $(e); var name = _me.attr('name'); var parendVal = _me.attr('parend'); if (parendVal){ cue = '.{0} ' + parendVal; } var $cue = _me.parents(cue.format([opts.className])).find('[name=cue]'); /** 非空校验*/ if (!_me.attr('isNull')){ var repeatFlag = base.commonVailFrom.vaildIsNull($cue, _me); if (repeatFlag){ xxx = 0; return false; } } /** 数字校验*/ if($(this).attr('num'))// 数字校验 { var repeatFlag = base.commonVailFrom.vailNum($cue, _me); if (repeatFlag){ xxx = 0; return false; } } /** 字段重复行校验*/ if (opts.repeatField && name === opts.repeatField){ var repeatFlag = base.commonVailFrom.vaildRepeat($cue, _me, opts); if (repeatFlag){ xxx = 0; return false; }else{ $cue.removeClass().empty().append(cope); } } /** 时间校验 */ if (opts.isVailTime && name === opts.endTimeId){ var repeatFlag = base.commonVailFrom.vaildTime($cue, _me, opts.startTimeId); if (repeatFlag){ xxx = 0; return false; }else{ $cue.removeClass().empty().append(cope); } } /** 时间校验2 */ if (opts.isVaildExpiryTime && name === opts.expEndId){ var repeatFlag = base.commonVailFrom.vaildExpiryTime($cue, _me, opts); if (repeatFlag){ xxx = 0; return false; }else{ $cue.removeClass().empty().append(cope); } }else{ $cue.removeClass().empty().append(cope); } }); return xxx; }, /** 判空校验 */ vaildIsNull: function($cue, _me) { var reslut = 0; var val = _me.val(); if (!val){ var dic = $cue.attr('dic') + '不能空'; // 提示消息 $cue.removeClass().addClass('redFont').empty().text(dic); // 获取焦点 _me.focus(); // 震动提示 base.invalid($cue); reslut = 1; } return reslut; }, /** 数字校验*/ vailNum: function($cue, _me){ var reslut = 0; // 校验数字--正整数 var vaildNum = /^[0-9]*[1-9][0-9]*$/; var val = _me.val(); if (vaildNum.test(val) == false) { var dic = '请正确输入数字,数量不能小于零'; // 提示消息 $cue.removeClass().addClass('redFont').empty().text(dic); // 获取焦点 _me.focus(); // 震动提示 base.invalid($cue); reslut = 1; } return reslut; } } }; /** * 添加String的format方法 替换对应位置的字符串 * * @param array[] 数组 */ String.prototype.format = function(array) { return this.replace(/\{(\d+)\}/g, function(s, i) { return array[i]; }); }; /** * 页头页面JS * @author 003598 */ var topPage={ /** 初始化化页头方法*/ init:function(){ this.initCloseBtn(); //this.initBackIndexBtn(); }, /** 初始化退出按钮*/ initCloseBtn:function(){ $("#close").click(function(){ location.href=basePath+"/quit.do"; }); } }; /** * 左侧菜单栏页面JS * @author 003598 */ var leftMenu={ // 初始化方法接口 init:function(){ this.initMenuMouseMove(); this.initMenuClick(); this.initMenuShow(); this.initMenu(); }, // 初始化菜单,只展示选中的菜单,设置选中背景 initMenu:function(){/* var $chidLi =$('#ulMenu .chidren'); pageMenuId = $.trim(pageMenuId); var selectPic = basePath + '/image/left/sidebar02_on.png'; $chidLi.find('li').each(function(){ var menuId = $(this).attr('menuId'); if(menuId == pageMenuId){ $(this).css('background-image','url('+selectPic+')'); $(this).parents('#ulMenu .chidren').show(); return false; } }); //leftMenu.menuFloat(); */}, // 初始化菜单栏鼠标移动此效果 initMenuMouseMove:function(){ $('#ulMenu>li').find('ul>li').each(function(e){ // 鼠标移入元素上 var muserPic = basePath + '/image/left/sidebar02_on_mouse.png'; var bgPic = basePath + '/image/left/sidebar02.png'; $(this).mouseover(function(e){ var bgImg = $(this).css('background-image'); if(bgImg.indexOf('sidebar02_on.png')<=0){ $(this).css('background-image','url('+muserPic+')'); } }); // 鼠标从元素上离开 $(this).mouseout(function(e){ var bgImg = $(this).css('background-image'); if(bgImg.indexOf('sidebar02_on.png')<=0){ $(this).css('background-image','url('+bgPic+')'); } }); }); }, // 初始化子菜单点击事件 initMenuClick:function(){ $('.chidrenTitle').each(function(e){ var _this = $(this); var href = _this.attr('href'); var menuId = _this.attr('menuId'); var action = href+'?menuId='+menuId; _this.click(function(){ location.href= action; }); }); }, /** 初始化菜单显示与隐藏*/ initMenuShow:function(){ $('.title').click(function(){ /* var liNum = $(this).next().find('ul>li').size(); var sp = 500; if (liNum<3){ sp = 200; }*/ /*if(!$(this).next().is(':visible')){ $('#ulMenu').find('.chidren:visible').slideUp(sp); }*/ /*$(this).next().slideToggle(sp);*/ /*$(this).next().slideDown(sp);*/ var _this = $(this); var _thisChidren = _this.next(); if (!_thisChidren.is(':visible')){ _thisChidren.slideDown(500); }else{ _thisChidren.slideUp(500); } }); }, /** 菜单栏浮动效果*/ menuFloat:function(){ // 触发上下滚动条事件 $(window).scroll( function() { // 获取页面总高度 var dH = $(document).height(); // 获取滚动条滚动高度 var scrTop = $(this).scrollTop(); // 获取菜单列表高度 var orderH = $('#ulMenu').height(); // 获取页头高度 var topHeight = $('.top').height(); var topNum = 0; if(scrTop>(topHeight-3)){ $('.order').css('position', 'fixed').css('top', '0px'); // 显示被遮住的菜单狼 if(scrTop>(dH-orderH)){ topNum = scrTop-(dH-orderH); $('.order').css('top', -(topNum)); } }else{ $('.order').css('position', 'inherit').css('top', '0px'); } }); } }; /** * 右侧内容区JS * @author 003598 */ var rightContent ={ // 初始化方法接口 init:function(){ this.initContent(); this.winUpdate(); }, /** 初始化内容页面的高度*/ initContent:function(_this){ if(!_this){ _this = $(window); } var topH = $('.top').height(); var bH = _this.height(); var contentH = bH-topH; // 最低高度不能小于600px if (contentH<600){ contentH = 600; } $('.menu_right').css('min-height', contentH); }, /** 当浏览器发生改变时,自适应浏览器的高度*/ winUpdate:function(){ $(window).resize(function() { rightContent.initContent($(this)); }); } }; // 加载模板页js方法 $(function(){ // 加载页面初始化方法 topPage.init(); leftMenu.init(); rightContent.init(); });