UNPKG

igi_orion_cignacmb

Version:

Censors words out of text

389 lines (382 loc) 16 kB
/* * @Author: weicong.ling * @Date: 2020-04-23 16:41:20 * @Last Modified by: weicong.ling * @Last Modified time: 2020-05-11 10:57:39 */ var centralController = { handleTips: function ($, errs, callback) { try { var that = this; var typeOfError = typeof errs; if (typeOfError == 'object') { if (errs instanceof Array) { for (var i = 0; i < errs.length; i++) { var err = errs[i]; if (err.code && err.code == -401) { that.handleTips(err.msg) } else { that.handleSingleTipsByType($, errs[0]) } } } else { that.handleSingleTipsByType($, errs) } } else if (typeOfError == 'string') { modal.open({ text: errs, buttons: [ { text: '确定', callback: function () { } } ] }) } } catch (e) { alert(e) } }, handleSingleTipsByType: function ($, err) { var that = this; try { if (err.type == 'alert') { alert(err.msg) } else if (err.type == 'tooltip') { if (err.id) { $('#' + err.id).attr('title', err.msg); $('#' + err.id).attr('data-original-title', err.msg); $('#' + err.id).tooltip(); $('#' + err.id).tooltip('show', { title: err.msg }); $('html,body').animate({ scrollTop: $('#' + err.id).offset().top - 300 }, '400') setTimeout(function () { $('#' + err.id).tooltip('destroy'); }, 5000) } } else if (err.type == 'popover') { $('#' + err.id) .addClass('errorClass') .attr('data-toggle', 'popover') .attr('data-placement', 'top') .attr('data-content', err.msg) .popover('show') $('html,body').animate({ scrollTop: $('#' + err.id).offset().top - 300 }, '400') var timer = setTimeout(function () { $('#' + err.id).popover('destroy') .removeClass('errorClass') clearTimeout(timer) }, 3000) } else if (err.type == 'popover_and_red') { $('#' + err.id) .addClass('error_red') .attr('data-toggle', 'popover') .attr('data-placement', 'top') .attr('data-content', err.msg) .popover('show') $('html,body').animate({ scrollTop: $('#' + err.id).offset().top - 300 }, '400') var timer = setTimeout(function () { $('#' + err.id).popover('destroy') .removeClass('error_red') clearTimeout(timer) }, 3000) } else if (err.type == 'modal') { if (err.callback) { modal.open({ text: err.msg, buttons: [ { text: '确定', callback: err.callback } ] }) } else { modal.open({ text: err.msg, buttons: [ { text: '确定' } ] }) } } else if (err.type == 'toast') { if (err.msg) { toast.open(err.msg, err.callback) } else { toast.open(err.msg) } } else if (err.type == 'jump') { window.location.href = err.data; } } catch (e) { alert(e) } }, setSelectHtmlForId: function ($, isId, htmlId, allSelects, defaultSelectsHtml, defaultSelectsValue, chooseSelectsValue, keyValue) { var result = { isId: isId ? isId : false, htmlId: htmlId ? htmlId : '',//需要设置的id allSelects: allSelects ? allSelects : '',//全部可选内容 defaultSelectsHtml: defaultSelectsHtml ? defaultSelectsHtml : '',//默认未选中的情况 defaultSelectsValue: defaultSelectsValue ? defaultSelectsValue : '',//默认未选中的情况 chooseSelectsValue: chooseSelectsValue ? chooseSelectsValue : '',//选中的内容 needAddHtml: '',//需要设置的html内容 }; if (defaultSelectsHtml) { result.needAddHtml = '<option value=' + result.defaultSelectsValue + '>' + result.defaultSelectsHtml + '</option>'; } for (var i = 0; i < result.allSelects.length; i++) { var item = result.allSelects[i]; if (item[keyValue.key] == result.chooseSelectsValue) { result.needAddHtml += '<option value="' + item[keyValue.key] + '" selected>' + item[keyValue.value] + '</option>' } else { result.needAddHtml += '<option value="' + item[keyValue.key] + '">' + item[keyValue.value] + '</option>' } } if (result.isId) { $("#" + result.htmlId).html(result.needAddHtml) } else { $("." + result.htmlId).html(result.needAddHtml) } }, testMobileOrPc: function ($) { try { var width = 0; if (document.body.clientWidth > window.screen.availWidth) { width = window.screen.availWidth } else { width = document.body.clientWidth } if (width < 768) { window.mobile = true window.terminalType = "mobile"; } else { window.mobile = false window.terminalType = "pc"; } $(window).resize(function () { var width = 0; if (document.body.clientWidth > window.screen.availWidth) { width = window.screen.availWidth } else { width = document.body.clientWidth } if (width < 768) { window.mobile = true window.terminalType = "mobile"; } else { window.mobile = false window.terminalType = "pc"; } }) } catch (e) { alert(e) } }, getAge: function (startDate, birthday) { try { var r = birthday.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/); if (r == null) return false; var birth = new Date(r[1], r[3] - 1, r[4]); if (birth.getFullYear() == r[1] && (birth.getMonth() + 1) == r[3] && birth.getDate() == r[4]) { var today = new Date(startDate); var age = today.getFullYear() - r[1]; if (today.getMonth() > birth.getMonth()) { return age; } if (today.getMonth() == birth.getMonth()) { if (today.getDate() >= birth.getDate()) { return age; } else { return age - 1; } } if (today.getMonth() < birth.getMonth()) { return age - 1; } } } catch (e) { return ("输入的日期格式错误!"); } }, checkIdCard: function (idcard) { var Y, JYM, JYM_X, ereg, Errors, area, S, M, M_X, idcard_array; if (idcard === '') { return false; } Errors = [true, false, false, false, false]; area = { 11: "北京", 12: "天津", 13: "河北", 14: "山西", 15: "内蒙古", 21: "辽宁", 22: "吉林", 23: "黑龙江", 31: "上海", 32: "江苏", 33: "浙江", 34: "安徽", 35: "福建", 36: "江西", 37: "山东", 41: "河南", 42: "湖北", 43: "湖南", 44: "广东", 45: "广西", 46: "海南", 50: "重庆", 51: "四川", 52: "贵州", 53: "云南", 54: "西藏", 61: "陕西", 62: "甘肃", 63: "青海", 64: "宁夏", 65: "新疆", // 71: "台湾", // 81: "香港", 82: "澳门", 91: "国外" }; //先看在不在36个省里 //再看是不是是1 idcard_array = idcard.split(""); /*地区检验*/ if (area[parseInt(idcard.substr(0, 2))] == null) { return Errors[4]; } /*身份号码位数及格式检验*/ switch (idcard.length) { case 15: if ((parseInt(idcard.substr(6, 2)) + 1900) % 4 == 0 || ((parseInt(idcard.substr(6, 2)) + 1900) % 100 == 0 && (parseInt(idcard.substr(6, 2)) + 1900) % 400 == 0)) { ereg = /^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}$/;//测试出生日期的合法性 } else { ereg = /^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}$/;//测试出生日期的合法性 } if (ereg.test(idcard)) { return 15; //15位验证通过 } else { return Errors[2]; } break; case 18: //18位身份号码检测 //出生日期的合法性检查 //闰年月日:((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9])) //平年月日:((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8])) if (parseInt(idcard.substr(6, 4)) % 4 == 0 || (parseInt(idcard.substr(6, 4)) % 100 == 0 && parseInt(idcard.substr(6, 4)) % 4 == 0)) { ereg = /^[1-9][0-9]{5}(19|20)[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}[0-9Xx]$/;//闰年出生日期的合法性正则表达式 } else { ereg = /^[1-9][0-9]{5}(19|20)[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}[0-9Xx]$/;//平年出生日期的合法性正则表达式 } if (ereg.test(idcard)) {//测试出生日期的合法性 //计算校验位 S = (parseInt(idcard_array[0]) + parseInt(idcard_array[10])) * 7 + (parseInt(idcard_array[1]) + parseInt(idcard_array[11])) * 9 + (parseInt(idcard_array[2]) + parseInt(idcard_array[12])) * 10 + (parseInt(idcard_array[3]) + parseInt(idcard_array[13])) * 5 + (parseInt(idcard_array[4]) + parseInt(idcard_array[14])) * 8 + (parseInt(idcard_array[5]) + parseInt(idcard_array[15])) * 4 + (parseInt(idcard_array[6]) + parseInt(idcard_array[16])) * 2 + parseInt(idcard_array[7]) + parseInt(idcard_array[8]) * 6 + parseInt(idcard_array[9]) * 3; Y = S % 11; M = "F"; JYM = "10x98765432"; JYM_X = "10X98765432"; M = JYM.substr(Y, 1); /*判断校验位*/ M_X = JYM_X.substr(Y, 1); /*判断校验位*/ if (M == idcard_array[17] || M_X == idcard_array[17]) { return 1; /*检测ID的校验位false;*/ } else { return Errors[3]; } } else { return Errors[2]; } break; default: return Errors[1]; break; } }, /** * 检查根据身份证检查性别是否匹配 * @param {检查根据身份证检查性别是否匹配} psidno */ getSex: function (psidno) { var sexno, sex; if (psidno.length == 18) { sexno = psidno.substring(16, 17) } else if (psidno.length == 15) { sexno = psidno.substring(14, 15) } else { return false } var tempid = sexno % 2; if (tempid == 0) { sex = 1; //返回女 } else { sex = 0; //返回男 } return sex }, checkSexAndId: function (ic_number, gender) { var that = this; var sex = that.getSex(ic_number); if (sex != gender) { return false; } else { return true; } }, getBirthdatByIdNo: function (idNumber, type) {//根据身份证号获取生日 var that = this; if(!idNumber && (!type || type == -1)){ return false; } var that = this; var tmpStr = ""; var idDate = ""; var tmpInt = 0; var strReturn = ""; var trim = function (s) { return s.replace(/^\s+|\s+$/g, ""); }; idNumber = trim(idNumber); if (type == 'G') { } else { if (!that.checkIdCard(idNumber)) { strReturn = "输入的证件号格式错误"; return false; } } if (idNumber.length == 15) { tmpStr = idNumber.substring(6, 12); tmpStr = "19" + tmpStr; tmpStr = tmpStr.substring(0, 4) + "-" + tmpStr.substring(4, 6) + "-" + tmpStr.substring(6) return tmpStr; } else { tmpStr = idNumber.substring(6, 14); tmpStr = tmpStr.substring(0, 4) + "-" + tmpStr.substring(4, 6) + "-" + tmpStr.substring(6) return tmpStr; } }, getSexByIdNum: function (idNumber,cur_sex) {//根据身份证号获取性别 var sexno; var sex; if (cur_sex) { sex = cur_sex; } else { sex = '0'; } if (idNumber.length == 18) { sexno = idNumber.substring(16, 17) } else if (idNumber.length == 15) { sexno = idNumber.substring(14, 15) } else { // alert("错误的身份证号码,请核对!") return sex } var tempid = sexno % 2; if (tempid == 0) { sex = '1'; //返回女 } else { sex = '0'; //返回男 } return sex }, }; module.exports = centralController