tools.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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) =>{
  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. suffix:str.split(matchStr)[1]||'',
  69. }
  70. }else if(str.match(/\${input_(.*})/)){
  71. let matchStr = str.match(/\${input_(.*})/)[0]
  72. let tmpHolder = matchStr.split('${input_')[1].split('}')[0]
  73. let iptLis = [],join='';
  74. if(tmpHolder.indexOf('/') != -1){
  75. let tmpHolderArr = tmpHolder.split('/')
  76. for(let i = 0;i < tmpHolderArr.length;i++){
  77. let obj={placeholder:'',value:''}
  78. let tmpData = tmpHolderArr[i];
  79. obj.placeholder=tmpData
  80. if(txt){
  81. obj.value=txt.split('/')[i]
  82. }
  83. iptLis.push(obj)
  84. }
  85. join = '/'
  86. }else{
  87. let obj={placeholder:'tmpHolder',value:txt}
  88. iptLis.push(obj)
  89. }
  90. result = {
  91. type:'text',
  92. placeholder:tmpHolder,
  93. iptLis:iptLis,
  94. join:join,
  95. prefix:str.split(matchStr)[0]||'',
  96. suffix:str.split(matchStr)[1]||'',
  97. }
  98. }
  99. return result
  100. }
  101. // 替换输入框占位符
  102. const patt = /\$\{[^\]]+\}/g;
  103. const getAllStr = (allData) =>{//获取界面数据,拼接字符串
  104. let allStr = '',data = allData.data;console.log(555,data)
  105. for(let i = 0;i < data.length;i++){
  106. if(data[i].controlType != 3&&data[i].value){
  107. // allStr += (data[i].value).replace('{','').replace('}','')+';'
  108. allStr += (data[i].value).replace(patt,'').replace(/\#\{/g,'').replace(/\}/g,'')+';'
  109. }
  110. if(data[i].controlType == 3){//多列选择
  111. let tmpStr = '';
  112. for(let j = 0;j < data[i].questionDetailList.length;j++){
  113. let tmpName = data[i].questionDetailList[j]
  114. if(tmpName&&tmpName.value&&tmpName.value!='/'){
  115. let obj = getModelExpStr(tmpName.name)
  116. tmpStr+=obj.prefix+tmpName.value+obj.suffix+(j ==(data[i].questionDetailList.length-1)?';':',')
  117. }
  118. }
  119. allStr+=tmpStr
  120. }
  121. }
  122. return trimDots(allStr);
  123. }
  124. const moduleCP = {
  125. 'symp':1, //症状情况
  126. 'diagT':51, //诊疗情况
  127. 'other':3, //其他史
  128. 'suplement':52,//补充内容
  129. }
  130. const moduleConfig = (config,modules) => {
  131. let activeModule = []
  132. for(let i = 0;i < config.length;i++){
  133. let tmpCode = config[i].code
  134. let tmpVal = config[i].value
  135. for(let j = 0;j < modules.length;j++){
  136. let tmpType = modules[j].type
  137. if(tmpCode=="symptoms_show"&&tmpType==moduleCP['symp']&&tmpVal==1){
  138. activeModule.push(modules[j])
  139. }else if(tmpCode=="diagnosis_show"&&tmpType==moduleCP['diagT']&&tmpVal==1){
  140. activeModule.push(modules[j])
  141. }else if(tmpCode=="omhistory_show"&&tmpType==moduleCP['other']&&tmpVal==1){
  142. activeModule.push(modules[j])
  143. }else if(tmpCode=="replenish_show"&&tmpType==moduleCP['suplement']&&tmpVal==1){
  144. activeModule.push(modules[j])
  145. }
  146. }
  147. }
  148. return {
  149. data:activeModule,
  150. len:activeModule.length||0,
  151. order:activeModule.length>0?activeModule[0].type:''
  152. }
  153. }
  154. // 监听键盘是否弹起
  155. function fixedKeyboard() {
  156. var win_h = $(window).height();
  157. $(window).on("resize",function(){
  158. if (/iphone|ipad/i.test(navigator.userAgent.toLowerCase())) {
  159. //ios 什么都不用做
  160. } else {
  161. //安卓触发window.resize
  162. if($(window).height() < win_h){
  163. $('.detailBox-wrap').css('position','static') ;//详情页
  164. $('.main').height((win_h)/100+'rem');
  165. }else{
  166. $('.detailBox-wrap').css('position','fixed');
  167. // $('.main').css('height','100%;') ;
  168. $('.main').height("100%") ;
  169. }
  170. }
  171. })
  172. $(window).on("click",function(){
  173. const { activeElement } = document;
  174. if (activeElement.tagName === 'INPUT' || activeElement.tagName === 'TEXTAREA') {
  175. setTimeout(() => {
  176. activeElement.scrollIntoView(true);
  177. let top = $('.main').scrollTop();
  178. $('.main').scrollTop(top-30); //预留题目位置
  179. }, 400);
  180. }
  181. })
  182. }
  183. // 移动到可视区--选项中的输入框,因阻止了冒泡
  184. function scrollToV(e){
  185. setTimeout(function() {
  186. // e.target.scrollIntoView(false);
  187. e.target.scrollIntoView(true); //true--元素顶部与可视区顶部对齐;false--元素底部与可视区底部对齐
  188. let mainH = $('.main').height();
  189. let top = $('.main').scrollTop();
  190. $('.main').scrollTop(top-30); //预留题目位置
  191. /*let HH = mainH-clientY;
  192. if(clientY < 210 || (mainH-clientY)>88){
  193. e.target.scrollIntoView(false); //底部对齐
  194. }else if(HH < 200){
  195. e.target.scrollIntoView(true);//顶部对齐
  196. }
  197. else{
  198. e.target.scrollIntoView();
  199. }*/
  200. }, 400)
  201. }
  202. function trimDots(str){
  203. return str.replace(/[,,.。::"“??”;;、!!]+/g,function(word){
  204. return word.substr(0,1);
  205. }).replace(/^[,,.。::"“??”;;、!!\s]+/,'');
  206. }
  207. module.exports = {
  208. imageUrlPrefix,
  209. getUrlArgObject,
  210. deepClone,
  211. getModelExpStr,
  212. getAllStr,
  213. moduleConfig,
  214. patt,
  215. moduleCP,
  216. getExpStr,
  217. fixedKeyboard,
  218. scrollToV,
  219. trimDots
  220. }