const qs = require('qs'); const $ = require('jquery'); const imageUrlPrefix = 'http://192.168.2.241:82' //后台图片地址 // const imageUrlPrefix = 'http://192.168.2.236:82' //后台图片地址 const getUrlArgObject = (parm) => { let query = window.location.search; let args = qs.parse(query.substr(1)); return args[parm];//返回对象 } const deepClone = (arr) =>{ let newArr = []; for(let i in arr){ newArr.push(arr[i]); } return newArr; } const getExpStr = (str) =>{ let result = {} if(str.match(/\${number_(.*})/)){//数字输入框 let matchStr = str.match(/\${number_(.*})/)[0] result = { type:'number', placeholder:matchStr.split('${number_')[1].split('}')[0], prefix:str.split(matchStr)[0]||'', suffix:str.split(matchStr)[1]||'' } }else if(str.match(/\${input_(.*})/)){ let matchStr = str.match(/\${input_(.*})/)[0] result = { type:'text', placeholder:matchStr.split('${input_')[1].split('}')[0], prefix:str.split(matchStr)[0]||'', suffix:str.split(matchStr)[1]||'' } } return result } // 多行输入 多个输入框 const getModelExpStr = (str,txt,des) =>{ let result = {} // console.log(str,txt,44444) if(str.match(/\${number_(.*})/)){//数字输入框 let matchStr = str.match(/\${number_(.*})/)[0] let tmpHolder = matchStr.split('${number_')[1].split('}')[0] let iptLis = [],join=''; if(tmpHolder.indexOf('/') != -1){ let tmpHolderArr = tmpHolder.split('/') for(let i = 0;i < tmpHolderArr.length;i++){ let obj={placeholder:'',value:''} let tmpData = tmpHolderArr[i]; obj.placeholder=tmpData if(txt){ obj.value=txt.split('/')[i] } iptLis.push(obj) } join = '/' }else{ let obj={placeholder:'tmpHolder',value:txt} iptLis.push(obj) } result = { type:'number', placeholder:tmpHolder, iptLis:iptLis, join:join, prefix:str.split(matchStr)[0]||'', prefixDes:des&&des.split(matchStr)[0]||'', suffix:str.split(matchStr)[1]||'', } }else if(str.match(/\${input_(.*})/)){ let matchStr = str.match(/\${input_(.*})/)[0] let tmpHolder = matchStr.split('${input_')[1].split('}')[0] let iptLis = [],join=''; if(tmpHolder.indexOf('/') != -1){ let tmpHolderArr = tmpHolder.split('/') for(let i = 0;i < tmpHolderArr.length;i++){ let obj={placeholder:'',value:''} let tmpData = tmpHolderArr[i]; obj.placeholder=tmpData if(txt){ obj.value=txt.split('/')[i] } iptLis.push(obj) } join = '/' }else{ let obj={placeholder:'tmpHolder',value:txt} iptLis.push(obj) } result = { type:'text', placeholder:tmpHolder, iptLis:iptLis, join:join, prefix:str.split(matchStr)[0]||'', prefixDes:des&&des.split(matchStr)[0]||'', suffix:str.split(matchStr)[1]||'', } } return result } // 替换输入框占位符 const patt = /\$\{[^\]]+\}/g; // 手机号验证 const phoneTest = /^[1]([3-9])[0-9]{9}$/; //身份证验证 /**15位 * [1-9]\d{5}                  前六位地区,非0打头     * \d{2}                       出生年份后两位00-99 * ((0[1-9])|(10|11|12))       月份,01-12月 * (([0-2][1-9])|10|20|30|31)  日期,01-31天 * \d{2}[0-9Xx]                顺序码两位,一位校验码最后一位数字或者大小写X */ /**18位 * * * [1-9]\d{5}                 前六位地区,非0打头 * (18|19|([23]\d))\d{2}      出身年份,覆盖范围为 1800-3999 年 * ((0[1-9])|(10|11|12))      月份,01-12月 * (([0-2][1-9])|10|20|30|31) 日期,01-31天 * \d{3}[0-9Xx]:              顺序码三位, 一位校验码数字或者大小写X */ const identify = /(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}[0-9Xx]$)|(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)/; //只能是数字和字母 const jgpattern = /^[A-Za-z0-9]+$/; //名字汉字字母 const name = /^[0-9\u4e00-\u9fa5]+$/; const getAllStr = (allData) =>{//获取界面数据,拼接字符串 // console.log(allData,777777) let allStr = '',data = allData.data,allStrDoc = '',obj={}; for(let i = 0;i < data.length;i++){ if(data[i].controlType != 3&&data[i].value){ allStr += (data[i].valueP).replace(patt,'').replace(/\#\{/g,'').replace(/\}/g,'')+',' allStrDoc += (data[i].value).replace(patt,'').replace(/\#\{/g,'').replace(/\}/g,'')+',' } if(data[i].controlType == 3){//多列选择 let tmpStr = '',tmpDoc=''; for(let j = 0;j < data[i].questionDetailList.length;j++){ let tmpName = data[i].questionDetailList[j] if(tmpName&&tmpName.value&&tmpName.value!='/'){ let obj = getModelExpStr(tmpName.name,'',tmpName.description) tmpStr+=obj.prefix+tmpName.valueP+obj.suffix+',' tmpDoc+=obj.prefix+tmpName.value+obj.suffix+',' } } allStr+=tmpStr allStrDoc+=tmpDoc } } obj.allStr = trimDots(allStr.replace(/,$/,'')) obj.allStrDoc = trimDots(allStrDoc.replace(/,$/,'')) return obj; } const moduleCP = { 'symp':1, //症状情况 'diagT':51, //诊疗情况 'other':3, //其他史 'suplement':52,//补充内容 } const moduleConfig = (config,modules) => { let activeModule = [] for(let i = 0;i < config.length;i++){ let tmpCode = config[i].code let tmpVal = config[i].value for(let j = 0;j < modules.length;j++){ let tmpType = modules[j].type if(tmpCode=="symptoms_show"&&tmpType==moduleCP['symp']&&tmpVal==1){ activeModule.push(modules[j]) }else if(tmpCode=="diagnosis_show"&&tmpType==moduleCP['diagT']&&tmpVal==1){ activeModule.push(modules[j]) }else if(tmpCode=="omhistory_show"&&tmpType==moduleCP['other']&&tmpVal==1){ activeModule.push(modules[j]) }else if(tmpCode=="replenish_show"&&tmpType==moduleCP['suplement']&&tmpVal==1){ activeModule.push(modules[j]) } } } return { data:activeModule, len:activeModule.length||0, order:activeModule.length>0?activeModule[0].type:'' } } // 判断是安卓还是ios function isIos(){ if (/iphone|ipad/i.test(navigator.userAgent.toLowerCase())) { return true; } else { return false; } } // 是否在微信打开 function isWX(){ let us = navigator.userAgent.toLowerCase(); if(us.indexOf('micromessenger') == -1){ return false; }else{ return true; } } // 是否QQ浏览器 function isQQ(){ let us = navigator.userAgent.toLowerCase(); // if(us.indexOf(' qq')>-1 && us.indexOf('mqqbrowser') <0){ if(us.indexOf(' qq')>-1){ return true; }else{ return false; } } // 监听键盘是否弹起 function fixedKeyboard() { var win_h = $(window).height(); $(window).on("resize",function(){ if(!isIos()) { //安卓触发window.resize if($(window).height() < win_h){ $('.detailBox-wrap').css('position','static') ;//详情页 $('.main').height((win_h)/100+'rem'); }else{ $('.detailBox-wrap').css('position','fixed'); // $('.main').css('height','100%;') ; $('.main').height("100%"); } } }) $(window).on("click",function(){ if(!isIos()){//安卓才跳转,ios已自动跳转 const { activeElement } = document; if (activeElement.tagName === 'INPUT' || activeElement.tagName === 'TEXTAREA') { setTimeout(() => { activeElement.scrollIntoView(true); let top = $('.main').scrollTop(); let tops = $('.detailBoxMain').css("transform").replace(/[^0-9\-,]/g,'').split(',')[5]; // console.log(tops,4444) $('.main').scrollTop(top-30); //预留题目位置 $('.detailBoxMain').css({"transform":'translate(0px, -'+tops+'"30") scale(1) translateZ("0px")'}); // translate(0px, -47px) scale(1) translateZ(0px); }, 400); } } }) } // 移动到可视区--选项中的输入框,因阻止了冒泡 function scrollToV(e){ // setTimeout(function() { // // e.target.scrollIntoView(false); // e.target.scrollIntoView(true); //true--元素顶部与可视区顶部对齐;false--元素底部与可视区底部对齐 // let mainH = $('.main').height(); // let top = $('.main').scrollTop(); // $('.main').scrollTop(top-30); //预留题目位置 // /*let HH = mainH-clientY; // if(clientY < 210 || (mainH-clientY)>88){ // e.target.scrollIntoView(false); //底部对齐 // }else if(HH < 200){ // e.target.scrollIntoView(true);//顶部对齐 // } // else{ // e.target.scrollIntoView(); // }*/ // }, 400) } function trimDots(str){ return str.replace(/[,,.。::"“??”‘’'';;、!!]+/g,function(word){ return word.substr(0,1); }).replace(/^[,,.。::"“??”‘’'';;、!!\s]+/,''); } // 拼值,并去掉占位符 function concatVal(data,flg){ let value = ""; //医生 let valueP = ""; //患者 let tmpStrHas = [],tmpStrNo = [],tmpAll=[]; if(flg){ tmpStrHas = data.filter((item)=>(item.select == 1&&item.flg==1)) tmpStrNo = data.filter((item)=>(item.select == 1&&item.flg == 2)) // tmpAll = tmpStrHas.concat(tmpStrNo) let valH='',valN='',valPH='',valPN=''; for(let k in tmpStrHas){ valH += tmpStrHas[k].name.replace(patt,'') + ','; valPH += (tmpStrHas[k].description || tmpStrHas[k].name).replace(patt,'') + ','; } for(let k in tmpStrNo){ valN += tmpStrNo[k].name.replace(patt,'') + ','; valPN += (tmpStrNo[k].description || tmpStrNo[k].name).replace(patt,'') + ','; } // console.log(valN) value = ((valH!='')?('有:'+valH):'')+((valN!='')?('无:'+valN):''); valueP = ((valPH!='')?('有:'+valPH):'')+((valPN!='')?('无:'+valPN):''); }else{ for(let k in data){ if(data[k].select){ if(data[k].value){ let str = data[k].name.replace(patt,data[k].value); let strP = (data[k].description || data[k].name).replace(patt,data[k].value); value += str + ','; valueP += strP + ','; }else{ value += data[k].name.replace(patt,'') + ','; valueP += (data[k].description || data[k].name).replace(patt,'') + ','; } } } } // 去掉最后一个逗号 return {value:value?value.substring(0,value.length-1):'',valueP:valueP?valueP.substring(0,valueP.length-1):''}; } function setScroll(scroll,flg,wrapper){ return new scroll(wrapper?wrapper:'.wrapper',{ scrollY: flg, click: true, tap: true, probeType:3, // bounceTime:800, momentumLimitTime:300,//只有在屏幕上快速滑动的时间小于 momentumLimitTime,才能开启 momentum 动画。 momentumLimitDistance:15,//只有在屏幕上快速滑动的距离大于 momentumLimitDistance,才能开启 momentum 动画。 swipeTime:500,//设置 momentum 动画的动画时长 deceleration:0.015, swipeBounceTime:500, bounce: { top: false, bottom: false, left: false, right: false } }) } function compare(property){ return function(obj1,obj2){ var value1 = (new Date(obj1[property].replace(/\-/g, "/"))).getTime(); var value2 = (new Date(obj2[property].replace(/\-/g, "/"))).getTime(); return value1 - value2; } } // 时间戳转换日期 function dateParser(timestamp,link = '-'){ if(!timestamp){ return '' } if(timestamp.length == 10){ timestamp = timestamp*1000 } let time = new Date(timestamp-0); let year = time.getFullYear(); let month = time.getMonth()+1; let date = time.getDate(); let hour = time.getHours().toString().padStart(2,'0'); let minute = time.getMinutes().toString().padStart(2,'0'); let second = time.getSeconds().toString().padStart(2,'0'); let result = year+link+(month<10?"0"+month:month)+link+(date<10?"0"+date:date)+' '+hour+':'+minute+':'+second; return result; } // 获取01-99 const getNum = () => { let num = []; for(let i = 1; i < 100; i++){ num.push(i.toString().padStart(2,'0')); } return num; } module.exports = { imageUrlPrefix, getUrlArgObject, deepClone, getModelExpStr, getAllStr, moduleConfig, patt, moduleCP, getExpStr, fixedKeyboard, scrollToV, isIos, trimDots, concatVal, setScroll, isWX, phoneTest, identify, jgpattern, compare, dateParser, name, isQQ, getNum }