tools.js 14 KB

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