tools.js 13 KB

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