tools.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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. const getAllStr = (allData) =>{//获取界面数据,拼接字符串
  106. // console.log(allData,777777)
  107. let allStr = '',data = allData.data,allStrDoc = '',obj={};
  108. for(let i = 0;i < data.length;i++){
  109. if(data[i].controlType != 3&&data[i].value){
  110. allStr += (data[i].valueP).replace(patt,'').replace(/\#\{/g,'').replace(/\}/g,'')+';'
  111. allStrDoc += (data[i].value).replace(patt,'').replace(/\#\{/g,'').replace(/\}/g,'')+';'
  112. }
  113. if(data[i].controlType == 3){//多列选择
  114. let tmpStr = '',tmpDoc='';
  115. for(let j = 0;j < data[i].questionDetailList.length;j++){
  116. let tmpName = data[i].questionDetailList[j]
  117. if(tmpName&&tmpName.value&&tmpName.value!='/'){
  118. let obj = getModelExpStr(tmpName.name,'',tmpName.description)
  119. tmpStr+=obj.prefix+tmpName.valueP+obj.suffix+(j ==(data[i].questionDetailList.length-1)?';':',')
  120. tmpDoc+=obj.prefix+tmpName.value+obj.suffix+(j ==(data[i].questionDetailList.length-1)?';':',')
  121. }
  122. }
  123. allStr+=tmpStr
  124. allStrDoc+=tmpDoc
  125. }
  126. }
  127. obj.allStr = trimDots(allStr)
  128. obj.allStrDoc = trimDots(allStrDoc)
  129. return obj;
  130. }
  131. const moduleCP = {
  132. 'symp':1, //症状情况
  133. 'diagT':51, //诊疗情况
  134. 'other':3, //其他史
  135. 'suplement':52,//补充内容
  136. }
  137. const moduleConfig = (config,modules) => {
  138. let activeModule = []
  139. for(let i = 0;i < config.length;i++){
  140. let tmpCode = config[i].code
  141. let tmpVal = config[i].value
  142. for(let j = 0;j < modules.length;j++){
  143. let tmpType = modules[j].type
  144. if(tmpCode=="symptoms_show"&&tmpType==moduleCP['symp']&&tmpVal==1){
  145. activeModule.push(modules[j])
  146. }else if(tmpCode=="diagnosis_show"&&tmpType==moduleCP['diagT']&&tmpVal==1){
  147. activeModule.push(modules[j])
  148. }else if(tmpCode=="omhistory_show"&&tmpType==moduleCP['other']&&tmpVal==1){
  149. activeModule.push(modules[j])
  150. }else if(tmpCode=="replenish_show"&&tmpType==moduleCP['suplement']&&tmpVal==1){
  151. activeModule.push(modules[j])
  152. }
  153. }
  154. }
  155. return {
  156. data:activeModule,
  157. len:activeModule.length||0,
  158. order:activeModule.length>0?activeModule[0].type:''
  159. }
  160. }
  161. // 判断是安卓还是ios
  162. function isIos(){
  163. if (/iphone|ipad/i.test(navigator.userAgent.toLowerCase())) {
  164. return true;
  165. } else {
  166. return false;
  167. }
  168. }
  169. // 监听键盘是否弹起
  170. function fixedKeyboard() {
  171. var win_h = $(window).height();
  172. $(window).on("resize",function(){
  173. if(!isIos()) {
  174. //安卓触发window.resize
  175. if($(window).height() < win_h){
  176. $('.detailBox-wrap').css('position','static') ;//详情页
  177. $('.main').height((win_h)/100+'rem');
  178. }else{
  179. $('.detailBox-wrap').css('position','fixed');
  180. // $('.main').css('height','100%;') ;
  181. $('.main').height("100%") ;
  182. }
  183. }
  184. })
  185. $(window).on("click",function(){
  186. if(!isIos()){//安卓才跳转,ios已自动跳转
  187. const { activeElement } = document;
  188. if (activeElement.tagName === 'INPUT' || activeElement.tagName === 'TEXTAREA') {
  189. setTimeout(() => {
  190. activeElement.scrollIntoView(true);
  191. let top = $('.main').scrollTop();
  192. $('.main').scrollTop(top-30); //预留题目位置
  193. }, 400);
  194. }
  195. }
  196. })
  197. }
  198. // 移动到可视区--选项中的输入框,因阻止了冒泡
  199. function scrollToV(e){
  200. setTimeout(function() {
  201. // e.target.scrollIntoView(false);
  202. e.target.scrollIntoView(true); //true--元素顶部与可视区顶部对齐;false--元素底部与可视区底部对齐
  203. let mainH = $('.main').height();
  204. let top = $('.main').scrollTop();
  205. $('.main').scrollTop(top-30); //预留题目位置
  206. /*let HH = mainH-clientY;
  207. if(clientY < 210 || (mainH-clientY)>88){
  208. e.target.scrollIntoView(false); //底部对齐
  209. }else if(HH < 200){
  210. e.target.scrollIntoView(true);//顶部对齐
  211. }
  212. else{
  213. e.target.scrollIntoView();
  214. }*/
  215. }, 400)
  216. }
  217. function trimDots(str){
  218. return str.replace(/[,,.。::"“??”;;、!!]+/g,function(word){
  219. return word.substr(0,1);
  220. }).replace(/^[,,.。::"“??”;;、!!\s]+/,'');
  221. }
  222. // 拼值,并去掉占位符
  223. function concatVal(data){
  224. let value = ""; //医生
  225. let valueP = ""; //患者
  226. for(let k in data){
  227. if(data[k].select==1){
  228. if(data[k].value){
  229. let str = data[k].name.replace(patt,data[k].value);
  230. let strP = (data[k].description || data[k].name).replace(patt,data[k].value);
  231. value += str + ',';
  232. valueP += strP + ',';
  233. }else{
  234. value += data[k].name.replace(patt,'') + ',';
  235. valueP += (data[k].description || data[k].name).replace(patt,'') + ',';
  236. }
  237. }
  238. }
  239. return {value,valueP};
  240. }
  241. module.exports = {
  242. imageUrlPrefix,
  243. getUrlArgObject,
  244. deepClone,
  245. getModelExpStr,
  246. getAllStr,
  247. moduleConfig,
  248. patt,
  249. moduleCP,
  250. getExpStr,
  251. fixedKeyboard,
  252. scrollToV,
  253. isIos,
  254. trimDots,
  255. concatVal
  256. }