tools.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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. // 是否QQ浏览器
  203. function isQQ(){
  204. let us = navigator.userAgent.toLowerCase();
  205. // if(us.indexOf(' qq')>-1 && us.indexOf('mqqbrowser') <0){
  206. if(us.indexOf(' qq')>-1){
  207. return true;
  208. }else{
  209. return false;
  210. }
  211. }
  212. // 监听键盘是否弹起
  213. function fixedKeyboard() {
  214. var win_h = $(window).height();
  215. $(window).on("resize",function(){
  216. if(!isIos()) {
  217. //安卓触发window.resize
  218. if($(window).height() < win_h){
  219. $('.detailBox-wrap').css('position','static') ;//详情页
  220. $('.main').height((win_h)/100+'rem');
  221. }else{
  222. $('.detailBox-wrap').css('position','fixed');
  223. // $('.main').css('height','100%;') ;
  224. $('.main').height("100%");
  225. }
  226. }
  227. })
  228. $(window).on("click",function(){
  229. if(!isIos()){//安卓才跳转,ios已自动跳转
  230. const { activeElement } = document;
  231. if (activeElement.tagName === 'INPUT' || activeElement.tagName === 'TEXTAREA') {
  232. setTimeout(() => {
  233. activeElement.scrollIntoView(true);
  234. let top = $('.main').scrollTop();
  235. let tops = $('.detailBoxMain').css("transform").replace(/[^0-9\-,]/g,'').split(',')[5];
  236. // console.log(tops,4444)
  237. $('.main').scrollTop(top-30); //预留题目位置
  238. $('.detailBoxMain').css({"transform":'translate(0px, -'+tops+'"30") scale(1) translateZ("0px")'}); // translate(0px, -47px) scale(1) translateZ(0px);
  239. }, 400);
  240. }
  241. }
  242. })
  243. }
  244. // 移动到可视区--选项中的输入框,因阻止了冒泡
  245. function scrollToV(e){
  246. // setTimeout(function() {
  247. // // e.target.scrollIntoView(false);
  248. // e.target.scrollIntoView(true); //true--元素顶部与可视区顶部对齐;false--元素底部与可视区底部对齐
  249. // let mainH = $('.main').height();
  250. // let top = $('.main').scrollTop();
  251. // $('.main').scrollTop(top-30); //预留题目位置
  252. // /*let HH = mainH-clientY;
  253. // if(clientY < 210 || (mainH-clientY)>88){
  254. // e.target.scrollIntoView(false); //底部对齐
  255. // }else if(HH < 200){
  256. // e.target.scrollIntoView(true);//顶部对齐
  257. // }
  258. // else{
  259. // e.target.scrollIntoView();
  260. // }*/
  261. // }, 400)
  262. }
  263. function trimDots(str){
  264. return str.replace(/[,,.。::"“??”‘’'';;、!!]+/g,function(word){
  265. return word.substr(0,1);
  266. }).replace(/^[,,.。::"“??”‘’'';;、!!\s]+/,'');
  267. }
  268. // 拼值,并去掉占位符
  269. function concatVal(data,flg){
  270. let value = ""; //医生
  271. let valueP = ""; //患者
  272. let tmpStrHas = [],tmpStrNo = [],tmpAll=[];
  273. if(flg){
  274. tmpStrHas = data.filter((item)=>(item.select == 1&&item.flg==1))
  275. tmpStrNo = data.filter((item)=>(item.select == 1&&item.flg == 2))
  276. // tmpAll = tmpStrHas.concat(tmpStrNo)
  277. let valH='',valN='',valPH='',valPN='';
  278. for(let k in tmpStrHas){
  279. valH += tmpStrHas[k].name.replace(patt,'') + ',';
  280. valPH += (tmpStrHas[k].description || tmpStrHas[k].name).replace(patt,'') + ',';
  281. }
  282. for(let k in tmpStrNo){
  283. valN += tmpStrNo[k].name.replace(patt,'') + ',';
  284. valPN += (tmpStrNo[k].description || tmpStrNo[k].name).replace(patt,'') + ',';
  285. }
  286. // console.log(valN)
  287. value = ((valH!='')?('有:'+valH):'')+((valN!='')?('无:'+valN):'');
  288. valueP = ((valPH!='')?('有:'+valPH):'')+((valPN!='')?('无:'+valPN):'');
  289. }else{
  290. for(let k in data){
  291. if(data[k].select){
  292. if(data[k].value){
  293. let str = data[k].name.replace(patt,data[k].value);
  294. let strP = (data[k].description || data[k].name).replace(patt,data[k].value);
  295. value += str + ',';
  296. valueP += strP + ',';
  297. }else{
  298. value += data[k].name.replace(patt,'') + ',';
  299. valueP += (data[k].description || data[k].name).replace(patt,'') + ',';
  300. }
  301. }
  302. }
  303. }
  304. // 去掉最后一个逗号
  305. return {value:value?value.substring(0,value.length-1):'',valueP:valueP?valueP.substring(0,valueP.length-1):''};
  306. }
  307. function setScroll(scroll,flg,wrapper){
  308. return new scroll(wrapper?wrapper:'.wrapper',{
  309. scrollY: flg,
  310. click: true,
  311. tap: true,
  312. probeType:3,
  313. // bounceTime:800,
  314. momentumLimitTime:300,//只有在屏幕上快速滑动的时间小于 momentumLimitTime,才能开启 momentum 动画。
  315. momentumLimitDistance:15,//只有在屏幕上快速滑动的距离大于 momentumLimitDistance,才能开启 momentum 动画。
  316. swipeTime:500,//设置 momentum 动画的动画时长
  317. deceleration:0.015,
  318. swipeBounceTime:500,
  319. bounce: {
  320. top: false,
  321. bottom: false,
  322. left: false,
  323. right: false
  324. }
  325. })
  326. }
  327. function compare(property){
  328. return function(obj1,obj2){
  329. var value1 = (new Date(obj1[property].replace(/\-/g, "/"))).getTime();
  330. var value2 = (new Date(obj2[property].replace(/\-/g, "/"))).getTime();
  331. return value1 - value2;
  332. }
  333. }
  334. // 时间戳转换日期
  335. function dateParser(timestamp,link = '-'){
  336. if(!timestamp){
  337. return ''
  338. }
  339. if(timestamp.length == 10){
  340. timestamp = timestamp*1000
  341. }
  342. let time = new Date(timestamp-0);
  343. let year = time.getFullYear();
  344. let month = time.getMonth()+1;
  345. let date = time.getDate();
  346. let hour = time.getHours().toString().padStart(2,'0');
  347. let minute = time.getMinutes().toString().padStart(2,'0');
  348. let second = time.getSeconds().toString().padStart(2,'0');
  349. let result = year+link+(month<10?"0"+month:month)+link+(date<10?"0"+date:date)+' '+hour+':'+minute+':'+second;
  350. return result;
  351. }
  352. // 获取01-99
  353. const getNum = () => {
  354. let num = [];
  355. for(let i = 1; i < 100; i++){
  356. num.push(i.toString().padStart(2,'0'));
  357. }
  358. return num;
  359. }
  360. module.exports = {
  361. imageUrlPrefix,
  362. getUrlArgObject,
  363. deepClone,
  364. getModelExpStr,
  365. getAllStr,
  366. moduleConfig,
  367. patt,
  368. moduleCP,
  369. getExpStr,
  370. fixedKeyboard,
  371. scrollToV,
  372. isIos,
  373. trimDots,
  374. concatVal,
  375. setScroll,
  376. isWX,
  377. phoneTest,
  378. identify,
  379. jgpattern,
  380. compare,
  381. dateParser,
  382. name,
  383. isQQ,
  384. getNum
  385. }