tools.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. const qs = require('qs');
  2. const $ = require('jquery');
  3. const imageUrlPrefix = 'http://192.168.2.241:82' //后台图片地址
  4. // const imageUrlPrefix = 'http://192.168.2.236:82' //后台图片地址
  5. const getUrlArgObject = (parm) => {
  6. let query = window.location.search;
  7. let args = qs.parse(query.substr(1));
  8. return args[parm];//返回对象
  9. }
  10. const deepClone = (arr) =>{
  11. let newArr = [];
  12. for(let i in arr){
  13. newArr.push(arr[i]);
  14. }
  15. return newArr;
  16. }
  17. const getExpStr = (str) =>{
  18. let result = {}
  19. if(str.match(/\${number_(.*})/)){//数字输入框
  20. let matchStr = str.match(/\${number_(.*})/)[0]
  21. result = {
  22. type:'number',
  23. placeholder:matchStr.split('${number_')[1].split('}')[0],
  24. prefix:str.split(matchStr)[0]||'',
  25. suffix:str.split(matchStr)[1]||''
  26. }
  27. }else if(str.match(/\${input_(.*})/)){
  28. let matchStr = str.match(/\${input_(.*})/)[0]
  29. result = {
  30. type:'text',
  31. placeholder:matchStr.split('${input_')[1].split('}')[0],
  32. prefix:str.split(matchStr)[0]||'',
  33. suffix:str.split(matchStr)[1]||''
  34. }
  35. }
  36. return result
  37. }
  38. // 多行输入 多个输入框
  39. const getModelExpStr = (str,txt,des) =>{
  40. let result = {}
  41. // console.log(str,txt,44444)
  42. if(str.match(/\${number_(.*})/)){//数字输入框
  43. let matchStr = str.match(/\${number_(.*})/)[0]
  44. let tmpHolder = matchStr.split('${number_')[1].split('}')[0]
  45. let iptLis = [],join='';
  46. if(tmpHolder.indexOf('/') != -1){
  47. let tmpHolderArr = tmpHolder.split('/')
  48. for(let i = 0;i < tmpHolderArr.length;i++){
  49. let obj={placeholder:'',value:''}
  50. let tmpData = tmpHolderArr[i];
  51. obj.placeholder=tmpData
  52. if(txt){
  53. obj.value=txt.split('/')[i]
  54. }
  55. iptLis.push(obj)
  56. }
  57. join = '/'
  58. }else{
  59. let obj={placeholder:'tmpHolder',value:txt}
  60. iptLis.push(obj)
  61. }
  62. result = {
  63. type:'number',
  64. placeholder:tmpHolder,
  65. iptLis:iptLis,
  66. join:join,
  67. prefix:str.split(matchStr)[0]||'',
  68. prefixDes:des&&des.split(matchStr)[0]||'',
  69. suffix:str.split(matchStr)[1]||'',
  70. }
  71. }else if(str.match(/\${input_(.*})/)){
  72. let matchStr = str.match(/\${input_(.*})/)[0]
  73. let tmpHolder = matchStr.split('${input_')[1].split('}')[0]
  74. let iptLis = [],join='';
  75. if(tmpHolder.indexOf('/') != -1){
  76. let tmpHolderArr = tmpHolder.split('/')
  77. for(let i = 0;i < tmpHolderArr.length;i++){
  78. let obj={placeholder:'',value:''}
  79. let tmpData = tmpHolderArr[i];
  80. obj.placeholder=tmpData
  81. if(txt){
  82. obj.value=txt.split('/')[i]
  83. }
  84. iptLis.push(obj)
  85. }
  86. join = '/'
  87. }else{
  88. let obj={placeholder:'tmpHolder',value:txt}
  89. iptLis.push(obj)
  90. }
  91. result = {
  92. type:'text',
  93. placeholder:tmpHolder,
  94. iptLis:iptLis,
  95. join:join,
  96. prefix:str.split(matchStr)[0]||'',
  97. prefixDes:des&&des.split(matchStr)[0]||'',
  98. suffix:str.split(matchStr)[1]||'',
  99. }
  100. }
  101. return result
  102. }
  103. // 替换输入框占位符
  104. const patt = /\$\{[^\]]+\}/g;
  105. // 手机号验证
  106. const phoneTest = /^[1]([3-9])[0-9]{9}$/;
  107. //身份证验证
  108. /**15位
  109. * [1-9]\d{5}                  前六位地区,非0打头    
  110. * \d{2}                       出生年份后两位00-99
  111. * ((0[1-9])|(10|11|12))       月份,01-12月
  112. * (([0-2][1-9])|10|20|30|31)  日期,01-31天
  113. * \d{2}[0-9Xx]                顺序码两位,一位校验码最后一位数字或者大小写X
  114. */
  115. /**18位
  116. *
  117. *
  118. * [1-9]\d{5}                 前六位地区,非0打头
  119. * (18|19|([23]\d))\d{2}      出身年份,覆盖范围为 1800-3999 年
  120. * ((0[1-9])|(10|11|12))      月份,01-12月
  121. * (([0-2][1-9])|10|20|30|31) 日期,01-31天
  122. * \d{3}[0-9Xx]:              顺序码三位, 一位校验码数字或者大小写X
  123. */
  124. 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]$)/;
  125. //只能是数字和字母
  126. const jgpattern = /^[A-Za-z0-9]+$/;
  127. //名字汉字字母
  128. const name = /^[0-9\u4e00-\u9fa5]+$/;
  129. const getAllStr = (allData) =>{//获取界面数据,拼接字符串
  130. // console.log(allData,777777)
  131. let allStr = '',data = allData.data,allStrDoc = '',obj={};
  132. for(let i = 0;i < data.length;i++){
  133. if(data[i].controlType != 3&&data[i].value){
  134. allStr += (data[i].valueP).replace(patt,'').replace(/\#\{/g,'').replace(/\}/g,'')+','
  135. allStrDoc += (data[i].value).replace(patt,'').replace(/\#\{/g,'').replace(/\}/g,'')+','
  136. }
  137. if(data[i].controlType == 3){//多列选择
  138. let tmpStr = '',tmpDoc='';
  139. for(let j = 0;j < data[i].questionDetailList.length;j++){
  140. let tmpName = data[i].questionDetailList[j]
  141. if(tmpName&&tmpName.value&&tmpName.value!='/'){
  142. let obj = getModelExpStr(tmpName.name,'',tmpName.description)
  143. tmpStr+=obj.prefix+tmpName.valueP+obj.suffix+','
  144. tmpDoc+=obj.prefix+tmpName.value+obj.suffix+','
  145. }
  146. }
  147. allStr+=tmpStr
  148. allStrDoc+=tmpDoc
  149. }
  150. }
  151. obj.allStr = trimDots(allStr.replace(/,$/,''))
  152. obj.allStrDoc = trimDots(allStrDoc.replace(/,$/,''))
  153. return obj;
  154. }
  155. const moduleCP = {
  156. 'symp':1, //症状情况
  157. 'diagT':51, //诊疗情况
  158. 'other':3, //其他史
  159. 'suplement':52,//补充内容
  160. }
  161. const moduleConfig = (config,modules) => {
  162. let activeModule = []
  163. for(let i = 0;i < config.length;i++){
  164. let tmpCode = config[i].code
  165. let tmpVal = config[i].value
  166. for(let j = 0;j < modules.length;j++){
  167. let tmpType = modules[j].type
  168. if(tmpCode=="symptoms_show"&&tmpType==moduleCP['symp']&&tmpVal==1){
  169. activeModule.push(modules[j])
  170. }else if(tmpCode=="diagnosis_show"&&tmpType==moduleCP['diagT']&&tmpVal==1){
  171. activeModule.push(modules[j])
  172. }else if(tmpCode=="omhistory_show"&&tmpType==moduleCP['other']&&tmpVal==1){
  173. activeModule.push(modules[j])
  174. }else if(tmpCode=="replenish_show"&&tmpType==moduleCP['suplement']&&tmpVal==1){
  175. activeModule.push(modules[j])
  176. }
  177. }
  178. }
  179. return {
  180. data:activeModule,
  181. len:activeModule.length||0,
  182. order:activeModule.length>0?activeModule[0].type:''
  183. }
  184. }
  185. // 判断是安卓还是ios
  186. function isIos(){
  187. if (/iphone|ipad/i.test(navigator.userAgent.toLowerCase())) {
  188. return true;
  189. } else {
  190. return false;
  191. }
  192. }
  193. // 是否在微信打开
  194. function isWX(){
  195. let us = navigator.userAgent.toLowerCase();
  196. if(us.indexOf('micromessenger') == -1){
  197. return false;
  198. }else{
  199. return true;
  200. }
  201. }
  202. // 监听键盘是否弹起
  203. function fixedKeyboard() {
  204. var win_h = $(window).height();
  205. $(window).on("resize",function(){
  206. if(!isIos()) {
  207. //安卓触发window.resize
  208. if($(window).height() < win_h){
  209. $('.detailBox-wrap').css('position','static') ;//详情页
  210. $('.main').height((win_h)/100+'rem');
  211. }else{
  212. $('.detailBox-wrap').css('position','fixed');
  213. // $('.main').css('height','100%;') ;
  214. $('.main').height("100%") ;
  215. }
  216. }
  217. })
  218. $(window).on("click",function(){
  219. if(!isIos()){//安卓才跳转,ios已自动跳转
  220. const { activeElement } = document;
  221. if (activeElement.tagName === 'INPUT' || activeElement.tagName === 'TEXTAREA') {
  222. setTimeout(() => {
  223. activeElement.scrollIntoView(true);
  224. let top = $('.main').scrollTop();
  225. let tops = $('.detailBoxMain').css("transform").replace(/[^0-9\-,]/g,'').split(',')[5];
  226. console.log(tops,4444)
  227. $('.main').scrollTop(top-30); //预留题目位置
  228. $('.detailBoxMain').css({"transform":'translate(0px, -'+tops+'"30") scale(1) translateZ("0px")'}); // translate(0px, -47px) scale(1) translateZ(0px);
  229. }, 400);
  230. }
  231. }
  232. })
  233. }
  234. // 移动到可视区--选项中的输入框,因阻止了冒泡
  235. function scrollToV(e){
  236. // setTimeout(function() {
  237. // // e.target.scrollIntoView(false);
  238. // e.target.scrollIntoView(true); //true--元素顶部与可视区顶部对齐;false--元素底部与可视区底部对齐
  239. // let mainH = $('.main').height();
  240. // let top = $('.main').scrollTop();
  241. // $('.main').scrollTop(top-30); //预留题目位置
  242. // /*let HH = mainH-clientY;
  243. // if(clientY < 210 || (mainH-clientY)>88){
  244. // e.target.scrollIntoView(false); //底部对齐
  245. // }else if(HH < 200){
  246. // e.target.scrollIntoView(true);//顶部对齐
  247. // }
  248. // else{
  249. // e.target.scrollIntoView();
  250. // }*/
  251. // }, 400)
  252. }
  253. function trimDots(str){
  254. return str.replace(/[,,.。::"“??”‘’'';;、!!]+/g,function(word){
  255. return word.substr(0,1);
  256. }).replace(/^[,,.。::"“??”‘’'';;、!!\s]+/,'');
  257. }
  258. // 拼值,并去掉占位符
  259. function concatVal(data,flg){
  260. let value = ""; //医生
  261. let valueP = ""; //患者
  262. let tmpStrHas = [],tmpStrNo = [],tmpAll=[];
  263. if(flg){
  264. tmpStrHas = data.filter((item)=>item.select == 1)
  265. tmpStrNo = data.filter((item)=>item.select == 2)
  266. tmpAll = tmpStrHas.concat(tmpStrNo)
  267. for(let k in tmpAll){
  268. let tmpStr = tmpAll[k].select==1?'有':'无';
  269. value += tmpStr+tmpAll[k].name.replace(patt,'') + ',';
  270. valueP += tmpStr+(tmpAll[k].description || tmpAll[k].name).replace(patt,'') + ',';
  271. }
  272. }else{
  273. for(let k in data){
  274. if(data[k].select){
  275. if(data[k].value){
  276. let str = data[k].name.replace(patt,data[k].value);
  277. let strP = (data[k].description || data[k].name).replace(patt,data[k].value);
  278. value += str + ',';
  279. valueP += strP + ',';
  280. }else{
  281. value += data[k].name.replace(patt,'') + ',';
  282. valueP += (data[k].description || data[k].name).replace(patt,'') + ',';
  283. }
  284. }
  285. }
  286. }
  287. // 去掉最后一个逗号
  288. return {value:value?value.substring(0,value.length-1):'',valueP:valueP?valueP.substring(0,valueP.length-1):''};
  289. }
  290. function setScroll(scroll,flg,wrapper){
  291. return new scroll(wrapper?wrapper:'.wrapper',{
  292. scrollY: flg,
  293. click: true,
  294. probeType:3,
  295. bounceTime:500
  296. })
  297. }
  298. function compare(property){
  299. return function(obj1,obj2){
  300. var value1 = (new Date(obj1[property].replace(/\-/g, "/"))).getTime();
  301. var value2 = (new Date(obj2[property].replace(/\-/g, "/"))).getTime();
  302. return value1 - value2;
  303. }
  304. }
  305. // 时间戳转换日期
  306. function dateParser(timestamp,link = '-'){
  307. if(!timestamp){
  308. return ''
  309. }
  310. if(timestamp.length == 10){
  311. timestamp = timestamp*1000
  312. }
  313. let time = new Date(timestamp-0);
  314. let year = time.getFullYear();
  315. let month = time.getMonth()+1;
  316. let date = time.getDate();
  317. let hour = time.getHours().toString().padStart(2,'0');
  318. let minute = time.getMinutes().toString().padStart(2,'0');
  319. let second = time.getSeconds().toString().padStart(2,'0');
  320. let result = year+link+(month<10?"0"+month:month)+link+(date<10?"0"+date:date)+' '+hour+':'+minute+':'+second;
  321. return result;
  322. }
  323. module.exports = {
  324. imageUrlPrefix,
  325. getUrlArgObject,
  326. deepClone,
  327. getModelExpStr,
  328. getAllStr,
  329. moduleConfig,
  330. patt,
  331. moduleCP,
  332. getExpStr,
  333. fixedKeyboard,
  334. scrollToV,
  335. isIos,
  336. trimDots,
  337. concatVal,
  338. setScroll,
  339. isWX,
  340. phoneTest,
  341. identify,
  342. jgpattern,
  343. compare,
  344. dateParser,
  345. name
  346. }