1. 程式人生 > >剛使用requrie.js時的代碼

剛使用requrie.js時的代碼

cap tip port mss ntb 保存 彈層 號碼 時間控件

//短信服務
define([‘jquery‘,‘jsrender‘,‘base‘,‘text!../../html/sms.html‘,‘pagination‘,‘bootstrap‘, ‘datetimepicker‘, ‘datetimepicker.zh-CN‘], function($,jsrender,base,html){
    function init(){
            var blackIdArry = [],
                timesDate = ‘‘,
                sendTypeN = ‘‘;
            $(‘body>.wrapper>.content‘).html(html);
            
//控制短信內容字數 function controlWord(){ var remainWd = 70-$(‘#status‘).val().length; $(‘.tipsWd‘).html(remainWd); } $(‘#mask‘).on(‘keydown‘,‘#status‘,function(){ controlWord() }) $(‘#mask‘).on(‘keyup‘,‘#status‘,function
(){ controlWord() }) /*==========================選擇分組====================================================*/ $(‘#mask‘).on(‘click‘,‘.span-tab‘,function(){ var i = $(this).index(); $(this).addClass(‘select‘).siblings(‘.span-tab‘).removeClass(‘select‘); $(
‘.show-con‘).eq(i).show().siblings(‘.show-con‘).hide(); }) /* * 下拉選擇 * 多選 */ //點擊得到下拉區域 $(‘#mask‘).on(‘click‘,‘.region-box‘,function(){ $(".region-list").show(); var queryData = {}; queryData.enterpriseId = sessionStorage.getItem("enterpriseId"); // queryData.name = ‘‘; base.ajax({"type":"GET","url":"/ecapi/cardgroup/query","data":queryData},function(res){ if(res.record == 1200){ //console.log(res); //渲染表格數據 var liList = $(‘.region-list ul li‘); var valData = res.data; var valLen = valData.length; var _Html = ‘‘; if(liList.length < 1){ for(var i=1;i<valLen;i++){ _Html += ‘<li class="clearfix" data-amount="‘+valData[i].amount+‘"><span class="text" data-id="‘+valData[i].id+‘">‘+valData[i].name+‘</span><span class="check checkbox"></span></li>‘; } $(‘.region-list ul‘).html(_Html); } //隱藏號碼為空的Li var liListLen = $(‘.region-list ul li‘).length; for(var i = 0;i<liListLen; i++){ if($(‘.region-list ul li‘).eq(i).attr("data-amount") == "0"){ $(‘.region-list ul li‘).eq(i).hide(); } } } }); //阻止冒泡 return false; }) //隱藏下拉區域 $("#mask").on(‘click‘,function(){ $(this).find(".region-list").hide(); }) $(‘#mask‘).on(‘click‘,‘.region-list‘,function(){ //阻止冒泡 return false; }) //選擇所在區域 checkbox $(‘#mask‘).on(‘click‘,‘.region-list ul .check‘,function(){ if( $(this).parent(‘li‘).hasClass(‘selected‘)){ $(this).parent(‘li‘).removeClass(‘selected‘); var val = $(this).parent().find(".text").html(); $(".region-com li").find(".text").each(function(){ if($(this).html() == val){ $(this).parent("li").remove(); } }) }else{ $(this).parent(‘li‘).addClass(‘selected‘); var val = $(this).parent().find(".text").html(); var text = ‘<li><span class="text">‘+val+‘</span><i class="icon"></i></li>‘; $(".region-com ul").append(text); } }) //全選 $(‘#mask‘).on(‘click‘,‘.region-list ul .allcheck‘,function(){ if($(this).parent(‘li‘).hasClass(‘selected‘)){ $(this).parent(‘li‘).removeClass(‘selected‘); $(this).parent(‘li‘).siblings(‘li‘).removeClass(‘selected‘); var lihtml = $(this).parent(‘li‘).siblings(‘li‘); $(".region-com ul").html(‘‘); }else{ $(this).parent(‘li‘).addClass(‘selected‘); $(this).parent(‘li‘).siblings(‘li‘).addClass(‘selected‘); var lihtml = $(this).parent(‘li‘).siblings(‘li‘); for(var i = 0;i<lihtml.length;i++){ var val = lihtml.eq(i).find(‘.text‘).html(); var text = ‘<li><span class="text">‘+val+‘</span><i class="icon"></i></li>‘; $(".region-com ul").append(text); } } }) /*==========================手動輸入生成標簽===========================================*/ /* * 手動添加 設備SN獲取焦點 */ $("#mask").on("click",".plan-num-com",function(){ $(".sn-input").focus(); }); function checkSn(sn, err_info, err_box) { var checkNumberData = []; checkNumberData.push(sn); base.ajax({"type":"POST","url":"/ecapi/shortMessage/checkNumber","data":{‘number‘:checkNumberData}},function(res){ if(res.record == 1200){ err_info.removeClass("error"); err_box.html(‘‘); return true; }else{ err_info.addClass("error"); err_box.html(res.msg); return false; } }); } // 如果超過6行,出現滾動條 var sixHeiFun = function() { var sn_box = $(".plan-num-com"), sn_hei = sn_box.height(); if (sn_hei >= 125) { sn_box.css({ "overflow-y" : "auto", "height" : "125px" }); } else { sn_box.css({ "overflow-y" : "hidden", "height" : "auto" }); } } /* * 手動添加函數 * 判斷是否重復 * 正則驗證 * */ var equipSN = function(){ //SN00000001 var num = Number($(".sn-list").length); var _this = $("#J_inp_sn"); var check_val = /^[a-zA-Z0-9]{1,32}$/; var inp_val = ($.trim(_this.val())).split(" "), str_len = inp_val.length; for(var j=0;j<str_len;j++){ if(j == 21 || num == 21){ break; } if(inp_val[j] != ""){ var text = ‘<div class="sn-list"><p>‘+inp_val[j]+‘</p><i class="sn-close"></i></div>‘; $(".sn-com").before(text); _this.val("").css({"width":"13px"}); var len = $(".sn-list").length- 1, err_box = $("#plan-num").next(), err_info = $(".sn-list").last(); sixHeiFun(); // for(var i=0;i<len;i++){ // if($(".sn-list").eq(i).find("p").html() == inp_val[j]){ // err_info.addClass("error"); // err_box.html("設備SN重復."); // continue; // }//設備SN只允許輸入英文大小寫及數字 // else if(!check_val.test(inp_val[j])){ // err_info.addClass("error"); // err_box.html("請輸入1-32位字母、數字組合的設備SN."); // continue; // } // } /** * 查詢數據庫裏是否有重復 */ checkSn(inp_val[j], err_info, err_box); //return true; //如果大於超過50個設備時,則不能輸入; if(num >= 19){ $("#J_inp_sn").attr("disabled","disabled"); }else{ $("#J_inp_sn").removeAttr("disabled"); } } } } /* * 自動延伸寬度 * */ var autoLength = function() { var input = document.getElementById(‘J_inp_sn‘); var hlp = document.getElementById(‘input_help‘); if (!hlp) { hlp = document.createElement(‘span‘); hlp.id = ‘input_help‘; hlp.style.visibility = ‘hidden‘; hlp.style.position = ‘absolute‘; hlp.style.left = 0; hlp.style.top = 0; hlp.style.wordWrap = ‘nowrap‘; hlp.style.overflowX = ‘visible‘; document.getElementById("J_sn_com").appendChild(hlp); } hlp.innerHTML = input.value; // 這裏多加20個像素,使文本框右邊內部有空白空間 input.style.width = (hlp.offsetWidth + 5) + ‘px‘; } /* * 手動添加 號碼 */ $("#mask").on("keyup",".sn-input",function(e){ autoLength(); var keyCode = window.event ? e.keyCode : e.which; if(keyCode == 13){ equipSN(); } }); /* * 輸入input失去焦點時 * 默認把input內容自動生成標簽 * 右鍵粘貼 * */ $("#mask").on("paste","#J_inp_sn",function(){ setTimeout(function() { equipSN(); },100); }); $("#mask").on("blur","#J_inp_sn",function(){ equipSN(); }); /* * 手動添加 設備SN 刪除標簽 */ $("#mask").on("click", ".sn-close", function() { var num = Number($(".sn-list").length); $(this).parent().remove(); sixHeiFun(); // 如果大於20個號碼時,則不能輸入; if (num = 20) { $("#J_inp_sn").removeAttr("disabled"); } // 如果錯誤標簽刪除時,提示需要清除 if (!$(".sn-list").hasClass("error")) { $("#plan-num").next().html(""); return true; } }) /* * 得到前N天或後N天的日期 * */ function showdateAll(n){ var uom = new Date(new Date()-0+n*86400000), m_num = uom.getMonth()+ 1, d_num = uom.getDate(); if(m_num < 10){ m_num = "0"+m_num; } if(d_num < 10){ d_num = "0"+d_num; } uom = uom.getFullYear() + "-" + (m_num) + "-" + (d_num); return uom; } /* * 得到當前日期 * */ function nowdate(){ var d = new Date(), m_now = d.getMonth()+ 1, d_now = d.getDate(); if(m_now < 10){ m_now = "0"+m_now; } if(d_now < 10){ d_now = "0"+d_now; } var dateEnd = d.getFullYear()+‘-‘+ (m_now)+"-"+ d_now; return dateEnd; } /*==========================選擇短信發送方式===========================================*/ $(‘#mask‘).on(‘click‘,‘.form_item .label‘,function(){ if($(‘#timingsend‘).is(":checked")){ $(‘#show-inputTime‘).show(); }else{ $(‘#show-inputTime‘).hide(); } //定時發送時間控件 var s_time = showdateAll(7), e_time = showdateAll(1); $(‘#sms_query_time‘).val(‘‘).datetimepicker({ format: ‘yyyy-mm-dd hh:ii‘, language: ‘zh-CN‘, startView: ‘year‘, minView: ‘hour‘, initialDate: e_time, startDate : e_time, endDate : s_time, //Date autoclose: true }); $(‘.datetimepicker‘).hide(); //選擇定時發送 $(‘#mask #sms-month-pick‘).on(‘changeDate‘,function(){ sendTypeN = ‘2‘; timesDate = $(‘#sms_query_time‘).val(); //console.log(timesDate); }) }) //選擇即時發送 $(‘#mask‘).on(‘click‘,‘#Immediatesed‘,function(){ sendTypeN = ‘1‘; var u_data = new Date(); m_num = u_data.getMonth()+ 1, d_num = u_data.getDate(); if(m_num < 10){ m_num = "0"+m_num; } if(d_num < 10){ d_num = "0"+d_num; } timesDate = u_data.getFullYear()+‘-‘+ (m_num)+"-"+ (d_num)+" "+ u_data.getHours()+":"+ u_data.getMinutes()+":"+ u_data.getSeconds(); }) //黑名單號碼列表checkbox $(‘#mask‘).on(‘click‘,‘#blackNameTable .maincheck‘,function(){ if($(this).is(‘:checked‘)){ $(‘#blackNameTable‘).find(‘.subcheck‘).prop("checked",true); }else{ $(‘#blackNameTable‘).find(‘.subcheck‘).prop("checked",false); } }); $(‘#mask‘).on(‘click‘,‘#blackNameTable .subcheck‘,function(){ var checkLen = $(this).is(":checked").length; //獲取當前td的id var blackId = Number($(this).parent(‘td‘).attr(‘id‘)); if($(this).is(":checked")){ blackIdArry.push(blackId); }else{ blackIdArry.pop(blackId); } console.log("n9999",blackIdArry); if(checkLen == 0){ $("#blackNameTable .maincheck").prop("checked",true); }else{ $("#blackNameTable .maincheck").prop("checked",false); } }) /*==========================短信發送記錄===========================================*/ //短信查詢時間控件 $(‘#J_query_time‘).val(‘‘).datetimepicker({ format: ‘yyyy-mm-dd‘, language: ‘zh-CN‘, startView: ‘year‘, minView: ‘month‘, initialDate: ‘‘, startDate: new Date(‘2017‘), //Date autoclose: true }); $(‘.datetimepicker‘).hide(); //短信發送記錄查詢 queryShortMessageFn({"shortTime":‘‘,"pageNum":1,"pageSize":10}); function queryShortMessageFn(queryMessageData){ base.ajax({"type":"GET","url":"/ecapi/shortMessage/queryShortMessage","data":queryMessageData},function(res){ if(res.record == 1200){ //渲染表格數據 var smsTableHtml = $("#smsTabel").render(res.data); $("#sms-table").html(smsTableHtml); //分頁 queryMessageData.total = res.data.total; base.listPage(queryShortMessageFn,queryMessageData,‘#sms-tableForm-box‘,true); } }); } //導出 queryShortMessageFn.exportFile = function(queryMessageData){ window.location.href="/ecapi/shortMessage/downloadShortMessage?shortTime="; } //點擊日歷查詢短信發送記錄 $(‘#month-pick‘).on(‘changeDate‘,function(ev){ var update_time = $(‘#J_query_time‘).val(); queryShortMessageFn({"shortTime":update_time,"pageNum":1,"pageSize":10}); //導出 queryShortMessageFn.exportFile = function(queryMessageData){ window.location.href="/ecapi/shortMessage/downloadShortMessage?shortTime="+update_time; } }) /**********************************彈窗操作***********************************/ /*********************發送短信彈窗*********************** */ $(‘.serviceBtn .setBtn‘).on(‘click‘,function(){ $(‘#mask‘).removeClass(‘hidden‘); var setMessageHtml = $("#setMessage").render(); $("#mask").html(setMessageHtml); }) /*******焦點離開驗證**********/ $(‘#mask‘).on(‘blur‘,‘#status‘,function(){ var messageCon_box = $(‘#status‘), messageCon = messageCon_box.val(), error_box = messageCon_box.parents(‘.form_item‘).next(); if(messageCon == ‘‘){ error_box.html(‘請輸入短信內容‘); return false; }else{ error_box.html(‘‘); return true; } }) /*******點擊發送驗證**********/ //發送內容 function setMessage(){ var messageCon_box = $(‘#status‘), messageCon = messageCon_box.val(), error_box = messageCon_box.parents(‘.form_item‘).next(); if(messageCon == ‘‘){ error_box.html(‘請輸入短信內容‘); return false; }else{ error_box.html(‘‘); return true; } } /* * 添加彈框點擊確定按鈕時 * 判斷手動輸入的號碼是否通過 * */ function handList(){//1311234567913 if($("#plan-num").next().html() == "號碼不在該集團客戶下"){ return false; }else{ return true; } } function blackname(){ if($("#plan-num").next().html() ==‘號碼已在黑名單,不能對其發送短信‘){ return false }else{ return true; } } //驗證接收號碼是否為空 function snList(){ if($(‘.span-tab.tab1‘).hasClass(‘select‘)){ // $(‘.region-com ul‘).html(‘‘); if($(‘.sn-list‘).length == 0){ $(‘.receive-number‘).parents(‘.form_item‘).next().html(‘請輸入接受號碼或選擇分組‘); return false; }else{ $(‘.receive-number‘).parents(‘.form_item‘).next().html(‘‘); return true; } } if($(‘.span-tab.tab2‘).hasClass(‘select‘)){ $(‘.sn-list‘).html(‘‘); if($(‘.region-com ul li‘).length > 0){ $(‘.receive-number‘).parents(‘.form_item‘).next().html(‘‘); return true; }else{ $(‘.receive-number‘).parents(‘.form_item‘).next().html(‘請輸入接受號碼或選擇分組‘); return false; } } } //驗證發送方式是否為空 function typePost(){ if(timesDate == ‘‘){ $(‘.show-inputTime‘).parents(‘.form_item‘).next().html(‘請選擇發送方式‘); return false; }else{ $(‘.show-inputTime‘).parents(‘.form_item‘).next().html(‘‘); return true; } } //點擊發送按鈕 $(‘#mask‘).on(‘click‘,‘#sendBtn‘,function(){ if(setMessage() && handList() &&blackname() && snList() && typePost()){ //接收號碼發送格式 var receivertype = ‘‘; var numberArry = []; if($("#mask .span-tab.select").attr("data-type") == "1"){ $(".plan-num-com .sn-list").each(function(){ numberArry.push($(this).find(‘p‘).html()); }) receivertype = ‘1‘; }else{ // $("#J-region-com li").each(function(){ // numberArry.push($(this).find(".text").html()); // }) $(‘.region-list li.selected‘).each(function(){ numberArry.push($(this).find(‘span‘).attr(‘data-id‘)); }) receivertype = ‘2‘; } console.log(numberArry); console.log(‘發送~~‘,timesDate); console.log(‘發送類型‘,receivertype); var sendShortData = {}; sendShortData.sendMessage = $(‘#status‘).val(); sendShortData.receiverNumber = numberArry;//以數組格式上傳號碼 sendShortData.receiverType = receivertype; sendShortData.sendTime = timesDate; sendShortData.sendType = sendTypeN; //發送短信請求接口 base.ajax({"type":"POST","url":"/ecapi/shortMessage/sendShort","data":sendShortData},function(res){ if(res.record == 1200){ $("#mask").addClass("hidden").html(); base.popo(res.msg); //短信發送記錄查詢 queryShortMessageFn({"shortTime":‘‘,"pageNum":1,"pageSize":10}); } }); } }) /*********************黑名單管理*********************** */ //黑名單管理請求數據 function blacklistFn(blacklistData){ base.ajax({"type":"GET","url":"/ecapi/shortMessage/blacklist",‘data‘:blacklistData},function(res){ if(res.record == 1200){ var blackTableHtml = $("#blackName").render(res.data); $("#mask").html(blackTableHtml); //分頁 blacklistData.total = res.data.total; base.listPage(blacklistFn,blacklistData,"#black-tableForm-box",false); } }); } //點擊顯示黑名單彈窗 $(‘.serviceBtn .blackBtn‘).on(‘click‘,function(){ $(‘#mask‘).removeClass(‘hidden‘); //顯示數據 blacklistFn({"pageNum":1,"pageSize":10}); }) //勾選復選框點擊移除按鈕 $(‘#mask‘).on(‘click‘,‘#J_black_name_box #removeBtn‘,function(){ var trLine = $(‘#blackNameTable tr‘); for(var i = 0;i<trLine.length;i++){ if(trLine.eq(i).find(‘.subcheck‘).is(‘:checked‘)){ popInfotrue(); } } }) //是否將所選號碼移除黑名單 function popInfotrue(){ var tryebox = $(‘#J_info_true_box‘).clone(); $(‘#mask‘).append(tryebox); $(‘#J_info_true_box‘).show(); $(‘#mask‘).removeClass(‘hidden‘); } //點擊確定移除黑名單 $(‘#mask‘).on(‘click‘,‘#J_info_true_box .true‘,function(){ removeName(); $(‘#J_info_true_box‘).hide(); //移除黑名單管理請求數據 base.ajax({"type":"POST","url":"/ecapi/shortMessage/delBlacklist",‘data‘:{‘blackId‘:blackIdArry}},function(res){ if(res.record == 1200){ blacklistFn({"pageNum":1,"pageSize":10}); } }); }) function removeName(){ var trLine = $(‘#blackNameTable tr‘); for(var i = 0;i<trLine.length;i++){ if(trLine.eq(i).find(‘.subcheck‘).is(‘:checked‘)){ trLine.eq(i).remove(); } } } //點擊取消 $(‘#mask‘).on(‘click‘,‘#J_info_true_box .del‘,function(){ $(‘#J_info_true_box‘).hide(); }) //添加黑名單 $(‘#mask‘).on(‘keyup‘,‘#J_balckname‘,function(e){ var keycode = event.which; if (keycode == 13) { addBlackname(); } }); function addBlackname(){ //添加黑名單請求數據 var addBlacklistData = {}; addBlacklistData.number = $(‘#J_balckname‘).val(); base.ajax({"type":"POST","url":"/ecapi/shortMessage/addBlacklist",‘data‘:addBlacklistData},function(res){ if(res.record == 1200){ //base.alerts({"title":"提示","tip":"添加黑名單成功"},function(){}) base.popo(res.msg); blacklistFn({"pageNum":1,"pageSize":10}); }else if(res.record == 1500){ base.popo(res.msg); } }); } /* * 所有彈層關閉/取消 * 公用class="window-close/cancel" */ $("#mask").on(‘click‘,‘.window-close,.cancel‘,function(){ $(‘#mask‘).addClass(‘hidden‘).html(); }) /*==========================短信網關配置====================================================*/ base.ajax({"type":"GET","url":"/ecapi/shortMessage/checkGateway"},function(res){ if(res.record == 1200){ $(‘.congifSms-box‘).hide(); $(‘.smsService-box‘).show(); }else{ $(‘.smsService-box‘).hide(); $(‘.congifSms-box‘).show(); } }); function congifSmsFn(){ var param1Val = $(‘#param1‘).val(), param2Val = $(‘#param2‘).val(), param3Val = $(‘#param3‘).val(); if(param1Val == ‘‘ || param2Val == ‘‘ || param3Val == ‘‘){ $(‘.congifSms-box .btnWrapper .btn‘).addClass(‘greyBtn‘); $(‘.congifSms-box .btnWrapper .btn‘).removeClass(‘blueBtn‘); $(‘.congifSms-box .btnWrapper .btn‘).css(‘cursor‘,‘default‘); $(‘.congifSms-box .btnWrapper .btn‘).attr(‘disabled‘); }else{ $(‘.congifSms-box .btnWrapper .btn‘).removeClass(‘greyBtn‘); $(‘.congifSms-box .btnWrapper .btn‘).addClass(‘blueBtn‘); $(‘.congifSms-box .btnWrapper .btn‘).css(‘cursor‘,‘pointer‘); $(‘.congifSms-box .btnWrapper .btn‘).removeAttr(‘disabled‘); } } $(‘#param1,#param2,#param3‘).keydown(function(){ congifSmsFn(); }) $(‘#param1,#param2,#param3‘).keyup(function(){ congifSmsFn(); }) //點擊確定保存 $(‘.congifSms-box‘).on(‘click‘,‘#sureBtn‘,function(){ var shortGateWayData = {}; shortGateWayData.param1 = $(‘#param1‘).val(); shortGateWayData.param2 = $(‘#param2‘).val(); shortGateWayData.param3 = $(‘#param3‘).val(); base.ajax({"type":"POST","url":"/ecapi/shortMessage/shortGateWay",‘data‘:shortGateWayData},function(res){ if(res.record == 1200){ $(‘.congifSms-box‘).hide(); $(‘.smsService-box‘).show(); base.popo(res.msg); }else{ $(‘.smsService-box‘).hide(); $(‘.congifSms-box‘).show(); base.popo(res.msg); } }); }) } return { init:init }; })

剛使用requrie.js時的代碼