123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- 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 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+(j ==(data[i].questionDetailList.length-1)?';':',')
- tmpDoc+=obj.prefix+tmpName.value+obj.suffix+(j ==(data[i].questionDetailList.length-1)?';':',')
- }
- }
- allStr+=tmpStr
- allStrDoc+=tmpDoc
- }
- }
- obj.allStr = trimDots(allStr)
- obj.allStrDoc = trimDots(allStrDoc)
- 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 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();
- $('.main').scrollTop(top-30); //预留题目位置
- }, 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){
- let value = ""; //医生
- let valueP = ""; //患者
- for(let k in data){
- if(data[k].select==1){
- 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,valueP};
- }
- module.exports = {
- imageUrlPrefix,
- getUrlArgObject,
- deepClone,
- getModelExpStr,
- getAllStr,
- moduleConfig,
- patt,
- moduleCP,
- getExpStr,
- fixedKeyboard,
- scrollToV,
- isIos,
- trimDots,
- concatVal
- }
|