tools.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. const qs = require('qs');
  2. const imageUrlPrefix = 'http://192.168.2.236:82' //后台图片地址
  3. const getUrlArgObject = (parm) => {
  4. let query = window.location.search;
  5. let args = qs.parse(query.substr(1));
  6. return args[parm];//返回对象
  7. }
  8. const deepClone = (arr) =>{
  9. let newArr = [];
  10. for(let i in arr){
  11. newArr.push(arr[i]);
  12. }
  13. return newArr;
  14. }
  15. const getModelExpStr = (str) =>{
  16. let result = {}
  17. if(str.match(/\${number_(.*})/)){//数字输入框
  18. let matchStr = str.match(/\${number_(.*})/)[0]
  19. result = {
  20. type:'number',
  21. placeholder:matchStr.split('${number_')[1].split('}')[0],
  22. prefix:str.split(matchStr)[0]||'',
  23. suffix:str.split(matchStr)[1]||''
  24. }
  25. }else if(str.match(/\${input_(.*})/)){
  26. let matchStr = str.match(/\${input_(.*})/)[0]
  27. result = {
  28. type:'text',
  29. placeholder:matchStr.split('${input_')[1].split('}')[0],
  30. prefix:str.split(matchStr)[0]||'',
  31. suffix:str.split(matchStr)[1]||''
  32. }
  33. }
  34. return result
  35. }
  36. const getAllStr = (allData) =>{//获取界面数据,拼接字符串
  37. let allStr = '',data = allData.data;
  38. for(let i = 0;i < data.length;i++){
  39. if(data[i].controlType != 3&&data[i].value){
  40. allStr += (data[i].value).replace('{','').replace('}','')+';'
  41. }
  42. if(data[i].controlType == 3){//多列选择
  43. let tmpStr = '';
  44. for(let j = 0;j < data[i].questionDetailList.length;j++){
  45. let tmpName = data[i].questionDetailList[j]
  46. if(tmpName&&tmpName.value){
  47. let obj = getModelExpStr(tmpName.name)
  48. tmpStr+=obj.prefix+tmpName.value+obj.suffix+(j ==(data[i].questionDetailList.length-1)?';':',')
  49. }
  50. }
  51. allStr+=tmpStr
  52. }
  53. }
  54. return allStr;
  55. }
  56. const moduleConfig = (config,modules) => {
  57. let activeModule = []
  58. for(let i = 0;i < config.length;i++){
  59. let tmpCode = config[i].code
  60. for(let j = 0;j < modules.length;j++){
  61. let tmpType = modules[j].type
  62. if(tmpCode=="symptoms_show"&&tmpType==1){
  63. activeModule.push(modules[j])
  64. }else if(tmpCode=="diagnosis_show"&&tmpType==51){
  65. activeModule.push(modules[j])
  66. }else if(tmpCode=="omhistory_show"&&tmpType==3){
  67. activeModule.push(modules[j])
  68. }else if(tmpCode=="replenish_show"&&tmpType==52){
  69. activeModule.push(modules[j])
  70. }
  71. }
  72. }
  73. return {
  74. data:activeModule,
  75. len:activeModule.length||0,
  76. order:activeModule.length>0?activeModule[0].type:''
  77. }
  78. }
  79. // 替换输入框占位符
  80. const patt = /\$\{[^\]]+\}/g;
  81. module.exports = {
  82. imageUrlPrefix,
  83. getUrlArgObject,
  84. deepClone,
  85. getModelExpStr,
  86. getAllStr,
  87. moduleConfig,
  88. patt
  89. }