tools.js 6.4 KB

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